Monitoring
如何在 OpenNMS 中監控 memcached 統計資訊?
我想去編譯數據的大小和點擊量……
創建以下腳本(並使其可執行):
#!/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
這會根據腳本的輸出創建一個表,其中每一行都有自己的節點。
如果要確認這一點,請執行以下命令:
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 配置之後:
<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-SNMP和Net-SNMP (UCD)的**systemDef標記,並在收集標記中添加以下內容:
<includeGroup>memcached_stats</includeGroup>
重新啟動 OpenNMS 就可以了……當 capsd 重新掃描主機時,它將開始收集這些統計資訊
以下是可以從 memcached 獲取的數據的參考:
- pid:此伺服器程序的程序ID
- 正常執行時間:此伺服器已執行的秒數
- time:根據伺服器的目前 UNIX 時間
- version:此伺服器的版本字元串
- pointer_size:主機作業系統上指針的預設大小
- rusage_user:此程序的累計使用者時間
- rusage_system:此程序的累積系統時間
- curr_items:伺服器儲存的目前項目數
- total_items:此伺服器自啟動以來儲存的項目總數
- bytes:此伺服器用於儲存項目的目前字節數
- curr_connections:打開的連接數
- total_connections:自伺服器開始執行以來打開的連接總數
- connection_structures:伺服器分配的連接結構數
- cmd_get:累計檢索請求數
- cmd_set:累計儲存請求數
- get_hits:已請求並發現存在的密鑰數
- get_misses:已請求但未找到的項目數
- evictions:從記憶體中刪除的有效項目數以釋放新項目的記憶體
- bytes_read:此伺服器從網路讀取的總字節數
- bytes_written:此伺服器發送到網路的總字節數
- limit_maxbytes:允許此伺服器用於儲存的字節數
- 執行緒:請求的工作執行緒數
剩下的就是建構您想要的任何圖形或報告。
(適用於 CentOS 5.2、OpenNMS 1.5.93-1、net-snmp 5.3.1、memcached 1.2.2)