-1

I want to create a method to return the ram usage in the main OS NOT THE OS I tried the RunTime class and it return only the JVM ram usage, but I want it for the OS level

  • 1
    Does this answer your question? [Get OS-level system information](https://stackoverflow.com/questions/25552/get-os-level-system-information) – Marvin Apr 06 '20 at 18:52
  • 1
    Maybe this could help you? https://stackoverflow.com/questions/47177/how-do-i-monitor-the-computers-cpu-memory-and-disk-usage-in-java – CodingTil Apr 06 '20 at 18:59
  • both answers return the JVM ram usage I want it for the whole system – Ibraheem Abdu Apr 06 '20 at 19:07
  • Out of curiosity, what do you mean by "ram usage...for the OS level?" The most simplistic answer is that an OS normally uses _all_ of the RAM, unless you have specially configured it not to do. A more sophisticated answer would recognize the many different ways in which a modern, demand-paged, virtual-memory OS can use RAM. For example, see the Unix [proc(5) man page](http://man7.org/linux/man-pages/man5/proc.5.html), and scroll down to the `/proc/meminfo` heading. What _kind_ of "ram usage" are you really interested in? – Solomon Slow Apr 06 '20 at 21:21
  • I want the use the usage in my system to auto alert me when the server have a high usage of ram, so yes I want to get the OS level usage – Ibraheem Abdu Apr 07 '20 at 14:53

1 Answers1

0

If you don't need portability you could read /proc/meminfo it might be what you are looking for and should be straight forward to parse.

A word of warning though, older kernel versions may have fewer rows of information. See for details https://access.redhat.com/solutions/406773

JohannesB
  • 2,214
  • 1
  • 11
  • 18
  • I want the use the usage in my system to auto alert me when the server have a high usage of ram – Ibraheem Abdu Apr 07 '20 at 14:52
  • Here an example from a system with 1.3 Gigabyte available: grep MemAvailable /proc/meminfo MemAvailable: 1373116 kB See also: https://superuser.com/questions/980820/what-is-the-difference-between-memfree-and-memavailable-in-proc-meminfo – JohannesB Apr 07 '20 at 14:55