# free -m total used free shared buffers cached Mem: 72363 68035 4328 0 522 66294 -/+ buffers/cache: 1218 71145 Swap: 12291 0 12291
还有这个:
# snmpwalk -c public -v 2c localhost .1.3.6.1.4.1.2021.4 UCD-SNMP-MIB::memIndex.0 = INTEGER: 0 UCD-SNMP-MIB::memErrorName.0 = STRING: swap UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 12586888 kB UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 12586784 kB UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 74100516 kB UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 4429580 kB UCD-SNMP-MIB::memTotalFree.0 = INTEGER: 17016364 kB UCD-SNMP-MIB::memMinimumSwap.0 = INTEGER: 16000 kB UCD-SNMP-MIB::memBuffer.0 = INTEGER: 534804 kB UCD-SNMP-MIB::memCached.0 = INTEGER: 44238560 kB UCD-SNMP-MIB::memSwapError.0 = INTEGER: noError(0) UCD-SNMP-MIB::memSwapErrorMsg.0 = STRING:
为什么免费显示66294MB用于“缓存”,而snmp显示大约44238MB用于“memCached”?那应该不一样吗?
看看MIB我发现“memCached”是用于缓存的“物理或虚拟”内存. (不要告诉我它将磁盘缓存放入交换中)^^
目标是通过snmp找出真正的自由物理内存(即此处为免费显示的71145).
更多信息
# cat /proc/meminfo MemTotal: 74100516 kB MemFree: 4422092 kB Buffers: 542168 kB Cached: 44239460 kB SwapCached: 4 kB Active: 16455504 kB Inactive: 28707308 kB SwapTotal: 12586888 kB SwapFree: 12586784 kB Dirty: 2536 kB Writeback: 0 kB AnonPages: 381088 kB Mapped: 252132 kB Slab: 23961488 kB SReclaimable: 23648768 kB SUnreclaim: 312720 kB PageTables: 7812 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 49637144 kB Committed_AS: 4 kB VmallocTotal: 34359738367 kB VmallocUsed: 264124 kB VmallocChunk: 34359474191 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 7936 kB DirectMap2M: 75481088 kB
解决方法
cache Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo)
free包括缓存中的slab分配; UCD-SNMP-MIB没有.如果你添加slab分配,你会得到:
UCD-SNMP-MIB::memCached.0 + slab = 44238560 + 23961488 = 68200048 KB
这更接近免费报道(67885056 KB).
至于获得真正的自由物理内存,使用此MIB可以做的最好的事情是粗略估计:
totFree = memAvailReal.0 + memBuffer.0 + memCached.0 = 4429580 + 534804 + 44238560 = 49202944 KB
这仍然明显低于免费报告的空闲缓冲区/缓存的值.
请注意,HOST-RESOURCES-MIB并不是更好;请参阅my answer到Stack Overflow上的类似问题.
较新的内核实际上为此提供了更好的指标.再次从free(1)手册页:
available
Estimation of how much memory is available for starting new applications,without swapping. Unlike the data provided by the cache or free fields,this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo,available on kernels 3.14,emulated on kernels 2.6.27+,otherwise the same as free)
这个值将低于可用缓冲区/缓存的总和,并且可以更好地衡量可用内存,但我没有在/ proc / meminfo中看到它并且我没有找到使用它的MIB.