netstat를 snmp(expend모드)로 모니터링
cacti를 사용시, snmp 값 으로 정보가 부족한 경우가 있은데, 아래와 같이 agent 방식으로 정보를 cacti 쪽으로 밀어 줘야 할때가 있다.. 그리고 mlb 값을 사용할 경우 ,
cacti 쪽에서 찍히는 정보가 정확한지 mib 값을 직접 확인해볼 필요도 있다..
1) 스크립트 ( /etc/snmp/netstat-cent.sh )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/bin/sh AAA=0 netstat -ant | tail -n+3 | awk '{print $6}' | sort | uniq -c > /tmp/sock.txt && cat /tmp/sock.txt CLOSE=`cat /tmp/sock.txt | grep CLOSE_WAIT |awk '{print $1}'` EST=`cat /tmp/sock.txt | grep ESTABLISHED |awk '{print $1}'` FIN1=`cat /tmp/sock.txt | grep FIN_WAIT2 |awk '{print $1}'` FIN2=`cat /tmp/sock.txt | grep FIN_WAIT1 |awk '{print $1}'` LISTEN=`cat /tmp/sock.txt | grep LISTEN |awk '{print $1}'` SYNR=`cat /tmp/sock.txt | grep SYN_RECEVIED |awk '{print $1}'` SYNS=`cat /tmp/sock.txt | grep SYN_SENT |awk '{print $1}'` TIMEW=`cat /tmp/sock.txt | grep TIME_WAIT |awk '{print $1}'` TIMEC=`cat /tmp/sock.txt | grep TIME_CLOSE |awk '{print $1}'` echo `expr $CLOSE + $AAA` echo `expr $EST + $AAA` echo `expr $FIN1 + $AAA` echo `expr $FIN2 + $AAA` echo `expr $LISTEN + $AAA` echo `expr $SYNR + $AAA` echo `expr $SYNS + $AAA` echo `expr $TIMEW + $AAA` echo `expr $TIMEC + $AAA` | cs |
2) snmpd.conf 추가 (/etc/snmp/snmpd.conf )
1 2 | extend sensortemps /etc/snmp/netstat-cent.sh | cs |
3) MLB 값 확인
1 2 3 4 5 6 7 8 9 10 11 12 13 | # snmpwalk -v 2c -c private localhost NET-SNMP-EXTEND-MIB::nsExtendObjects . . NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".1 = STRING: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".2 = STRING: 1 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".3 = STRING: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".4 = STRING: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".5 = STRING: 7 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".6 = STRING: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".7 = STRING: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".8 = STRING: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."netstatcent".9 = STRING: 0 | cs |