Page 1 of 1

Memory Service Explanation

Posted: Wed Mar 30, 2016 2:46 pm
by angus
Hello,

Attached is a screen shot of a RAM monitoring service on a Linux machine. I do not understand the math at work here. If there is only 3952MB of RAM total available and 3553MB is used (3952MB - 3553MB = 399MB left) that leaves only 399MB left over. Yet the free amount is showing as 1522MB. Are the Buffers and Cached metrics included in the Used metric? Please explain how this works. I have a server admin requesting more RAM and need to make sure there is a need.

Thanks.

Re: Memory Service Explanation

Posted: Wed Mar 30, 2016 3:41 pm
by bwallace
To verify how much free RAM you have, on the Linux box run

Code: Select all

free -m 
and look at the row that says "-/+ buffers/cache" in the column that says "free". That is your answer in megabytes.

This site goes into futher detail:
http://www.linuxatemyram.com/

Re: Memory Service Explanation

Posted: Wed Mar 30, 2016 3:45 pm
by lmiltchev
Most probably your command is defined with "-n" on the client. In this case, the cached memory is added to the free memory.

(total-used+cached) / total * 100

If you don't pass the "-n" flag, the calculation would be:

(total-used) / total * 100

Here's some info on custom_check_mem usage, and linux cached memory:

https://support.nagios.com/wiki/index.p ... ree_Memory

Re: Memory Service Explanation

Posted: Wed Mar 30, 2016 4:10 pm
by ssax
Here is how it's calculated (two different programs but it will get us real close):

Code: Select all

[root@localhost linux-nrpe-agent]# free -m
             total       used       free     shared    buffers     cached
Mem:           995        765        229          0         11        205
-/+ buffers/cache:        548        446
Swap:         2015         21       1994

Code: Select all

[root@localhost linux-nrpe-agent]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 30 -c check_mem -a '-w 20 -c 10'
OK - 434 / 995 MB (43%) Free Memory, Used: 766 MB, Shared: 0 MB, Buffers: 11 MB, Cached: 205 MB | total=995MB free=434MB used=766MB shared=0 buffers=11MB cached=205MB
434 = (free + cached)
995 = total
766 = (total - free)

Re: Memory Service Explanation

Posted: Thu Nov 10, 2016 10:12 am
by jhethke
Just curious, but if the explanation for what custom_check_mem is doing is to look at linuxatemyram.com, then why is the custom_check_mem script using the wrong fields to determine available memory? For example, looking at the below 'free -m' output, the memory the OS see's as available for new applications is the number under the 'free' column on the 'buffers/cache' row, and if you take the columns 'free, buffers, and cached' from the 'Mem:' row you get the same number as what is on the 'buffers/cache' row. Looking at the script, it is taking the number under 'free' on the 'Mem:' line and if you use the '-n' option, it adds the 'cached' number as well. Ultimately, this leads to false alerts since the available memory is actually greater than what the script is calculating. See example below for a little more clarity.

These numbers and calculations work on at least RHEL 5, 6 and 7.


total used free shared buffers cached
Mem: 3828 2722 1105 0 535 1386
-/+ buffers/cache: 800 3027
Swap: 4095 0 4095

- Example -
custome_check_mem -n: free + cached = 1105 + 1386 = 2491
actual available memory: free + buffers + cached = 1105 + 535 + 1386 = 3026 (or 3027 as listed on under free on the buffers/cache line)

Re: Memory Service Explanation

Posted: Thu Nov 10, 2016 11:50 am
by avandemore
All of those metrics are accurate or inaccurate depending on your point of view. Figuring out if a system needs more memory allocated to it is quite simple assuming it's operating normally eg not a bad plugin or something.

Simply watch the swap usage and if it's paging frequently it could benefit from more RAM. Most everything else ends in a wild goose chase because you have understand top down how the system is doing everything as well as if OOM killer is in play. Much more accurate to watch swap in/out paging. So graphing and alert on something like the output of vmstat 1 is much more meaning full than anything free(1) will tell you in terms of "Do I need more RAM".