summaryrefslogtreecommitdiffstats
path: root/check_mem
diff options
context:
space:
mode:
Diffstat (limited to 'check_mem')
-rwxr-xr-xcheck_mem63
1 files changed, 47 insertions, 16 deletions
diff --git a/check_mem b/check_mem
index fb25403..009f067 100755
--- a/check_mem
+++ b/check_mem
@@ -5,6 +5,7 @@ use warnings;
use VServer;
use Nagios::Plugin;
+use Nagios::Plugin::Functions;
our $VERSION = '1.6';
@@ -20,7 +21,7 @@ sub init_nagios_plugin() {
usage => "Usage: %s [-h|--help] [-w|--warnings=...] " .
"[-c|--critical=...] [-d|--domain=...] [vserver-name]",
version => $VERSION,
- blurb => "This plugin could monitor the load of single vserver guests."
+ blurb => "This plugin could monitor the memory of vserver guests."
);
$plugin->add_arg(
@@ -69,11 +70,28 @@ sub parse_thresholds($) {
return undef;
}
-sub handle_vserver($$$$) {
+sub output_results($$$$) {
+ my $n = shift;
+ my $name = shift;
+ my $statuses = shift;
+ my $output = shift;
+
+ my $service = $ENV{NAGIOS_PLUGIN};
+ my $status = $n->max_state(@{$statuses});
+ $status = Nagios::Plugin::Functions::UNKNOWN unless
+ defined $status && exists $Nagios::Plugin::Functions::STATUS_TEXT{$status};
+ my $result = $Nagios::Plugin::Functions::STATUS_TEXT{$status};
+ my $perf = $n->all_perfoutput();
+
+ print "$name\t$service\t$status\t$result - used memory$output | $perf\n\x17";
+}
+
+sub handle_vserver($$$;$$) {
my $id = shift;
my $warn = shift;
my $crit = shift;
my $name = shift;
+ my $domain = shift;
my $n = init_nagios_plugin();
my $mem = VServer::get_mem($id);
@@ -100,12 +118,19 @@ sub handle_vserver($$$$) {
$output .= " - $desc{$key}: ${mb}MB";
}
- $n->nagios_exit($n->max_state(@status), "used memory$output");
+ if ($name) {
+ $n->nagios_exit($n->max_state(@status), "used memory$output");
+ }
+ else {
+ $name = VServer::get_name($id);
+ output_results($n, "$name$domain", \@status, $output);
+ }
}
}
# fix taint mode
+$ENV{PATH} = undef;
if ($0 =~ m/(\w[\w\/]*\w)/) {
$ENV{'NAGIOS_PLUGIN'} = $1;
}
@@ -118,20 +143,26 @@ 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);
-my $vserver = shift;
-unless ($vserver) {
- $n->nagios_exit(UNKNOWN, "vserver name required");
-}
-
my $domain = '';
$domain = ('.' . $n->opts->d) if $n->opts->d;
-$domain = quotemeta $domain;
-$vserver =~ s/$domain$//;
-my $context = VServer::get_context_id($vserver);
-unless ($context) {
- $n->nagios_exit(UNKNOWN, "vserver '$vserver' not found");
-}
+if (my $vserver = shift) {
+ if (defined $domain) {
+ $domain = quotemeta $domain;
+ $vserver =~ s/$domain$//;
+ }
+
+ my $context = VServer::get_context_id_by_name($vserver);
+ unless ($context) {
+ $n->nagios_exit(UNKNOWN, "vserver '$vserver' not found");
+ }
-handle_vserver($context, \%warn, \%crit, $vserver);
-$n->nagios_exit(UNKNOWN, 'unable to parse memory statistics');
+ handle_vserver($context, \%warn, \%crit, $vserver);
+ $n->nagios_exit(UNKNOWN, 'unable to parse memory statistics');
+}
+else {
+ for my $dir (glob("/proc/virtual/*/")) {
+ my $id = VServer::get_context_id_by_dir($dir);
+ handle_vserver($id, \%warn, \%crit, undef, $domain);
+ }
+}