2

您好,我是 python 和 snmp 的新手,我想知道如何使用 pysnmp 来监控系统资源,例如 CPU 使用率、内存使用率、磁盘使用率和 NIC 负载?

我正在尝试cmdgen.CommandGenerator().getCmd()但很难找到能给我带来任何有意义的 OID。

我尝试过的一个例子(cpu使用查询):

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)

输出:

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

1 回答 1

2

您可以尝试免费的 MIB 浏览器,例如 mbrowse,并查看存储在 /usr/share/snmp/mibs/ 中的 mib

具体示例(取自http://www.debianhelp.co.uk/linuxoids.htm):

加载

           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

中央处理器

           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

内存统计

           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
于 2012-02-03T16:02:18.113 回答