#!/usr/bin/perl # Nagios plugin for monitoring KSM 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 KSM usage", ); $np->add_arg( spec => "warning|w=s", help => qq{-w, --warning=RANGE Warning if number of shared pages is outside this range}, default => 0, ); $np->add_arg( spec => "critical|c=s", help => qq{-c, --critical=RANGE Critical if number of shared pages is outside this range}, default => 0, ); $np->getopts; open PAGES, "nagios_exit(UNKNOWN, "Unable to read shared KSM pages"); my $ksm_shared = ; chomp $ksm_shared; close PAGES; open PAGES, "nagios_exit(UNKNOWN, "Unable to read sharing KSM pages"); my $ksm_sharing = ; chomp $ksm_sharing; close PAGES; open PAGES, "nagios_exit(UNKNOWN, "Unable to read unshared KSM pages"); my $ksm_unshared = ; chomp $ksm_unshared; close PAGES; open PAGES, "nagios_exit(UNKNOWN, "Unable to read volatile KSM pages"); my $ksm_volatile = ; chomp $ksm_volatile; close PAGES; $np->set_thresholds(warning => $np->opts->warning, critical => $np->opts->critical); $np->add_perfdata(label => "Shared KSM pages", value => $ksm_shared, threshold => $np->threshold()); $np->add_perfdata(label => "Sharing KSM pages", value => $ksm_sharing); $np->add_perfdata(label => "Unshared KSM pages", value => $ksm_unshared); $np->add_perfdata(label => "Volatile KSM pages", value => $ksm_volatile); $np->nagios_exit(return_code => $np->check_threshold($ksm_shared), message => "$ksm_shared shared pages, $ksm_sharing sharing pages, $ksm_unshared unshared pages, $ksm_volatile volatile pages");