Nagios plugin: and

Nagios plugin: and

I have written a couple more Nagios plugins for use with NRPE on linux machines. The first one, “ ,” grabs the cpu state from “/proc/stats” and sends back a status result and perfdata. You can tell it to send back either the aggregate data from all cpus as a single total or can have it return all cpus individually. Be aware though, that if you wish to have it send data on all cpu’s you will need to patch Nagios to allow for a larger perfdata return buffer. I didn’t want to mess with doing that, so I just have it watch the aggregate data. preview

The second plugin, “,” will parse the output of “free -mt” to give you a look at the current memory and swap utilization. preview

13 thoughts on “Nagios plugin: and

  1. Hi,
    i really like your plugins, but i somehow hit a bug in check_cpu. if the load is less than 1.0, i get the following output:
    /usr/local/nagios/libexec/check_cpu: line 191: [: -ge: unary operator expected
    /usr/local/nagios/libexec/check_cpu: line 192: [: -ge: unary operator expected
    OK: CPU=.76 | used=.76;;;; system=.38;;;; user=.13;;;; nice=.04;;;; iowait=.21;;;; irq=0;;;; softirq=0;;;;
    the script continues to run, but nagios tells me the result is unknown:Remote command execution failed: /usr/local/nagios/libexec/check_cpu: line 191: [: -ge: unary operator expected
    it would be nice to have a fix for this.
    thank you in advance.

  2. I don’t see this happening on my system. Can you give me the exact command line you are using? I suspect you are putting invalid data in the -w (line 191) and -c (line 192) values. These should be passed as whole numbers, not decimal values…

    The command line should read… -w 75 -c 90
    not… -w 0.75 -c 0.90

  3. This happens to me too, but only when the total cpu load goes below one percent.

    I assume the tests on line 191 and 192 round a cpu load value below 1.0 as zero, which is somehow transformed into a null value, hence the -ge test fails “unary operator expected”.

  4. You can simply fix the bug by adding the following four lines just above line 191. It just adds an extra zero if necessary:

    if [[ ${pct_used[${cpucount}]} == .* ]]

  5. OK. I see what’s happening… your distro must be passing the result from procstat without any leading zero on a value of less than one. Mine passes it with the leading zero on small decimal numbers. That is why I don’t see this error happening. Ville’s patch will certainly work to fix this. Thanks for bringing this to my attention.

  6. Hi,
    Sorry for the late Answer. I’d like to thank you for the fix.
    I will add those lines to the Script.
    Meanwhile made a quick-n-dirty solution by replacing the lines with
    [ $(cut -d’.’ -f 1 /dev/null 2>&1 ${warning} ] && exitstatus=1
    [ $(cut -d’.’ -f 1 /dev/null 2>&1 ${critical} ] && exitstatus=2
    and redirecting the Output to /dev/null which also seems to work.


  7. Howdy!

    Great plugin… alas – it appears that the PHP template spits out a Undefined offset: 8 for line 48… for check_cpu. Any ideas?


  8. Hello guys, I used plugin, but the problem is still using the default template even though I have put check_nrpe_mem.php in template.dist directory, but the way I’m using pnp4nagios, please advise how to fix this so that will use check_nrpe_mem.php template for graphing.


  9. @Gene @comment9
    Change line 48 to be “while (isset($DS[$i]) != “” ) {”

    @idegz @comment10,
    You need to change CUSTOM_TEMPLATE to “CUSTOM_TEMPLATE = 0,1” in pnp4nagios/etc/check_commands/check_nrpe.cfg (maybe you need to create the file)

    Than place check_nrpe_mem.php in pnp4nagios/share/templates and rename it to

Leave a Reply