summaryrefslogtreecommitdiffstats
path: root/check_mem
diff options
context:
space:
mode:
Diffstat (limited to 'check_mem')
-rwxr-xr-xcheck_mem74
1 files changed, 18 insertions, 56 deletions
diff --git a/check_mem b/check_mem
index 2c3321d..725bedf 100755
--- a/check_mem
+++ b/check_mem
@@ -5,7 +5,6 @@ use warnings;
use VServer;
use Nagios::Plugin;
-use POSIX;
our $VERSION = '1.6';
@@ -63,41 +62,6 @@ sub parse_thresholds($) {
return undef;
}
-sub get_mem($$) {
- my $n = shift;
- my $context = shift;
-
- my $proc = VServer::get_proc_dir($context);
- $n->nagios_exit(UNKNOWN, "vserver not running") unless($proc);
-
- my $ps = POSIX::sysconf(&POSIX::_SC_PAGESIZE);
- $n->nagios_exit(UNKNOWN, "unable to determine pagesize") unless $ps;
-
- open(my $limit, "<", "$proc/limit") ||
- $n->nagios_exit(UNKNOWN, "could not open '$proc/limit'");
-
- my @mem = undef;
- while (<$limit>) {
- if ($_ =~ m/^VM:\s*([0-9]+)\s/) {
- $mem[0] = $1 * $ps;
- }
- elsif ($_ =~ m/RSS:\s*([0-9]+)\s/) {
- $mem[1] = $1 * $ps;
- }
- elsif ($_ =~ m/ANON:\s*([0-9]+)\s/) {
- $mem[2] = $1 * $ps;
- }
- elsif ($_ =~ m/VML:\s*([0-9]+)\s/) {
- $mem[3] = $1 * $ps;
- }
-
- }
-
- close($limit);
-
- return @mem;
-}
-
# fix taint mode
if ($0 =~ m/(\w[\w\/]*\w)/) {
@@ -109,8 +73,8 @@ $n->getopts();
alarm $n->opts->timeout;
my (%warn, %crit);
-($warn{'VM'}, $warn{'RSS'}, $warn{'ANON'}, $warn{'VML'}) = parse_thresholds($n->opts->w);
-($crit{'VM'}, $crit{'RSS'}, $crit{'ANON'}, $crit{'VML'}) = parse_thresholds($n->opts->c);
+($warn{'vm'}, $warn{'rss'}, $warn{'anon'}, $warn{'vml'}) = parse_thresholds($n->opts->w);
+($crit{'vm'}, $crit{'rss'}, $crit{'anon'}, $crit{'vml'}) = parse_thresholds($n->opts->c);
my $vserver = shift;
unless ($vserver) {
@@ -127,38 +91,36 @@ unless ($context) {
$n->nagios_exit(UNKNOWN, "vserver '$vserver' not found");
}
-my @mem = get_mem($n, $context);
-if (@mem) {
- my %values;
+my $mem = VServer::get_mem($id);
+if ($mem) {
my %desc;
- ($values{'VM'}, $values{'RSS'}, $values{'ANON'}, $values{'VML'}) = @mem;
%desc = (
- VM => 'virtual memory',
- RSS => 'resident set size',
- ANON => 'anonymous memory',
- VML => 'locked memory',
+ vm => 'virtual memory',
+ rss => 'resident set size',
+ anon => 'anonymous memory',
+ vml => 'locked memory',
);
my @status = [ UNKNOWN ];
my $output = "";
- for my $mem (qw( VM RSS ANON VML )) {
- $n->add_perfdata(label => $mem,
- value => $values{$mem},
+ for my $key (qw( vm rss anon vml )) {
+ $n->add_perfdata(label => $key,
+ value => $mem->{$key},
min => 0,
- warning => $warn{$mem},
- critical => $crit{$mem},
+ warning => $warn{$key},
+ critical => $crit{$key},
);
push(@status,
- $n->check_threshold(check => $values{$mem},
- warning => $warn{$mem},
- critical => $crit{$mem},
+ $n->check_threshold(check => $mem->{$key},
+ warning => $warn{$key},
+ critical => $crit{$key},
)
);
- $values{$mem} = int(($values{$mem} / 1024) / 1024);
- $output .= " - $desc{$mem}: $values{$mem}MB";
+ $mb = int(($mem->{$key} / 1024) / 1024);
+ $output .= " - $desc{$mem}: ${mb}MB";
}
$n->nagios_exit($n->max_state(@status), "used memory$output");