dynamic configuration with snmptable

I’m playing with snmp monitoring stuff (as usual) and it occurred to me there is an easier way to query resources that I want to monitor: snmptable. Frinstance, rather than look up the disks on a given system, why not run snmptable and get a list of the attached disks, then build a query around that?
[/Users/paul]:: snmptable -cpublic -Cw 80 -v2c red hrStorageTable
SNMP table: HOST-RESOURCES-MIB::hrStorageTable

hrStorageIndex hrStorageType
1 HOST-RESOURCES-TYPES::hrStorageOther
2 HOST-RESOURCES-TYPES::hrStorageRam
3 HOST-RESOURCES-TYPES::hrStorageVirtualMemory
4 HOST-RESOURCES-TYPES::hrStorageOther
5 HOST-RESOURCES-TYPES::hrStorageFixedDisk
6 HOST-RESOURCES-TYPES::hrStorageFixedDisk
7 HOST-RESOURCES-TYPES::hrStorageFixedDisk
8 HOST-RESOURCES-TYPES::hrStorageFixedDisk
9 HOST-RESOURCES-TYPES::hrStorageFixedDisk
10 HOST-RESOURCES-TYPES::hrStorageFixedDisk

SNMP table HOST-RESOURCES-MIB::hrStorageTable, part 2

hrStorageDescr hrStorageAllocationUnits hrStorageSize hrStorageUsed
Memory Buffers 256 Bytes 0 ?
Real Memory 4096 Bytes 39602 ?
Swap Space 4096 Bytes 5671053 ?
Memory Buffer Clusters 1024 Bytes 1024 ?
/ 1024 Bytes 99183 ?
/usr 1024 Bytes 7302338 ?
/var 1024 Bytes 19815 ?
/proc 4096 Bytes 1 ?
/opt 1024 Bytes 75746877 ?
/usr/compat/linux/proc 4096 Bytes 1 ?

So I would want the resources labelled hrStorageFixedDisk, and then get their hrStorageIndex, and the hrStorageDescr.
Then I can make snmpget requests from that: that would allow me to get the names/mountpoints for labelling.

[/Users/paul]:: snmpget -cpublic -v2c red hrStorageDescr.5 hrStorageUsed.5 hrStorageSize.5
HOST-RESOURCES-MIB::hrStorageDescr.5 = STRING: /
HOST-RESOURCES-MIB::hrStorageUsed.5 = INTEGER: 68136
HOST-RESOURCES-MIB::hrStorageSize.5 = INTEGER: 99183

The bonehead way would be to just loop over some range, but that lacks elegance.


Snmptable.Pl

This will print out the right snmpget commands to get the capacity and bytes used of all attached disks.

Works on FreeBSD and OS X, anyway. (I just re-discovered that, for mysterious reasons, all disk values returned by the snmp agent on OS X systems must be multiplied by 4. Curious.)

Two datapoints works fine for simple graphing tools like mrtg, but for more robust tools like rrdtool, I might also plot the transactions/activity on a given spindle. Not today, though.

Leave a Reply

Your email address will not be published. Required fields are marked *