cacti监控tcp链接数
首先修改被监控端snmpd.conf,在最后增长一行:web
[root@localhost ~]# vim /etc/snmp/snmpd.conf
extend .1.3.6.1.4.1.2021.21 webconn /bin/bash /etc/snmp/webconn.sh
再在/etc/snmp下建立获取端口链接数的脚本webconn.shvim
#!/bin/sh
#If more than one IP or port Please '|' separated
ip="58.251.x.x|119.145.x.x" #咱们服务器是双线接入,因此有2个IP
port="80|443" #我这里是监控80和443端口
webconn=`netstat -nt |grep ESTABLISHED |awk '{print $4}'|awk '/('$ip'):('$port')/'| wc -l`
websyn=`netstat -nt |grep SYN_RECV |awk '{print $4}'|awk '/('$ip'):('$port')/'| wc -l`
weback=`netstat -nt |grep LAST_ACK |awk '{print $4}'|awk '/('$ip'):('$port')/'| wc -l`
webwait=`netstat -nt |grep TIME_WAI |awk '{print $4}'|awk '/('$ip'):('$port')/'| wc -l`
echo $webconn
echo $websyn
echo $weback
echo $webwait
再赋予脚本可执行权限并重启snmpbash
[root@localhost ~]# chmod a+x /etc/snmp/webconn.sh
[root@localhost ~]# service snmpd restart
接下来在cacti上验证看可否经过snmp抓取到客户端的数据:服务器
[root@monitor ~]# snmpwalk -v 2c -c public 172.16.88.10 .1.3.6.1.4.1.2021.21
UCD-SNMP-MIB::ucdavis.21.1.0 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.21.2.1.2.7.119.101.98.99.111.110.110 = STRING: "/bin/bash"
UCD-SNMP-MIB::ucdavis.21.2.1.3.7.119.101.98.99.111.110.110 = STRING: "/etc/snmp/webconn.sh"
UCD-SNMP-MIB::ucdavis.21.2.1.4.7.119.101.98.99.111.110.110 = ""
UCD-SNMP-MIB::ucdavis.21.2.1.5.7.119.101.98.99.111.110.110 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.21.2.1.6.7.119.101.98.99.111.110.110 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.21.2.1.7.7.119.101.98.99.111.110.110 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.21.2.1.20.7.119.101.98.99.111.110.110 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.21.2.1.21.7.119.101.98.99.111.110.110 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.21.3.1.1.7.119.101.98.99.111.110.110 = STRING: "221"
UCD-SNMP-MIB::ucdavis.21.3.1.2.7.119.101.98.99.111.110.110 = STRING: "221
16
1
19"
UCD-SNMP-MIB::ucdavis.21.3.1.3.7.119.101.98.99.111.110.110 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.21.3.1.4.7.119.101.98.99.111.110.110 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.21.4.1.2.7.119.101.98.99.111.110.110.1 = STRING: "221"
UCD-SNMP-MIB::ucdavis.21.4.1.2.7.119.101.98.99.111.110.110.2 = STRING: "16"
UCD-SNMP-MIB::ucdavis.21.4.1.2.7.119.101.98.99.111.110.110.3 = STRING: "1"
UCD-SNMP-MIB::ucdavis.21.4.1.2.7.119.101.98.99.111.110.110.4 = STRING: "19"
如有上面的输出则说明成功了,接下来就只要建cacti的模板了,这里就不讲创建模板的过程了,我已经把模板导出来,有须要可下载附件包含模板和脚本tcp
cacti-tcp.zipide
另外个人cacti是0.8.7f的,不一样版本模板的hash值不同,因此非0.8.7f版本的cacti导入此模板会报错,不过可将模板里的0020所有替换成你所用版本的 hash值就能够解决,下面是每一个版本对应的hash值:
1. “0.8.4″ => “0000″,
2. “0.8.5″ => “0001″,
3. “0.8.5a” => “0002″,
4. “0.8.6″ => “0003″,
5. “0.8.6a” => “0004″,
6. “0.8.6b” => “0005″,
7. “0.8.6c” => “0006″,
8. “0.8.6d” => “0007″,
9. “0.8.6e” => “0008″,
10. “0.8.6f” => “0009″,
11. “0.8.6g” => “0010″,
12. “0.8.6h” => “0011″,
13. “0.8.6i” => “0012″,
14. “0.8.6j” => “0013″,
15. “0.8.7″ => “0014″,
16. “0.8.7a” => “0015″,
17. “0.8.7b” => “0016″,
18. “0.8.7c” => “0017″,
19. “0.8.7d” => “0018″
20. “0.8.7e” => “0019″
21. “0.8.7f” => “0020″
pwa