OperatingSystemMXBean
中的 getFreePhysicalMemorySize()
方法返回的值为不含缓存的可用物理内存,该指标不能很好的反应 Linux 中实际可用的物理内存,因为 Linux 尽量使用内存的特性,该指标返回的数据几乎总是接近总物理内存,我们根据 /proc/meminfo
中返回的数据采集出类似 free
命令中 available
列的值以便更好的监测可用物理内存。
部分代码如下:
1 | /** |
1 | public class OperatingSystemMemoryImpl implements OperatingSystemMemoryMXBean { |
Reference
How to monitor free memory ( including buffers and cache) in java? - Stack Overflow
jdk/OperatingSystemMXBean.java at jdk8-b120 · openjdk/jdk · GitHub
free(1) - Linux manual page
proc(5) - Linux manual page
extras-memory-monitor/ProcMemInfo.java at master · jenkinsci/extras-memory-monitor · GitHub
How to calculate system memory usage from /proc/meminfo (like htop) - Stack Overflow
/proc/meminfo: provide estimated available memory - Linux kernel source tree