summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-02-14 04:07:36 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-02-14 04:36:57 +0100
commiteef23fb03918f05f357a2ef54cf4f949b76c18ce (patch)
treec2c359f5e667f7689edc46389608b355f97a459f
parent2816f34bc6b18ee7bf2832966f9534c5c198eec3 (diff)
downloadvserver-monitoring-eef23fb03918f05f357a2ef54cf4f949b76c18ce.tar.gz
vserver-monitoring-eef23fb03918f05f357a2ef54cf4f949b76c18ce.tar.bz2
vserver-monitoring-eef23fb03918f05f357a2ef54cf4f949b76c18ce.zip
add multi host mode with NSCA-ng compatible output
-rwxr-xr-xcheck_load60
-rwxr-xr-xcheck_mem63
2 files changed, 91 insertions, 32 deletions
diff --git a/check_load b/check_load
index 6f068d7..59a8554 100755
--- a/check_load
+++ b/check_load
@@ -5,6 +5,7 @@ use warnings;
use VServer;
use Nagios::Plugin;
+use Nagios::Plugin::Functions;
our $VERSION = '1.6';
@@ -13,7 +14,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 load of vserver guests."
);
$plugin->add_arg(
@@ -58,11 +59,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 - load average:$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 $load = VServer::get_loadavg($id);
@@ -88,12 +106,19 @@ sub handle_vserver($$$$) {
$output .= " $load->{$key}";
}
- $n->nagios_exit($n->max_state(@status), "load average:$output");
+ if ($name) {
+ $n->nagios_exit($n->max_state(@status), "load average:$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;
}
@@ -113,20 +138,23 @@ for my $load (qw( load1 load5 load15 )) {
}
}
-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) {
+ $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 loadavg');
+ handle_vserver($context, \%warn, \%crit, $vserver);
+ $n->nagios_exit(UNKNOWN, 'unable to parse loadavg');
+}
+else {
+ for my $dir (glob("/proc/virtual/*/")) {
+ my $id = VServer::get_context_id_by_dir($dir);
+ handle_vserver($id, \%warn, \%crit, undef, $domain);
+ }
+}
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);
+ }
+}