System Administration
Showing results for 
Search instead for 
Did you mean: 

Need help in adding 'LowFree' value of /proc/meminfo in Nagios script.

Frequent Advisor

Need help in adding 'LowFree' value of /proc/meminfo in Nagios script.


I have attached a script(check_ram)which is for memory monitoring in Nagios. I have tested and it's working fine. I would like to add the 'LowFree' value of /proc/meminfo in that so that it checks and sends the alert based on LowFree value of /proc/meminfo. As of now this scripts checks the other value of /proc/meminfo and sends the alert.

I am not good in scripting and need you help on this.

Thanks in advance.
Honored Contributor

Re: Need help in adding 'LowFree' value of /proc/meminfo in Nagios script.

Hi Gaby,

your attachment is a Nagios plug-in written in Python.
Though I can read the Python code I am not into scripting in Python.
Had it been a Perl or Bash plug-in I probably could have helped.

Hey, but this is good way for you to get started learning some Python.
Although I am quite perl-biased some Python skills won't hurt (especially on RedHat Linux much of their systems programming is done in Python, e.g. Yum).

Only bear in mind that in Python indentations are mandatory.
It doesn't matter how many spaces you indent the control structure or function blocks as long as all lines within them are indented by the same spacing.

So if you're interested in LowFree why not just add an extra elif block here?

for x in range(len(output)):
y = output[x].split()
if y [0] == "MemTotal:":
memtotal = int(y[1])
elif y[0] == "MemFree:":
memfree = int(y[1])
elif y[0] == "Cached:":
memcached = int(y[1])
elif y[0] == "LowFree:":
lowfree = int(y[1])

Then of course this list also needs to be extended:

for x in memtotal,memfree,memcached,lowfree:

Some more work is required within the memory arithmetics block following the parsing
because the plug-in caters for passed in warning and critical thresholds in a variety of units (e.g. KB, MB, GB, %).

As a general hint I would suggest that you replaced the conditionals referring to total_free by something like e.g.

if lowfree < critical_threshold:


It simply requires a bit of fiddling on your behalf.
Since Python is a scripting language there are no long compile cycles involved and you can try out changes to the code immediately as you script along.

Or if you cannot reconcile with the idea of scripting at all ask some Python hacker to do the little changes for you.

Madness, thy name is system administration
Frequent Advisor

Re: Need help in adding 'LowFree' value of /proc/meminfo in Nagios script.

Hi Ralph,

Thanks a lot for the reply. I have a perl script as well which I am attaching here.

Could you please help me to add the LowFree (/proc/meminfo) option in that. I have tested this script and it's working fine but I need to add the 'LowFree' of /proc/meminfo in the same so that I can get alert whenever the LowFree is below 100MB.

Honored Contributor

Re: Need help in adding 'LowFree' value of /proc/meminfo in Nagios script.

Hi Gaby,

I have patched your post's attachment that included the Nagios plug-in and attached my patch
although it probably would have been wiser to rewrite the plug-in from scratch.

As I wasn't so sure how your requirement with regard to the LowFree value is
I assumed that it would be ok to just relate it to LowTotal and stick to the relative free check in percentage.
Thus, I got rid of all the code parts that applied to the -f, -u, and -C options to the plug-in.
Hope, that is somewhat close to your requirement.

Ah, and since you posted this thread in the Linux Forum I of course also got rid of the code bits that cater for running this plug-in on Solaris where either the existence of the KStat module or some parsing of (Solaris) vmstat's output was required.

To apply my patch just copy your original plug-in to e.g. and then issue

$ patch

Madness, thy name is system administration