Search code examples
pythonnetwork-programmingmonitoringsnmppysnmp

How to use pysnmp to monitor system resources?


Hello I am new to python and snmp and I was wondering how can I use pysnmp to monitor system resources such as CPU usage, Memory usuage, Disk usage and NIC Load?

I am experimenting with the cmdgen.CommandGenerator().getCmd() but having a hard time finding the OIDs that will return me anything meaningful.

An example of what I have tried (cpu usage query):

errorIndication, errorStatus, errorIndex, varBinds =
    cmdgen.CommandGenerator().getCmd(
    cmdgen.CommunityData('my-agent', 'public', 0),
    cmdgen.UdpTransportTarget(('localhost', 161)),
    '1.3.6.1.4.1.11.2.3.1.1.13'
    )
print(varBinds)

output:

[(ObjectName(1.3.6.1.4.1.2021.10.1.3.1), Null(''))]

Solution

  • You could try a free MIB browser like mbrowse, and look at the mibs stored in /usr/share/snmp/mibs/

    For specific examples ( Taken from http://www.debianhelp.co.uk/linuxoids.htm ):

    Load

               1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
               5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
               15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3
    

    CPU

               percentage of user CPU time:    .1.3.6.1.4.1.2021.11.9.0
               raw user cpu time:                  .1.3.6.1.4.1.2021.11.50.0
               percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
               raw system cpu time:              .1.3.6.1.4.1.2021.11.52.0
               percentages of idle CPU time:   .1.3.6.1.4.1.2021.11.11.0
               raw idle cpu time:                   .1.3.6.1.4.1.2021.11.53.0
               raw nice cpu time:                  .1.3.6.1.4.1.2021.11.51.0
    

    Memory Statistics

               Total Swap Size:                .1.3.6.1.4.1.2021.4.3.0
               Available Swap Space:         .1.3.6.1.4.1.2021.4.4.0
               Total RAM in machine:          .1.3.6.1.4.1.2021.4.5.0
               Total RAM used:                  .1.3.6.1.4.1.2021.4.6.0
               Total RAM Free:                   .1.3.6.1.4.1.2021.4.11.0
               Total RAM Shared:                .1.3.6.1.4.1.2021.4.13.0
               Total RAM Buffered:              .1.3.6.1.4.1.2021.4.14.0
               Total Cached Memory:           .1.3.6.1.4.1.2021.4.15.0