#!/usr/bin/perl # Nagios plugin for monitoring hugemem usage # Written by Adrian Bridgett (c) Bitcube Ltd. 2009 # Released under GPL v3 license # For opsview use lib '/usr/local/nagios/perl/lib', '/usr/local/nagios/lib'; use warnings; use strict; use Nagios::Plugin; my $VERSION = "0.01"; my $np = Nagios::Plugin->new( usage => "Usage: %s [-w warning] [-c critical]", version => $VERSION, blurb => "Checks hugemem usage", ); $np->add_arg( spec => "warning|w=i", help => qq{-w, --warning=INTEGER Warning if there are fewer hugepages left than this}, default => 0, ); $np->add_arg( spec => "critical|c=i", help => qq{-c, --critical=INTEGER Critical if there are fewer hugepages left than this}, default => 0, ); $np->getopts; open PAGES, "nagios_exit(UNKNOWN, "Unable to read free hugepages"); my $free_pages = ; chomp $free_pages; close PAGES; open PAGES, "nagios_exit(UNKNOWN, "Unable to read number of hugepages"); my $total_pages = ; chomp $total_pages; close PAGES; $np->set_thresholds(warning => $np->opts->warning . ":", critical => $np->opts->critical . ":"); $np->add_perfdata(label => "Free hugepages", value => $free_pages, threshold => $np->threshold()); $np->add_perfdata(label => "Total hugepages", value => $total_pages); $np->nagios_exit(return_code => $np->check_threshold($free_pages), message => "$free_pages/$total_pages free")