Created
October 8, 2013 10:59
-
-
Save robrwo/6882994 to your computer and use it in GitHub Desktop.
Quick and dirty munin plugin to monitor monit status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# This is a Perl version of the monit_parser from | |
# https://github.com/munin-monitoring/contrib/blob/master/plugins/monit/monit_parser | |
use v5.10.1; | |
use strict; | |
use warnings; | |
use Carp; | |
my %stats; | |
my $raw = `monit status`; | |
if (my $rc = $@) { | |
croak "Error running `monit status`\n"; | |
exit $rc; | |
} | |
foreach my $line (split /\n/, $raw) { | |
state $current; | |
if ($line =~ /^Process '([\w-]+)'/) { | |
$current = $1; | |
$stats{$current} = { }; | |
} elsif ($current) { | |
if ($line =~ /\s+memory kilobytes total\s+(\d+)/) { | |
$stats{$current}->{memory} = $1; | |
} elsif ($line =~ /\s+cpu percent total\s+(\d+[.]\d+)\%/) { | |
$stats{$current}->{cpu} = $1; | |
} elsif ($line =~ /\s+children\s+(\d+)/) { | |
$stats{$current}->{children} = $1; | |
} | |
} | |
} | |
if (@ARGV && $ARGV[0] eq 'config') { | |
say "graph_title Per Process stats from Monit"; | |
say "graph_vlabel numbers"; | |
say "graph_category monit"; | |
foreach my $process (keys %stats) { | |
foreach my $val (keys %{$stats{$process}}) { | |
say sprintf('monit_%s_%s.label %s.%s', $process, $val, $process, $val); | |
} | |
} | |
} else { | |
foreach my $process (keys %stats) { | |
foreach my $val (keys %{$stats{$process}}) { | |
say sprintf('monit_%s_%s.value %s', $process, $val, $stats{$process}->{$val}); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment