Bonding Device

gleichzeitige Überwachung von bond0, eth0 und eth1

Nagios Plugin

#!/usr/bin/perl

# check_bonded_traffic.pl - nagios plugin 
#
# Author: Michael Mende 
# Last change: 2010-07-28

use strict;
use warnings;
use Sys::Statistics::Linux;

my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
my $exit = 'UNKNOWN';
my %warn=('rxbyt'=>700,'txbyt'=>700,'ttbyt'=>800);
my %crit=('rxbyt'=>800,'txbyt'=>800,'ttbyt'=>900);

sub toM {
    my ($i) = @_;
    $i*8/1024/1024;
}
umask(0027);

my $cachefile = '/tmp/nagios-sysstats-netstats.yml';
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($cachefile);
if (-e $cachefile and ( -l $cachefile or $uid != $>)) {
    printf "%s Cachefile insecure: %s\n", "UNKNOWN", $cachefile;
    exit $ERRORS{UNKNOWN};
}

my $lxs = Sys::Statistics::Linux->new(
    netstats => {
        init => 1,
        initfile => $cachefile
    }
);

my $stat = $lxs->get(); # without to sleep

my ($out,$perf);
$exit = 'OK';
foreach my $k (keys(%{$stat->netstats})) {
    next unless $k =~ /^(eth[01]|bond0)$/;
    if (&toM($stat->netstats->{$k}{rxbyt}) > $warn{rxbyt} or
        &toM($stat->netstats->{$k}{txbyt}) > $warn{txbyt} or
        &toM($stat->netstats->{$k}{ttbyt}) > $warn{ttbyt}) {
        $exit = 'WARN';
    } elsif (&toM($stat->netstats->{$k}{rxbyt}) > $crit{rxbyt} or
           &toM($stat->netstats->{$k}{txbyt}) > $crit{txbyt} or
           &toM($stat->netstats->{$k}{ttbyt}) > $crit{ttbyt}) {
    $exit = 'CRIT';
  }

    $out .= sprintf ("RX[%s]=%.2fMbps TX[%s]=%.2fMbps TOTAL[%s]=%.2fMbps ", $k, &toM($stat->netstats->{$k}{rxbyt}), $k, &toM($stat->netstats->{$k}{txbyt}), $k, &toM($stat->netstats->{$k}{ttbyt}));
    $perf .= sprintf ("RX[%s]=%.2fMbps;%i;%i TX[%s]=%.2fMbps;%i;%i TOTAL[%s]=%.2fMbps;%i;%i ", $k, &toM($stat->netstats->{$k}{rxbyt}), $warn{rxbyt}, $crit{rxbyt}, $k, &toM($stat->netstats->{$k}{txbyt}), $warn{txbyt}, $crit{txbyt}, $k, &toM($stat->netstats->{$k}{ttbyt}), $warn{ttbyt}, $crit{ttbyt});
}

print $exit,": ", $out, "| ", $perf, "\n";
exit $ERRORS{$exit}

Nagiosgrapher Config

define ngraph{
    service_name        bonding_traf
    graph_perf_regex    RX.bond0.=(\d*.\d*)Mbps
    graph_value     bond0in
    graph_units     Mbps
    graph_legend        "bond0 in   "
    rrd_plottype        LINE3       
    rrd_color       7fff00
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0in
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0in
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0in
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0in
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}

define ngraph{
    service_name        bonding_traf
    graph_perf_regex    TX.bond0.=(\d*.\d*)Mbps
    graph_value     bond0out
    graph_units     Mbps
    graph_legend        "bond0 out  "
    rrd_plottype        LINE3       
    rrd_color       ff34a3
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0out
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0out
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0out
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0out
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}
define ngraph{
    service_name        bonding_traf
    graph_perf_regex    TOTAL.bond0.=(\d*.\d*)Mbps
    graph_value     bond0tot
    graph_units     Mbps
    graph_legend        "bond0 total"
    rrd_plottype        LINE3       
    rrd_color       ffc520
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0tot
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0tot
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0tot
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            bond0tot
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}

define ngraph{
    service_name        bonding_traf
    graph_perf_regex    RX.eth0.=(\d*.\d*)Mbps
    graph_value     eth0in
    graph_units     Mbps
    graph_legend        "eth0  in   "
    rrd_plottype        LINE2       
    rrd_color       006400
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0in
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0in
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0in
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0in
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}

define ngraph{
    service_name        bonding_traf
    graph_perf_regex    TX.eth0.=(\d*.\d*)Mbps
    graph_value     eth0out
    graph_units     Mbps
    graph_legend        "eth0  out  "
    rrd_plottype        LINE2       
    rrd_color    8b0000
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0out
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0out
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0out
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0out
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}
define ngraph{
    service_name        bonding_traf
    graph_perf_regex    TOTAL.eth0.=(\d*.\d*)Mbps
    graph_value     eth0tot
    graph_units     Mbps
    graph_legend        "eth0  total"
    rrd_plottype        LINE2       
    rrd_color       ff9c00
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0tot
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0tot
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0tot
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth0tot
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}
define ngraph{
    service_name        bonding_traf
    graph_perf_regex    RX.eth1.=(\d*.\d*)Mbps
    graph_value     eth1in
    graph_units     Mbps
    graph_legend        "eth1  in   "
    rrd_plottype        LINE2       
    rrd_color       00ff00
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1in
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1in
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1in
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1in
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}

define ngraph{
    service_name        bonding_traf
    graph_perf_regex    TX.eth1.=(\d*.\d*)Mbps
    graph_value     eth1out
    graph_units     Mbps
    graph_legend        "eth1  out  "
    rrd_plottype        LINE2       
    rrd_color       ff0000
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1out
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1out
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1out
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1out
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}
define ngraph{
    service_name        bonding_traf
    graph_perf_regex    TOTAL.eth1.=(\d*.\d*)Mbps
    graph_value     eth1tot
    graph_units     Mbps
    graph_legend        "eth1  total"
    rrd_plottype        LINE2       
    rrd_color       ffff00
}
define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1tot
        print_description       Latest:
        print_function          LAST
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1tot
        print_description       Maximum:
        print_function          MAX
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1tot
        print_description       Minimum:
        print_function          MIN
        print_format            %4.2lf Mbps
}

define ngraph{
        service_name            bonding_traf
        type                    GPRINT
        print_source            eth1tot
        print_description       Average:
        print_function          AVERAGE
        print_format            %4.2lf Mbps
        print_eol               left
}
#.EOF.