How to monitor available memory (including cache and cache) in Java?
I have searched for possible solutions, such as how to monitor the computer's CPU, memory, and disk usage in Java But the memory used in buffers and caches is not mentioned anywhere?
For example, on Linux, output free - M:
total used free shared buffers cached Mem: 2011 1835 175 0 309 847 -/+ buffers/cache: 678 1333 Swap: 1998 0 1998
I have tested the output of sigar, which reports 175 MB of available memory
The reason for this problem is when the operating system has little memory? In the previous free - M output, 175mb seemed quite low; But by adding buffers and caches, it is clear that the available memory is actually 1333 MB of 2 GB
All in all, can you get a value of 1333 MB as the value of available memory using Java? As I have mentioned, so far, I only know how to get 175 MB value
Solution
If you are trying to get the memory statistics of the operating system itself (not the JVM), you can use JNA or JNI to map platform specific native API calls directly to the operating system