summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-02-14 03:51:19 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-02-14 04:36:57 +0100
commit2388161afa4fed244b7333c7edab62c68ad7ec6c (patch)
tree40326819509b9b4ab07171f22f1a1cf34e6c0033
parent6ccc388658b58bca0e89149c69bcc7bfa1cfed2f (diff)
downloadvserver-monitoring-2388161afa4fed244b7333c7edab62c68ad7ec6c.tar.gz
vserver-monitoring-2388161afa4fed244b7333c7edab62c68ad7ec6c.tar.bz2
vserver-monitoring-2388161afa4fed244b7333c7edab62c68ad7ec6c.zip
use methods from new VServer.pm
-rwxr-xr-xcheck_load48
-rwxr-xr-xcheck_mem74
2 files changed, 28 insertions, 94 deletions
diff --git a/check_load b/check_load
index 802839c..8a3b2c8 100755
--- a/check_load
+++ b/check_load
@@ -58,31 +58,6 @@ sub parse_thresholds($) {
return undef;
}
-sub get_load($$) {
- my $n = shift;
- my $context = shift;
-
- my $proc = VServer::get_proc_dir($context);
- unless ($proc) {
- $n->nagios_exit(UNKNOWN, "vserver not running");
- }
-
- open(my $cvirt, "<", "$proc/cvirt") ||
- $n->nagios_exit(UNKNOWN, "could not open '$proc/cvirt'");
-
- my @load = undef;
- while (<$cvirt>) {
- if ($_ =~ m/^loadavg:\s*([0-9.]+)\s*([0-9.]+)\s*([0-9.]+)$/) {
- @load = ($1, $2, $3);
- last;
- }
- }
-
- close($cvirt);
-
- return @load;
-}
-
# fix taint mode
if ($0 =~ m/(\w[\w\/]*\w)/) {
@@ -119,30 +94,27 @@ unless ($context) {
$n->nagios_exit(UNKNOWN, "vserver '$vserver' not found");
}
-my @load = get_load($n, $context);
+my $load = VServer::get_loadavg($id);
if (@load) {
- my %values;
- ($values{'load1'}, $values{'load5'}, $values{'load15'}) = @load;
-
my @status = [ UNKNOWN ];
my $output = "";
- for my $load (qw( load1 load5 load15 )) {
- $n->add_perfdata(label => $load,
- value => $values{$load},
- warning => $warn{$load},
- critical => $crit{$load},
+ for my $key (qw( load1 load5 load15 )) {
+ $n->add_perfdata(label => $key,
+ value => $load->{$key},
+ warning => $warn{$key},
+ critical => $crit{$key},
min => 0,
);
push(@status,
- $n->check_threshold(check => $values{$load},
- warning => $warn{$load},
- critical => $crit{$load}
+ $n->check_threshold(check => $load->{$key},
+ warning => $warn{$key},
+ critical => $crit{$key}
)
);
- $output .= " $values{$load}";
+ $output .= " $load->{$key}";
}
$n->nagios_exit($n->max_state(@status), "load average:$output");
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");