OpenNMS擴充 – SNMP報表配置
SNMP報表的顯示主要由兩個檔案,datacollection-config.xml與snmp-graph.properties。
定制SNMP圖形報表主要步驟如下:
1. 通過SNMP擷取資料(datacollection-config.xml)
在datacollection-config.xml檔案中定義OID捕獲資料,在此例中将捕獲系統中CPU的占用情況(藍色字型部分):
<group name = "windows-host" ifType = "ignore">
<mibObj oid=".1.3.6.1.2.1.25.3.3.1.2" instance="1" alias="cpuPercentBusy" type="integer" />
<!-- Drive information is from the hrStorage table. -->
<!-- I'm cheating and assuming that the second and third -->
<!-- entries refer to Drive_C and Drive_D -->
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.3" instance="2" alias="hrDescDisk2" type="string"/>
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.4" instance="2" alias="hrUnitsDisk2" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.5" instance="2" alias="hrSizeDisk2" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.6" instance="2" alias="hrUsedDisk2" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.3" instance="3" alias="hrDescDisk3" type="string"/>
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.4" instance="3" alias="hrUnitsDisk3" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.5" instance="3" alias="hrSizeDisk3" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.6" instance="3" alias="hrUsedDisk3" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.3" instance="4" alias="hrDescDisk4" type="string"/>
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.4" instance="4" alias="hrUnitsDisk4" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.5" instance="4" alias="hrSizeDisk4" type="integer" />
<mibObj oid=".1.3.6.1.2.1.25.2.3.1.6" instance="4" alias="hrUsedDisk4" type="integer" />
<!-- Memory in KBytes -->
<mibObj oid=".1.3.6.1.2.1.25.2.2" instance="0" alias="memorySize" type="integer" />
<!-- the total system's CPU resources consumed -->
<!—instance表示OID索引位置,alias表示别名 -->
<mibObj oid=".1.3.6.1.2.1.25.5.1.1.1" instance="1" alias="hrSWRunPerfCPU" type="integer" />
</group>
請注意,確定給定的OID能夠在系統中找到,否則将不會産生RRDTool檔案(RRDTool檔案通常存儲在$OPENNMS_HOME/share/rrd/snmp/目錄下),可通過snmpget檢測是否可以找到此OID。
[[email protected] /]# snmpget -v 1 -c public 192.168.6.21 .1.3.6.1.2.1.25.5.1.1.1.1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.1 = INTEGER: 482801
2. 編輯SNMP圖形屬性檔案(snmp-graph.properties)
2.1 檢查RRDTOOL資料檔案
定制的圖形報表需定義如下屬性:
l 名字(name):用來顯示報表的名字。
l 列(colunms):顯示RRDTool檔案中的資料。
l 類型(type):如果狀态跟每個網絡接口有關聯,則使用“interface”類型,如果影響整個結點的,則使用“node”類型。
一種擷取RRDTool檔案資訊的方法是采用rrdtool info 指令行的方式,如下:
[[email protected] 13]# rrdtool info hrSWRunPerfCPU.rrd
filename = "hrSWRunPerfCPU.rrd"
rrd_version = "0001"
step = 300
last_update = 1211338458
ds[hrSWRunPerfCPU].type = "GAUGE"
ds[hrSWRunPerfCPU].minimal_heartbeat = 600
ds[hrSWRunPerfCPU].min = NaN
ds[hrSWRunPerfCPU].max = NaN
ds[hrSWRunPerfCPU].last_ds = "UNKN"
ds[hrSWRunPerfCPU].value = 3.5009052000e+08
ds[hrSWRunPerfCPU].unknown_sec = 0
rra[0].cf = "AVERAGE"
rra[0].rows = 8928
rra[0].pdp_per_row = 1
rra[0].xff = 5.0000000000e-01
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0
rra[1].cf = "AVERAGE"
rra[1].rows = 8784
rra[1].pdp_per_row = 12
rra[1].xff = 5.0000000000e-01
rra[1].cdp_prep[0].value = 1.0469351560e+07
rra[1].cdp_prep[0].unknown_datapoints = 0
rra[2].cf = "MIN"
rra[2].rows = 8784
rra[2].pdp_per_row = 12
rra[2].xff = 5.0000000000e-01
rra[2].cdp_prep[0].value = 7.9226661000e+05
rra[2].cdp_prep[0].unknown_datapoints = 0
rra[3].cf = "MAX"
rra[3].rows = 8784
rra[3].pdp_per_row = 12
rra[3].xff = 5.0000000000e-01
rra[3].cdp_prep[0].value = 1.3079840700e+06
rra[3].cdp_prep[0].unknown_datapoints = 0
如果由于某種原因,如果rrdtool資料檔案的一部分沒有定義或沒有資料,則相應的圖形也将不會顯示在Web上。
記得随時檢查rrdtool資料檔案的内容,輸入:
rrdtool dump hrSWRunPerfCPU.rrd(按日期顯示大量采集的資料)
2.2 添加圖形定義
可以随時檢查定義生成的資料檔案産生的圖形顯示效果,用RRDTool圖形生成指令行可以做到:
rrdtool graph hrSWRunPerfCPU.png --title " The total system's CPU resources consumed " --vertical-label /
Days "DEF:timeticks=hrSWRunPerfCPU.rrd:hrSWRunPerfCPU:AVERAGE" /
"CDEF:days=timeticks,8640000,/" AREA:days#FF0000:"Days" /
GPRINT:days:AVERAGE:"Avg //: %8.1lf %s" GPRINT:days:MIN:"Min //: %8.1lf %s" /
GPRINT:days:MAX:"Max //: %8.1lf %s"
如下是snmp-graph.properties檔案中hrSWRunPerfCPU圖形報表屬性配置:
report.microsoft.hrSWRunPerfCPU.name=CPU resources consumed
report.microsoft.hrSWRunPerfCPU.columns=hrSWRunPerfCPU
report.microsoft.hrSWRunPerfCPU.type=node
report.microsoft.hrSWRunPerfCPU.command=--title="The total system's CPU resources consumed" /
--vertical-label Days /
DEF:hrSWRunPerfCPU={rrd1}:hrSWRunPerfCPU:AVERAGE /
CDEF:days=hrSWRunPerfCPU,8640000,/ /
AREA:days#FF0000:"Days" /
GPRINT:days:AVERAGE:"Avg //: %8.1lf %s" /
GPRINT:days:MIN:"Min //: %8.1lf %s" /
GPRINT:days:MAX:"Max //: %8.1lf %s" /
如果,定義的其中report.microsoft.hrSWRunPerfCPU.columns=hrSWRunPerfCPU中的hrSWRunPerfCPU是datacollection-config.xml檔案中MIB的别名。報表的定義的key規則:report.+reports key中定義的報表名稱+屬性。
3. 添加新報表到報表屬性
最後,為了顯示産生的報表,需要在snmp-graph.properties檔案的reports key 中添加microsoft.hrSWRunPerfCPU,并加逗号與/結束。
#report keys, list ALL prefab reports here!
reports=mib2.bits, mib2.discards, mib2.errors, mib2.HCbits, mib2.packets, /
mib2.tcpopen, mib2.tcperrs, mib2.tcpsegs, /
mib2.traffic-inout, /
mib2.ups-amp, mib2.ups-charge, mib2.ups-temp, mib2.ups-time, mib2.ups-volt, /
mib2printer.lifeCount, mib2printer.powerOnCount, /
apc.load, apc.percent, apc.temp, apc.time, apc.vac, /
checkpoint.pktsAccepted, checkpoint.pktsDropped, checkpoint.pktsLogged, checkpoint.pktsRejected, /
cisco.altigaactsess, cisco.altigacpu, cisco.altigafanspeed, cisco.altigatemp, /
cisco.altigatput, cisco.altigavoltage, cisco.altiga3volt, cisco.altiga5volt, /
cisco.avgbusy5, cisco.bufferfails, cisco.buffhits, cisco.buffmiss, /
cisco.ccmcti, cisco.ccmgs, cisco.ccmgw, cisco.ccmmd, cisco.ccmphones, /
cisco.ccmps, cisco.ccmvm, /
cisco.cike-bits, cisco.cike-dn, cisco.cike-fail, cisco.cike-init, cisco.cike-pkts, /
cisco.cike-p2ex, cisco.cike-p2exinv, cisco.cike-p2exrej, cisco.cike-tunnels, /
cisco.dropsin, cisco.dropsout, cisco.freemem, /
cisco.firewall, cisco.memory, /
cisco.pkts, cisco.protoin, cisco.protoout, cisco.temp, /
cisco.4bb, cisco.80bb, cisco.256bb, cisco.1550bb, /
extreme.currentTemp, /
foundry.actualTemp, foundry.cpuUtil1Min, foundry.dynMemUtil, /
hp.swbuffcorrupt, hp.swbufferfree, hp.swbufferinit, hp.swbuffermin, /
hp.swbuffermiss, hp.swbuffersize, hp.swfreemem, hp.switchcpu, hp.swmemalloc, hp.swtotalmem, /
hpux.cpu, hpux.memory, hpux.numFsMounted, hpux.numProcs, hpux.numUsers, hpux.swap, /
juniper.bufferPoolUtil, juniper.cpu, juniper.temp, /
mge.ambtemp, mge.ambhumid, mge.current, mge.level, mge.temp, mge.time, mge.voltage, /
microsoft.cpuPercentBusy, microsoft.hrDisk2, microsoft.hrDisk3, microsoft.hrDisk4, microsoft.hrSWRunPerfCPU, /
netsnmp.context, /
netsnmp.disk1, netsnmp.disk1percent, netsnmp.disk2, netsnmp.disk2percent, /
netsnmp.disk3, netsnmp.disk3percent, netsnmp.disk4, netsnmp.disk4percent, netsnmp.disk5, netsnmp.disk5percent, /
netsnmp.hrMemory, netsnmp.hrNumUsers, netsnmp.interrupts, /
netsnmp.hrSystemUptime, netsnmp.loadavg, netsnmp.swapinout, /
netBotz.air, netBotz.humid, netBotz.temp, /
nortel.kernelmem, nortel.kerneltasks, /
novell.cacheBuffers, novell.codeDataMemory, novell.diskSpaceSys, /
novell.diskSpaceVol2, novell.licensedConnections, novell.numberOfNLMsLoaded, novell.openFiles, /
sinf.availmem, sinf.mempool, sinf.paging, sinf.processes, sinf.sysmem, /
sinf.cpu0percent, sinf.cpu1percent, sinf.cpu2percent, sinf.cpu3percent, sinf.cputotalpercent, /
sinf.diskfreeC, sinf.diskfreeD, sinf.diskfreeE, sinf.diskfreetotal, /
sinf.exchange-is.vmfreeblks, sinf.exchange-is.users, /
sun.cpuTime, sun.diskxfer, sun.interrupts, sun.packets, sun.paging, sun.procs, /
sun.swap, sun.swapping, /
netsnmp.memStats, /
netsnmp.cpuStats, /
netsnmp.connectNums
我們定義的報表是microsoft.hrSWRunPerfCPU,如果沒有在這裡定義,當試圖運作這個性能報表時,将會在Web頁面上抛出一個異常:
Missing Parameter
The request you made was incomplete. It was missing the report parameter.
The following parameters are required:
report
node
4. 重新開機Tomcat與OpenNMS
su - tomcat -c "/usr/local/tomcat/bin/startup.sh"
/usr/local/opennms/source/work/bin/opennms.sh restart
大約過一兩分鐘RDD資料檔案就會生成。
如果隻是修改snmp-graph.properties檔案,則不需重新開機OpenNMS,因為報表程式每次會重新讀取此檔案。