Extracting system and network statistics with net-snmp


The net-snmp software suite implements the SNMPv1, SNMPv2 and SNMPv3 protocols, and comes with several utilities to remotely retrieve data from servers and network devices. One such utility is snmpstatus, which allows you to retrieve the overall status of a given device:

$ snmpstatus -v 2c -c yikes 10.10.1.1

[10.10.1.7]=>[Content Switch SW Version 07.90 with SNMPv1/v2c Agent] Up: 152 days, 10:47:55.03
Interfaces: 6, Recv/Trans packets: -1275435709/-1122090667 | IP: 58510352/75120061
2 interfaces are down!

Another nifty tool that comes with net-snmp is snmpnetstat, which allows you to get a “netstat”-like view of any device that supports SNMP. The following example show how to retrieve the active and passive UDP and TCP ports from a device:

$ snmpnetstat -v 2c -c yikes -a 10.10.1.1

Active Internet (tcp) Connections (including servers)
Proto Local Address Foreign Address (state)
tcp *.ftp LISTEN
tcp *.ssh  LISTEN
tcp *.telnet  LISTEN
tcp *.80 LISTEN
tcp *.443  LISTEN
tcp 10.10.1.1.4189 www.youch.net.8080 ESTABLISHED
tcp 10.10.1.1.4190 www.youch.net.8080 ESTABLISHED
Active Internet (udp) Connections
Proto Local Address
udp *.ntp
udp *.snmpd
udp *.1024
udp *.5002
udp *.47806

Snmpstat also allows you to retrieve network statistics with the “-s” option:

$ snmpnetstat -v 2c -c yikes -s 10.10.1.1

ip:
58509607 total datagrams received
0 datagrams with header errors
6068304 datagrams with an invalid destination address
0 datagrams forwarded
0 datagrams with unknown protocol
0 datagrams discarded
52441309 datagrams delivered
75119154 output datagram requests
0 output datagrams discarded
45 datagrams with no route
0 fragments received
0 datagrams reassembled
0 reassembly failures
0 datagrams fragmented
0 fragmentation failures
0 fragments created
icmp:
2634607 total messages received
0 messages dropped due to errors
584 ouput message requests
270 output messages discarded
Output Histogram:
Destination unreachable: 270
Echo Reply: 314
Input Histogram:
Echo Request: 314
Echo Reply: 2634293
tcp:
2476943 active opens
713945482 passive opens
322859 failed attempts
2073710 resets of established connections
694522544 current established connections
-1065832368 segments received
1831139460 segments sent
18 segments retransmitted
tcp:
2476943 active opens
713945482 passive opens
322859 failed attempts
2073710 resets of established connections
694522544 current established connections
-1065832365 segments received
1831139460 segments sent
18 segments retransmitted
udp:
1244436728 total datagrams received
0 datagrams to invalid port
29924 datagrams dropped due to errors
1244436695 output datagram requests
udp:
1244436728 total datagrams received
0 datagrams to invalid port
29924 datagrams dropped due to errors
1244436695 output datagram requests

SNMP is a useful protocol, and I am looking forward to seeing more vendors support SNMPv3.

This article was posted by Matty on 2006-08-03 08:16:00 -0400 -0400