在 Windows 上使用 SNMP 计算内存使用情况
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5120212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Figure out memory usage using SNMP on Windows
提问by timeshift
Currently i use the following to figure it out:
目前我使用以下方法来弄清楚:
For total memory:
对于总内存:
.1.3.6.1.2.1.25.2.2.0
For used memory i walk the following oid (gives me usage of each process):
对于已用内存,我执行以下 oid(让我了解每个进程的使用情况):
.1.3.6.1.2.1.25.5.1.1.2
and sum them all.
并将它们全部汇总。
However, this is very inaccurate, because it shows much less usage than if i use WMI or the performance monitor.
然而,这是非常不准确的,因为它显示的使用量比我使用 WMI 或性能监视器时少得多。
Am i missing something? I do not want to use third party SNMP agents (like SNMP informant, which works correctly btw). I wanna figure it out using what's standard in windows.
我错过了什么吗?我不想使用第三方 SNMP 代理(如 SNMP 线人,顺便说一句,它可以正常工作)。我想用 Windows 中的标准来弄清楚。
回答by Bill
Try 1.3.6.1.2.1.25.2.3.1. I received the following results with Net-SNMP's snmpwalk utility from one of our Windows Server 2003 servers:
尝试1.3.6.1.2.1.25.2.3.1。我使用 Net-SNMP 的 snmpwalk 实用程序从我们的一台 Windows Server 2003 服务器收到以下结果:
$ snmpwalk -v1 -cpublic 10.200.80.221 1.3.6.1.2.1.25.2.3.1.3
HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: C:\ Label: Serial Number 38728140
HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: D:\
HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: O:\ Label:Data Serial Number b618c4bc
HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: Q:\ Label:Quorum Serial Number 4cbbcc74
HOST-RESOURCES-MIB::hrStorageDescr.5 = STRING: Virtual Memory
HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: Physical Memory
$ snmpwalk -v1 -cpublic 10.200.80.221 1.3.6.1.2.1.25.2.3.1.4
HOST-RESOURCES-MIB::hrStorageAllocationUnits.1 = INTEGER: 4096 Bytes
HOST-RESOURCES-MIB::hrStorageAllocationUnits.2 = INTEGER: 0 Bytes
HOST-RESOURCES-MIB::hrStorageAllocationUnits.3 = INTEGER: 4096 Bytes
HOST-RESOURCES-MIB::hrStorageAllocationUnits.4 = INTEGER: 4096 Bytes
HOST-RESOURCES-MIB::hrStorageAllocationUnits.5 = INTEGER: 65536 Bytes
HOST-RESOURCES-MIB::hrStorageAllocationUnits.6 = INTEGER: 65536 Bytes
$ snmpwalk -v1 -cpublic 10.200.80.221 1.3.6.1.2.1.25.2.3.1.5
HOST-RESOURCES-MIB::hrStorageSize.1 = INTEGER: 17911195
HOST-RESOURCES-MIB::hrStorageSize.2 = INTEGER: 0
HOST-RESOURCES-MIB::hrStorageSize.3 = INTEGER: 66794245
HOST-RESOURCES-MIB::hrStorageSize.4 = INTEGER: 35836990
HOST-RESOURCES-MIB::hrStorageSize.5 = INTEGER: 128101
HOST-RESOURCES-MIB::hrStorageSize.6 = INTEGER: 98266
$ snmpwalk -v1 -cpublic 10.200.80.221 1.3.6.1.2.1.25.2.3.1.6
HOST-RESOURCES-MIB::hrStorageUsed.1 = INTEGER: 1365706
HOST-RESOURCES-MIB::hrStorageUsed.2 = INTEGER: 0
HOST-RESOURCES-MIB::hrStorageUsed.3 = INTEGER: 38290
HOST-RESOURCES-MIB::hrStorageUsed.4 = INTEGER: 17637
HOST-RESOURCES-MIB::hrStorageUsed.5 = INTEGER: 4819
HOST-RESOURCES-MIB::hrStorageUsed.6 = INTEGER: 6952
What is important here are the 5th and 6th rows of the tables. If you have fewer hard disks then you can find the values of virtual and physical memory in other rows.
这里重要的是表格的第 5 行和第 6 行。如果您的硬盘较少,那么您可以在其他行中找到虚拟内存和物理内存的值。
回答by Lex Li
You may either report this as a bug to Microsoft and wait for a fix, or simply switch to another agent.
您可以将此作为错误报告给 Microsoft 并等待修复,或者干脆切换到另一个代理。
Microsoft prefers WMI to SNMP, so you should know the agent is only a second class citizen on Windows.
与 SNMP 相比,Microsoft 更喜欢 WMI,因此您应该知道代理只是 Windows 上的二等公民。