Patching check_swap Nagios / Monitoring plugin to run without thresholds

Written by - 0 comments

Published on - Listed in Monitoring Coding Icinga Nagios Linux

While Swap (extended server memory on the disk) was an important helper 20 years ago (memory was expensive!), these days Swap memory is about to disappear. Kubernetes nodes for example should run without swap space and there are other applications which don't play nice with swapping.

Nevertheless, it's been crucial to monitor the Swap usage in all these years. The check_swap monitoring plugin is one of the first and original Nagios plugins, released in 1999. It does the job perfectly and alerts when the Swap space is used or about to be fully used.

check_swap requires thresholds

As Swap Memory has become less critical over these years, the Swap monitoring has been reduced to a performance or trouble identifier. Swap being used means there might have been a situation where the available memory ran out or something else didn't play as expected. But even if the Swap space would be fully used, it wouldn't mean the end for the running application.

For such situations, it would be enough to have the check_swap plugin check for the current Swap usage and consult the resulting historical (performance data) graphs if needed. Unfortunately with the current check_swap this is not possible, as check_swap requires warning and critical thresholds. An attempt to use the plugin without thresholds results in an error and the check is not executed:

ck@mint ~ $ /usr/lib/nagios/plugins/check_swap
check_swap: Could not parse arguments
 check_swap [-av] -w <percent_free>% -c <percent_free>%
  -w <bytes_free> -c <bytes_free> [-n <state>]

What if I don't want to be alerted at all and only check for the current Swap usage?

Patched check_swap to run without thresholds

Good news! This has been done now! The check_swap plugin, a monitoring plugin written in C, has been patched and now supports to be run without thresholds. 

Here's check_swap running without thresholds:

ck@mint ~/src/nagios-plugins/plugins $ ./check_swap
SWAP OK - 100% free (4091 MB out of 4091 MB) |swap=4091MB;0;0;0;4091

In case the Swap space is fully used, check_swap now returns OK when no thresholds are defined:

ck@debian:/tmp/nagios-plugins/plugins $ ./check_swap
SWAP OK - 0% free (0 MB out of 7627 MB) |swap=0MB;0;0;0;7627

And if thresholds are used, the plugin alerts again:

ck@debian:/tmp/nagios-plugins/plugins $ ./check_swap -w 10% -c 5%
SWAP CRITICAL - 0% free (0 MB out of 7627 MB) |swap=0MB;762;381;0;7627

The necessary pull requests have been submitted to the relevant projects:

According to feedback in the PR, the updated check_swap plugin should make it into the next feature release of nagios-plugins, which should be Nagios Plugins 2.5.x.

On the monitoring-plugins project, the PR has been merged and the updated check_swap will most likely make it into the next release, which should be either 2.3.6 or 2.4.x.

Until then you need to compile the check_swap plugin manually.

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

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   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