2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/drbd/drbd
2012-02-13 18:24:46 +01:00

144 lines
4.1 KiB
Perl
Executable File

#!/usr/bin/perl
# http://www.drbd.org/users-guide/ch-admin.html#s-proc-drbd
use strict;
my $file="/proc/drbd";
my $store = {};
my $temp;
&crunch;
&display;
sub display{
if ($ARGV[0] and $ARGV[0] eq "config"){
print "graph_title DRBD\n";
print "graph_category DRBD\n";
print "graph_info Graph DRBD\n";
print "graph_vlabel Bytes per \${graph_period} read (-) / written (+)\n";
print "graph_args --base 1024 --lower-limit 0\n";
foreach my $key ( keys %$store ){
my $drbdname = 'drbd'.$key;
print $drbdname."dr.label $drbdname disk\n";
print $drbdname."dr.cdef ".$drbdname."dr,819,*\n";
print $drbdname."dr.type DERIVE\n";
print $drbdname."dr.min 0\n";
print $drbdname."dr.graph no\n";
print $drbdname."dw.label $drbdname disk\n";
print $drbdname."dw.cdef ".$drbdname."dw,819,*\n";
print $drbdname."dw.type DERIVE\n";
print $drbdname."dw.min 0\n";
print $drbdname."dw.negative ".$drbdname."dr\n";
print $drbdname."nr.label $drbdname net\n";
print $drbdname."nr.cdef ".$drbdname."nr,819,*\n";
print $drbdname."nr.type DERIVE\n";
print $drbdname."nr.min 0\n";
print $drbdname."nr.graph no\n";
print $drbdname."ns.label $drbdname net\n";
print $drbdname."ns.cdef ".$drbdname."ns,819,*\n";
print $drbdname."ns.type DERIVE\n";
print $drbdname."ns.min 0\n";
print $drbdname."ns.negative ".$drbdname."nr\n";
}
exit 0;
}
foreach my $key ( keys %$store ){
my $drbdname = 'drbd'.$key;
print $drbdname."dw.value ".$store->{$key}->{'dw'}."\n";
print $drbdname."dr.value ".$store->{$key}->{'dr'}."\n";
print $drbdname."ns.value ".$store->{$key}->{'ns'}."\n";
print $drbdname."nr.value ".$store->{$key}->{'nr'}."\n";
}
}
sub crunch{
open (IN, $file ) || die "Could not open $file for reading: $!";
while (<IN>){
next if /version:|GIT-hash:/;
chomp;
my ($drbd) = $_ =~ /^\s+(\d):/;
$temp = $drbd if $drbd =~ /\d/;
if (/resync/){
my ($hits) = $_ =~ /hits:(\d*)/;
$store->{ $temp }->{'resync'}->{hits} = $hits if $hits ne undef;
my ($misses) = $_ =~ /misses:(\d*)/;
$store->{ $temp }->{'resync'}->{misses} = $misses if $misses ne undef;
my ($starving) = $_ =~ /starving:(\d*)/;
$store->{ $temp }->{'resync'}->{starving} = $starving if $starving ne undef;
my ($dirty) = $_ =~ /dirty:(\d*)/;
$store->{ $temp }->{'resync'}->{dirty} = $dirty if $dirty ne undef;
my ($changed) = $_ =~ /changed:(\d*)/;
$store->{ $temp }->{'resync'}->{changed} = $changed if $changed ne undef;
}
if (/act_log/){
my ($hits) = $_ =~ /hits:(\d*)/;
$store->{ $temp }->{'act_log'}->{hits} = $hits if $hits ne undef;
my ($misses) = $_ =~ /misses:(\d*)/;
$store->{ $temp }->{'act_log'}->{misses} = $misses if $misses ne undef;
my ($starving) = $_ =~ /starving:(\d*)/;
$store->{ $temp }->{'act_log'}->{starving} = $starving if $starving ne undef;
my ($dirty) = $_ =~ /dirty:(\d*)/;
$store->{ $temp }->{'act_log'}->{dirty} = $dirty if $dirty ne undef;
my ($changed) = $_ =~ /changed:(\d*)/;
$store->{ $temp }->{'act_log'}->{changed} = $changed if $changed ne undef;
}
my ($ns) = $_ =~ /ns:(\d*)/;
$store->{ $temp }->{'ns'} = $ns if $ns ne undef;
my ($nr) = $_ =~ /nr:(\d*)/;
$store->{ $temp }->{'nr'} = $nr if $ns ne undef;
my ($dw) = $_ =~ /dw:(\d*)/;
$store->{ $temp }->{'dw'} = $dw if $dw ne undef;
my ($dr) = $_ =~ /dr:(\d*)/;
$store->{ $temp }->{'dr'} = $dr if $dr ne undef;
my ($al) = $_ =~ /al:(\d*)/;
$store->{ $temp }->{'al'} = $al if $dr ne undef;
my ($bm) = $_ =~ /bm:(\d*)/;
$store->{ $temp }->{'bm'} = $bm if $dr ne undef;
my ($lo) = $_ =~ /lo:(\d*)/;
$store->{ $temp }->{'lo'} = $lo if $dr ne undef;
my ($pe) = $_ =~ /pe:(\d*)/;
$store->{ $temp }->{'pe'} = $pe if $dr ne undef;
my ($ua) = $_ =~ /ua:(\d*)/;
$store->{ $temp }->{'ua'} = $ua if $dr ne undef;
my ($ap) = $_ =~ /ap:(\d*)/;
$store->{ $temp }->{'ap'} = $ap if $ap ne undef;
my ($hits) = $_ =~ /hits:(\d*)/;
$store->{ $temp }->{'hits'} = $hits if $hits ne undef;
my ($used) = $_ =~ /used:(\d*\\\d*)\s/;
$store->{ $temp }->{'used'} = $used if $used ne undef;
}
close (IN);
#print Dumper \$store;
}
exit 0;