Nagios plugin check_procs misses perfdata and how you can add it

Written by - 2 comments

Published on - Listed in Nagios Linux Monitoring


To my very big surprise one of the oldest original Nagios plugins (check_procs) doesn't seem to have performance data integrated in the output.

Here's a typical launch of the plugin on the command line, done with two different versions:

# ./check_procs --version
check_procs v2019 (nagios-plugins 1.4.13)

# ./check_procs -w 150 -c 300
PROCS OK: 97 processes

# ./check_procs --version
check_procs v1.4.15 (nagios-plugins 1.4.15)

# ./check_procs -w 150 -c 300
PROCS OK: 110 processes

None of them show the perfdata, which is followed after a pipe character (|) after the output.
To create graphics with Nagiosgraph, at least some output in the perfdata 'field' is necessary.

A quick research on the Nagios Plugin Sourceforce page shows that several patches have already been supplied to add perfdata to this plugin. The first was submitted in 2005, the newest as of now just a month ago in December 2011. But bummer, they never made it into the plugin.
So that means that the good Nagios admin has to take matters in his own hands. I show you now in a step-by-step tutorial how you can enable perfdata yourself, and this is very easy, believe me!

1. First download the Nagios plugin source file from the SourceForge website.

2. Untar/Unzip the file, I'm doing this in /tmp:

/tmp # tar -xfz nagios-plugins-1.4.15.tar.gz

3. Change dir into the newly created folder:

/tmp # cd nagios-plugins-1.4.15

4. Open the check_procs source file which is called 'check_procs.c' and is located in the 'plugins' subfolder with your favourite editor (like vim):

/tmp/nagios-plugins-1.4.15 # vim plugins/check_procs.c

5. Go to line 295 where this line should be (as of version 1.4.15):

printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs);

Just some lines below, add the following line just before the new line output (printf ("\n");) on line 305:

printf ("|procs=%d;%d;%d;0", procs, wmax, cmax);

So it looks like this at the end:

printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs);

if (strcmp(fmt,"") != 0) {
   printf (_(" with %s"), fmt);
}

if ( verbose >= 1 && strcmp(fails,"") )
   printf (" [%s]", fails);

printf ("|procs=%d;%d;%d;0", procs, wmax, cmax);
printf ("\n");
return result;

What we did is simple: To the standard output we add another output (not as a new line, but directly followed after the original output) by using the variables procs (The number of processes found), wmax (the defined warning threshold) and cmax (the defined critical threshold).

Once done, save the changes.

6. Still in the nagios-plugins folder, the plugins need to be compiled (or re-compiled):

/tmp/nagios-plugins-1.4.15 # ./configure
/tmp/nagios-plugins-1.4.15 # make

7. The new check_procs plugin can now be found in the plugins folder and you can copy it to the other plugins:

/tmp/nagios-plugins-1.4.15 # cp plugins/check_procs /usr/local/nagios/libexec/

8. Test it on the command line and you'll find the performance data output:

/usr/local/nagios/libexec # ./check_procs -w 150 -c 300
PROCS OK: 133 processes|procs=133;150;300;0

Hurray!

What's missing now is the Nagiosgraph map entry for check_procs. Here you go:

# Service Type: check_proc
# Regex by Claudio Kuenzler
# Nagios Output: PROCS OK: 114 processes
# Perfdata: procs=114;150;200;0
/perfdata:procs=(\d+);(\d+);(\d+);0/
and push @s, [procs,
        ['active', GAUGE, $1 ],
        ['warn', GAUGE, $2 ],
        ['crit', GAUGE, $3 ] ];

Enjoy!


Add a comment

Show form to leave a comment

Comments (newest first)

Claudio from Switzerland wrote on Feb 20th, 2012:

Yes, you are correct. I just tested this with some zombie processes and this is shown like this:

/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
PROCS OK: 0 processes|procs=0;5;10;0 with STATE = Z

Of course the 'with STATE = Z' should be in the output, not in the perfdata part. I will correct the article. Thanks for the hint!


ljorg from Denmark wrote on Feb 20th, 2012:

Isn't the added line supposed to come a little later in the source, like this:

printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs);

if (strcmp(fmt,"") != 0) {
printf (_(" with %s"), fmt);
}

if ( verbose >= 1 && strcmp(fails,"") )
printf (" [%s]", fails);

printf ("|procs=%d;%d;%d;0", procs, wmax, cmax);

printf ("\n");


(just above the final newline). If not then additional output like "with args 'test'" will be appended to the performance data.


RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Icingaweb   Icingaweb2   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder   


Update cookies preferences