歡迎您光臨本站 登入註冊首頁

Cacti 獲取 SNMP 發送的自定義信息繪圖

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

Cacti 獲取 SNMP 發送的自定義信息繪圖

Cacti 獲取 SNMP 發送的自定義信息繪圖

本文以獲取 squid 內存緩存命中率為例。
在 /etc/snmp/snmpd.conf 可以看到這樣的樣例:
# exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest
可以使用自己編寫的腳本,比如:
exec .1.3.6.1.4.1.2021.50 squidmemhits /usr/local/bin/squidmemhits.sh
vi /usr/local/bin/squidmemhits.sh01.#!/bin/sh

02.PATH=$PATH:/usr/local/squid/bin

03.export PATH

04.squidclient -t 1 -h localhost -p 3128 mgr:info | grep "Memory hits" | cut -d "%" -f 2 | awk '{print $5}'

05.squidclient -t 1 -h localhost -p 3128 mgr:info | grep "Memory hits" | cut -d "%" -f 3 | awk '{print $3}'
複製代碼/etc/init.d/snmpd restart

檢查一下能否讀取到數據:snmpwalk -v 2c 192.168.0.200 -c public .1.3.6.1.4.1.2021.50
01.UCD-SNMP-MIB::ucdavis.50.1.1 = INTEGER: 1

02.UCD-SNMP-MIB::ucdavis.50.2.1 = STRING: "squidmemhits"

03.UCD-SNMP-MIB::ucdavis.50.3.1 = STRING: "/usr/local/bin/squidmemhits.sh"

04.UCD-SNMP-MIB::ucdavis.50.100.1 = INTEGER: 0

05.UCD-SNMP-MIB::ucdavis.50.101.1 = STRING: "86.0"

06.UCD-SNMP-MIB::ucdavis.50.101.2 = STRING: "86.6"

07.UCD-SNMP-MIB::ucdavis.50.102.1 = INTEGER: 0

08.UCD-SNMP-MIB::ucdavis.50.103.1 = ""
複製代碼其中
UCD-SNMP-MIB::ucdavis.50.101.1 = STRING: "86.0"
UCD-SNMP-MIB::ucdavis.50.101.2 = STRING: "86.6"
這兩行就是所需要的。01.snmpwalk -v 1 192.168.0.200 -c public .1.3.6.1.4.1.2021.50.101.1

02.UCD-SNMP-MIB::ucdavis.50.101.1 = STRING: "86.0"

03.snmpwalk -v 1 192.168.0.200 -c public .1.3.6.1.4.1.2021.50.101.2

04.UCD-SNMP-MIB::ucdavis.50.101.2 = STRING: "86.6"
複製代碼能採集到數據,就可以配置 Cacti 來接收了。
先創建數據模板:01.

02.console -> Templates -> Data Templates -> Add ->

03.Data Templates Name: ucd/net - Squid - Memory Hits - 5 Minute

04.Data Source Name: |host_description| - Squid - Memory Hits - 5 Minute

05.Data Input Method: GET SNMP Data

06.Associated RRA's: remove Hourly (1 Minute Average)

07.Internal Data Source Name: squid_memhits_5min

08.create ->

09.OID: .1.3.6.1.4.1.2021.50.101.1

10.Save複製代碼同樣再創建一個 Squid - Memory Hits - 60 Minute 的數據模板。
再創建圖形模板:01.console -> Templates -> Graph Templates -> Add ->

02.Name: ucd/net - Squid Memory Hits

03.Title: |host_description| - Squid Memory Hits

04.Vertical Label: percent

05.create

06.

07.Graph Template Items -> Add

08.Data Source: ucd/net - Squid - Memory Hits - 5 Minute - (squid_memhits_5min)

09.Color: FFC73B

10.Graph Item Type: AREA

11.Consolidation Function: AVERAGE

12.Text Format: 5 Minute

13.create ->

14.Graph Template Items -> Add

15.Graph Item Type: GPRINT

16.Consolidation Function: LAST

17.Text Format: Current:

18.Insert Hard Return

19.create ->

20.

21.Graph Template Items -> Add

22.Data Source: ucd/net - Squid - Memory Hits - 60 Minute - (squid_memhits_60min)

23.Color: FF0000

24.Graph Item Type: LINE1

25.Consolidation Function: AVERAGE

26.Text Format: 60 Minute

27.create ->

28.Graph Template Items -> Add

29.Graph Item Type: GPRINT

30.Consolidation Function: LAST

31.Text Format: Current:

32.Insert Hard Return

33.create -> Save複製代碼然後就可以選擇主機,添加圖形了。
《解決方案》

謝謝分享

[火星人 ] Cacti 獲取 SNMP 發送的自定義信息繪圖已經有519次圍觀

http://coctec.com/docs/service/show-post-1127.html