MOON
Server: Apache
System: Linux cl1170g 4.19.62-mod-std-ipv6-64-rescue #828825 SMP Tue Jul 30 13:54:49 UTC 2019 x86_64
User: wh0f20bb (1057)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //usr/lib/nagios/plugins/check_mem.sh
#!/usr/bin/perl
# Copyright (c) 2012 Jason Hancock <jsnbyh@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# This file is part of the nagios-cpu bundle that can be found
# at https://github.com/jasonhancock/nagios-memory
use strict;
use warnings;
use Nagios::Plugin;
use Nagios::Plugin::Threshold;
my $np = Nagios::Plugin->new(
usage => "Usage: %s [-w|--warning=<percent> ] [ -c|--critical=<percent> ]",
shortname => 'MEMORY',
);
$np->add_arg(
spec => 'warning|w=s',
help => '-w, --warning=percent',
required => 1,
);
$np->add_arg(
spec => 'critical|c=s',
help => '-c, --critical=percent',
required => 1,
);
$np->getopts;
# read the data from /proc/meminfo into the %data hash
my %data;
open IN, '</proc/meminfo' or die('Can\'t read /proc/meminfo');
while(my $line=<IN>) {
if($line=~m/^(.+):\s+(\d+)/) {
$data{$1} = $2;
}
}
close IN;
# Calculate mem used
$data{'MemUsed'} = $data{'MemTotal'} - $data{'MemFree'} - $data{'Cached'} - $data{'Buffers'};
$np->add_perfdata(
label => 'used',
value => $data{'MemUsed'} * 1024,
uom => undef,
);
$np->add_perfdata(
label => 'cached',
value => $data{'Cached'} * 1024,
uom => undef,
);
$np->add_perfdata(
label => 'buffers',
value => $data{'Buffers'} * 1024,
uom => undef,
);
$np->add_perfdata(
label => 'free',
value => $data{'MemFree'} * 1024,
uom => undef,
);
# check the result against the defined warning and critical thresholds,
# output the result and exit
my $code = $np->check_threshold(
check => $data{'MemUsed'} * 1024,
warning => $np->opts->warning * .01 * $data{'MemTotal'} * 1024,
critical => $np->opts->critical * .01 * $data{'MemTotal'} * 1024,
);
$np->nagios_exit(
return_code => $code,
message => sprintf(
($np->opts->verbose ?
'%d%% used (used: %d kB cached: %d kB buffers: %d kB free: %d kB)' :
'%d%% used'),
($data{'MemUsed'} / $data{'MemTotal'}) * 100,
$data{'MemUsed'},
$data{'Cached'},
$data{'Buffers'},
$data{'MemFree'},
)
);