如何监控OpenNMS中的memcached统计信息?

我想去编辑数据的大小和命中…

创build以下脚本(并使其可执行):

#!/bin/bash exec 5<> /dev/tcp/127.0.0.1/11211 if [ $? -eq 0 ]; then echo "stats" >&5 echo "quit" >&5 while read -u 5 -d $'\r' stat name value; do echo $value done exit 0 fi exit 1 

我的是/usr/local/bin/memcached_stats.sh

它连接到memcached守护进程,并吐出memcached stats命令的清理版本,并输出如下所示的内容:

 2754 2129139 1243545563 1.2.2 64 2299.898362 7336.774640 217721 7091925 1909177049 108 27653 633 234138327 7091925 220430936 13707391 352833 89610818966 1385141563315 2147483648 4 

将以下内容添加到/etc/snmp/snmpd.conf中,然后重新启动snmpd:

 extend .1.3.6.1.4.1.1.900.100 memcached /usr/local/bin/memcached_stats.sh 

这将根据脚本的输出创build一个表,每行获取自己的节点。

如果你想确认这个运行如下:

 snmpwalk -v2c -c public 127.0.0.1 .1.3.6.1.4.1.1.900.100 

你应该得到像这样的东西:

 SNMPv2-SMI::enterprises.1.900.100.3.1.3.9.109.101.109.99.97.99.104.101.100 = INTEGER: 23 SNMPv2-SMI::enterprises.1.900.100.3.1.4.9.109.101.109.99.97.99.104.101.100 = INTEGER: 0 SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.1 = STRING: "2754" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.2 = STRING: "2123005" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.3 = STRING: "1243539429" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.4 = STRING: "1.2.2" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.5 = STRING: "64" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.6 = STRING: "2290.369810" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.7 = STRING: "7308.630919" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.8 = STRING: "217652" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.9 = STRING: "7066934" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.10 = STRING: "1909286395" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.11 = STRING: "108" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.12 = STRING: "27628" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.13 = STRING: "633" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.14 = STRING: "233251848" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.15 = STRING: "7066934" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.16 = STRING: "219593496" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.17 = STRING: "13658352" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.18 = STRING: "348593" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.19 = STRING: "89233569948" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.20 = STRING: "1380956068373" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.21 = STRING: "2147483648" SNMPv2-SMI::enterprises.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.22 = STRING: "4" 

从那里你可以推断哪个节点是哪个属性,但幸运的是我已经完成了所有的事情。

datacollection-config.xml中,将以下内容添加到顶部,但毕竟rrd config:

 <resourceType name="MemcachedStats" label="memcached stats" resourceLabel="memcached"> <persistenceSelectorStrategy class="org.opennms.netmgt.collectd.PersistAllSelectorStrategy"/> <storageStrategy class="org.opennms.netmgt.dao.support.IndexStorageStrategy"/> </resourceType> 

然后在组中添加以下内容:

 <group name="memcached_stats" ifType="all"> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.1" instance="MemcachedStats" alias="pid" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.2" instance="MemcachedStats" alias="uptime" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.3" instance="MemcachedStats" alias="time" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.4" instance="MemcachedStats" alias="version" type="string" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.5" instance="MemcachedStats" alias="pointer_size" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.4" instance="MemcachedStats" alias="rusage_user" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.7" instance="MemcachedStats" alias="rusage_system" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.8" instance="MemcachedStats" alias="curr_items" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.9" instance="MemcachedStats" alias="total_items" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.10" instance="MemcachedStats" alias="bytes" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.11" instance="MemcachedStats" alias="curr_connections" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.12" instance="MemcachedStats" alias="total_connections" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.13" instance="MemcachedStats" alias="connection_structures" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.14" instance="MemcachedStats" alias="cmd_get" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.15" instance="MemcachedStats" alias="cmd_set" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.16" instance="MemcachedStats" alias="get_hits" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.17" instance="MemcachedStats" alias="get_misses" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.18" instance="MemcachedStats" alias="evictions" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.19" instance="MemcachedStats" alias="bytes_read" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.20" instance="MemcachedStats" alias="bytes_written" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.21" instance="MemcachedStats" alias="limit_maxbytes" type="integer" /> <mibObj oid=".1.3.6.1.4.1.1.900.100.4.1.2.9.109.101.109.99.97.99.104.101.100.22" instance="MemcachedStats" alias="threads" type="integer" /> </group> 

最后进一步向下查找Net-SNMPNet-SNMP(UCD)systemDef标签,并在collect标签中添加以下内容:

 <includeGroup>memcached_stats</includeGroup> 

重新启动OpenNMS和那里你有它…当capsd重新扫描主机,它将开始收集这些统计数据

以下是可以从memcached获得的数据的参考:

  • pid:此服务器进程的进程ID
  • 正常运行时间:此服务器已运行的秒数
  • 时间:根据服务器当前的UNIX时间
  • 版本:此服务器的版本string
  • pointer_size:主机OS上指针的默认大小
  • rusage_user:这个过程的累计用户时间
  • rusage_system:这个过程累积的系统时间
  • curr_items:当前服务器存储的项目数
  • total_items:此服务器自启动以来存储的项目总数
  • 字节:此服务器用于存储项目的当前字节数
  • curr_connections:打开连接的数量
  • total_connections:自服务器开始运行以来打开的连接总数
  • connection_structures:服务器分配的连接结构的数量
  • cmd_get:检索请求的累计数量
  • cmd_set:存储请求的累计数量
  • get_hits:已经请求并且find的键的数目
  • get_misses:已请求和未find的项目数量
  • 逐出:从caching中删除的有效项目的数量到新项目的可用内存
  • bytes_read:此服务器从networking读取的总字节数
  • bytes_written:此服务器发送到networking的总字节数
  • limit_maxbytes:此服务器允许用于存储的字节数
  • 线程数:请求的工作线程数

剩下的就是build立你想要的图表或报告。

(适用于CentOS 5.2,OpenNMS 1.5.93-1,net-snmp 5.3.1,memcached 1.2.2)

从1.7.4开始内置。

请参阅http://www.opennms.org/wiki/Memcached_Monitor

好的工作,Nathan! 只是几个意见。

你做这个比想要的要困难 – 对于标量的对象来说,使用自定义的resourceType并不是必须的,也就是说,每个节点只出现一次。 如果删除resourceType,则只需将每个<mibObj>的“oid”属性的最后一位移入其“实例”属性,并将<group>的“ifType”属性从“all”忽略”。

你一定要把这些统计数据中的一部分作为计数器(单调递增的数值,例如两个样本之间的差值是真正重要的),通过指定“counter”而不是“integer”(或“gauge”,这是相当,但更清晰)的types。 记住什么是计量器和什么是计数器的好记事是计量器代表例如现在在一个房间里的人数,而计数器代表例如已经通过旋转门进入房间的人数。 所以“curr_items”应该是衡量标准,“total_items”应该是一个反面。 其他人也需要改变,但这应该足以让你去。 您需要重新启动并删除使用错误types创build的所有RRD文件; OpenNMS将自动重新创build文件。

最后,你也可以使用HTTP收集器来完成这个工作,但是你不会经历使用SNMP的乐趣;)

最后一件事情 – 通常最好是在opennms.org wiki上logging这些“食谱”,而不是像ServerFault这样的外部网站。 这是因为从现在开始,用于SNMP数据收集的XML模式可能会改变,并且能够相应地更新指令,而无需在一百万个站点上创build账户或为一百万名作者追踪电子邮件地址。

我重新考虑了你的脚本:(需要netcat)

 #!/bin/bash echo -e "stats\nquit"|nc $1 11211 | while read -d $'\r' stat name value; do echo $value done 

fyi:OpenNMS> 1.7.4现在有本地memcached监视。 查看OpenNMS维基,了解我写的一篇半成品文章。

memcache协议定义了stat命令,使用它可以获得所有的信息。 无论你使用哪种API,它都应该绑定这个命令。