接收SNMP資料
安裝SNMP Fluentd Plugin
gem install fluent-plugin-snmp
設定檔
test.conf設定檔案如下:
<source>
type snmp
tag snmp.server1
nodes name, value
host localhost
community idv90we3rnov90wer # 這是config檔案中的community的設定
mib sysContact.0, sysDescr.0, sysName.0
method_type get
polling_time 5
polling_type async_run
</source>
<match snmp.server*>
type stdout
</match>
snmp config
在資料擷取前,需要在主機上設定相對應的snmp config,以便把相關資訊提供給fluentd抓取...
# snmp.conf設定檔案如下:
# Map 'idv90we3rnov90wer' community to the 'ConfigUser'
# Map '209ijvfwer0df92jd' community to the 'AllUser'
# sec.name source community
com2sec ConfigUser default idv90we3rnov90wer
com2sec AllUser default 209ijvfwer0df92jd
# Map 'ConfigUser' to 'ConfigGroup' for SNMP Version 2c
# Map 'AllUser' to 'AllGroup' for SNMP Version 2c
# sec.model sec.name
group ConfigGroup v2c ConfigUser
group AllGroup v2c AllUser
# Define 'SystemView', which includes everything under .1.3.6.1.2.1.1 (or .1.3.6.1.2.1.25.1)
# Define 'AllView', which includes everything under .1
# incl/excl subtree
view SystemView included .1.3.6.1.2.1.1
view SystemView included .1.3.6.1.2.1.25.1.1
view AllView included .1
# Give 'ConfigGroup' read access to objects in the view 'SystemView'
# Give 'AllGroup' read access to objects in the view 'AllView'
# context model level prefix read write notify
access ConfigGroup "" any noauth exact SystemView none none
access AllGroup "" any noauth exact AllView none none
以CPU load為例
首先,在snmp設定檔中設定cpu load average的mib設定。
參考:http://www.debianadmin.com/linux-snmp-oids-for-cpumemory-and-disk-statistics.html
# vim /etc/snmp/snmpd.conf
(skip)
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3
(skip)
接著,可以到fluentd設定檔中設定抓取該snmp資訊:
<source>
type snmp
tag snmp.server1
nodes name, value
host test-centos6
community 209ijvfwer0df92jd # <-- 這是config檔案中的community的設定
mib laLoad.1, laLoad.2, laLoad.3
mib_modules UCD-SNMP-MIB
method_type get
polling_time 5
polling_type async_run
</source>
<match snmp.server*>
type stdout
</match>
以上面設定為例,所顯示的stdout如下:
2015-07-07 13:54:25 +0000 snmp.server1: {"name":"UCD-SNMP-MIB::laLoad.1","value":0.0}
2015-07-07 13:54:25 +0000 snmp.server1: {"name":"UCD-SNMP-MIB::laLoad.2","value":0.02}
2015-07-07 13:54:25 +0000 snmp.server1: {"name":"UCD-SNMP-MIB::laLoad.3","value":0.0}
2015-07-07 13:54:30 +0000 snmp.server1: {"name":"UCD-SNMP-MIB::laLoad.1","value":0.0}
2015-07-07 13:54:30 +0000 snmp.server1: {"name":"UCD-SNMP-MIB::laLoad.2","value":0.02}