1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 18:07:20 +00:00

Category Tree: reduce number of categories

This commit is contained in:
dipohl 2017-02-22 02:54:01 +01:00
parent abd4092268
commit 29bdf34eae
29 changed files with 44 additions and 44 deletions

View file

@ -1,455 +0,0 @@
#!/usr/bin/perl
# -*- perl -*-
=head1 NAME
2wire - Plugin to monitor 2Wire/Pace residential gateway
=head1 CONFIGURATION
[2wire]
env.gatewayaddr http://192.168.1.254
env.drawline true
env.monthline 250000000000
env.weekline 62500000000
env.dayline 8333333333
=head1 LICENSE
GPLv2
=head1 AUTHOR
Daniel Lee <Longinus00@gmail.com>
=head1 MAGICK MARKERS
#%# family=network
#%# capabilities=autoconf
=cut
use strict;
use warnings;
use POSIX;
use WWW::Mechanize;
use WWW::Mechanize::TreeBuilder;
use Munin::Plugin;
my $gatewayAddr = $ENV{'gatewayaddr'} || 'http://192.168.1.254';
my $drawLine = $ENV{'drawline'} || 'false';
my $monthLine = $ENV{'monthline'} || 250000000000;
my $weekLine = $ENV{'weekline'} || 62500000000;
my $dayLine = $ENV{'dayline'} || 8333333333;
my $mech = WWW::Mechanize->new;
WWW::Mechanize::TreeBuilder->meta->apply($mech);
sub autoconf {
my $url = $gatewayAddr."/xslt?PAGE=C_0_0";
$mech->get( $url );
if($mech->success()) {
print "yes\n";
}
else {
print "no\n";
}
exit 0;
}
sub config {
print << "EOF";
multigraph 2wire_session_count
graph_title 2wire NAT session count
graph_args --base 1000 -l 0
#graph_vlabel number of sessions in (-) / out (+)
graph_vlabel number of sessions
graph_scale no
graph_category 2wire
graph_total Total
graph_printf %.0lf
inboundSessions.label Inbound
inboundSessions.draw AREASTACK
#inboundSessions.graph no
outboundSessions.label Outbound
outboundSessions.draw AREASTACK
#outboundSessions.negative inboundSessions
#inboundSessions.line 512:ff0000:Inbound session limit
outboundSessions.line 1024:ff0000:Session table limit
multigraph 2wire_session_type
graph_title 2wire NAT session type
graph_args --base 1000 -l 0
graph_vlabel number of sessions
graph_scale no
graph_category 2wire
graph_total Total
graph_printf %.0lf
tcpSessions.label TCP
tcpSessions.draw AREASTACK
udpSessions.label UDP
udpSessions.draw AREASTACK
udpSessions.line 1024:ff0000:Session table limit
multigraph 2wire_session_uptime
graph_title 2wire session uptime
graph_args --base 1000 -l 0
graph_vlabel Uptime in days
graph_scale no
graph_category 2wire
sessionUptime.label Uptime
sessionUptime.draw AREA
sessionUptime.cdef sessionUptime,86400,/
###
multigraph 2wire_dsl_power
graph_title 2wire DSL output power
graph_args --base 1000
graph_vlabel dBmV
graph_scale no
graph_category 2wire
powerDown.label Down
#powerDown.graph no
powerUp.label Up
#powerUp.negative powerDown
multigraph 2wire_dsl_details
graph_title 2wire DSL details
graph_args --base 1000
graph_vlabel dB
graph_scale no
graph_category 2wire
noiseM.label Noise margin
attenuation.label Attenuation
attenuation300.label Attenuation @ 300kHz
gain.label Final Receive Gain
multigraph 2wire_dsl_seconds
graph_title 2wire Errors Time
graph_args --base 1000
graph_vlabel s
graph_scale no
graph_category 2wire
cumSecErrors.label Cumulative Seconds w/Errors
cumSecSevErrors.label Cumulative Seconds w/Severe Errors
unavailable.label DSL Unavailable Seconds
multigraph 2wire_dsl_blocks
graph_title 2wire Block Correction
graph_args --base 1000
graph_vlabel blocks/s
graph_scale no
graph_category 2wire
correctedBlocks.label Corrected Blocks
correctedBlocks.type DERIVE
correctedBlocks.min 0
uncorrectableBlocks.label Uncorrectable Blocks
uncorrectableBlocks.type DERIVE
uncorrectableBlocks.min 0
multigraph 2wire_dsl_traffic
graph_title 2wire DSL traffic
graph_args --base 1024 -l 0
graph_vlabel Bytes in (-) / out (+) per second
graph_category 2wire
receive.label Bps
receive.type DERIVE
receive.min 0
receive.graph no
transmit.label Bps
transmit.type DERIVE
transmit.min 0
transmit.negative receive
####
multigraph 2wire_dsl_bandwidth_monthly
graph_title 2wire DSL bandwidth usage (monthly)
graph_args --base 1024 -l 0 -M
graph_vlabel Bytes
graph_category 2wire
down.label Down
up.label Up
total.label Total
EOF
if($drawLine eq 'true') {
print "total.line ".$monthLine.":ff0000\n"
}
print << "EOF";
multigraph 2wire_dsl_bandwidth_weekly
graph_title 2wire DSL bandwidth usage (weekly)
graph_args --base 1024 -l 0 -M
graph_vlabel Bytes
graph_category 2wire
down.label Down
up.label Up
total.label Total
EOF
if($drawLine eq 'true') {
print "total.line ".$weekLine.":ff0000\n"
}
print << "EOF";
multigraph 2wire_dsl_bandwidth_daily
graph_title 2wire DSL bandwidth usage (daily)
graph_args --base 1024 -l 0 -M
graph_vlabel Bytes
graph_category 2wire
down.label Down
up.label Up
total.label Total
EOF
if($drawLine eq 'true') {
print "total.line ".$dayLine.":ff0000\n"
}
exit 0;
}
sub bandwidth_acc {
my $date = shift;
my $bandwidth = shift;
my $str = shift;
my $up = shift;
my $down = shift;
unless(exists $bandwidth->{$str}) {
$bandwidth->{$str} = $date;
$bandwidth->{$str.'_u_c'} = 0;
$bandwidth->{$str.'_d_c'} = 0;
$bandwidth->{$str.'_u_t'} = $up;
$bandwidth->{$str.'_d_t'} = $down;
}
if($date != $bandwidth->{$str}) {
$bandwidth->{$str} = $date;
if($bandwidth->{$str.'_u_t'} <= $up || $bandwidth->{$str.'_d_t'} <= $down) {
$bandwidth->{$str.'_u_c'} = $up - $bandwidth->{$str.'_u_t'};
$bandwidth->{$str.'_d_c'} = $down - $bandwidth->{$str.'_d_t'};
}
else {
$bandwidth->{$str.'_u_c'} = 0;
$bandwidth->{$str.'_d_c'} = 0;
}
}
elsif($bandwidth->{$str.'_u_t'} > $up || $bandwidth->{$str.'_d_t'} > $down) {
$bandwidth->{$str.'_u_c'} += $up;
$bandwidth->{$str.'_d_c'} += $down;
}
else {
$bandwidth->{$str.'_u_c'} += $up - $bandwidth->{$str.'_u_t'};
$bandwidth->{$str.'_d_c'} += $down - $bandwidth->{$str.'_d_t'};
}
$bandwidth->{$str.'_u_t'} = $up;
$bandwidth->{$str.'_d_t'} = $down;
}
sub process_bandwidth {
my $values = shift;
my ($up,$down) = ($values->{'transmit'}, $values->{'receive'});
my ($day, $week, $month) = map(int, split(/ /, POSIX::strftime("%j %U %m", localtime)));
$month = int(($week-1) / 4);
my %bandwidth = restore_state();
my %bandwidth = ();
bandwidth_acc($month,\%bandwidth,'month',$up,$down);
bandwidth_acc($week,\%bandwidth,'week',$up,$down);
bandwidth_acc($day,\%bandwidth,'day',$up,$down);
save_state(%bandwidth);
print "multigraph 2wire_dsl_bandwidth_monthly\n";
print "up.value ", $bandwidth{'month_u_c'},"\n";
print "down.value ", $bandwidth{'month_d_c'},"\n";
print "total.value ", $bandwidth{'month_u_c'}+$bandwidth{'month_d_c'},"\n";
print "\n";
print "multigraph 2wire_dsl_bandwidth_weekly\n";
print "up.value ", $bandwidth{'week_u_c'},"\n";
print "down.value ", $bandwidth{'week_d_c'},"\n";
print "total.value ", $bandwidth{'week_u_c'}+$bandwidth{'week_d_c'},"\n";
print "\n";
print "multigraph 2wire_dsl_bandwidth_daily\n";
print "up.value ", $bandwidth{'day_u_c'},"\n";
print "down.value ", $bandwidth{'day_d_c'},"\n";
print "total.value ", $bandwidth{'day_u_c'}+$bandwidth{'day_d_c'},"\n";
print "\n";
}
sub process_values {
my $values = shift;
print << "EOF";
multigraph 2wire_dsl_power
powerDown.value $values->{'power-down'}
powerUp.value $values->{'power-up'}
multigraph 2wire_dsl_details
noiseM.value $values->{'noise-margin'}
attenuation.value $values->{'attenuation'}
attenuation300.value $values->{'attenuation300'}
gain.value $values->{'gain'}
multigraph 2wire_dsl_seconds
cumSecErrors.value $values->{'cum-sec-errors'}
cumSecSevErrors.value $values->{'cum-sec-sev-errors'}
unavailable.value $values->{'sec-unavailable'}
multigraph 2wire_dsl_blocks
correctedBlocks.value $values->{'corrected-blocks'}
uncorrectableBlocks.value $values->{'uncorrectable-blocks'}
multigraph 2wire_dsl_traffic
transmit.value $values->{'transmit'}
receive.value $values->{'receive'}
EOF
}
sub broadband_page {
my $url = $gatewayAddr."/xslt?PAGE=C_1_0";
$mech->get( $url );
die unless $mech->success();
my (%values, $m);
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Noise Margin'});
$m->right()->as_text =~ /(\S+) dB/;
$values{'noise-margin'} = $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Attenuation'});
$m->right()->as_text =~ /(\S+) dB/;
$values{'attenuation'} = $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Output Power'});
$m->right()->as_text =~ /(\S+) dB/;
$values{'power-down'} = $1;
$m = $m->right();
$m->right()->as_text =~ /(\S+) dB/;
$values{'power-up'} = $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Attenuation @ 300kHz'});
$m->right()->as_text =~ /(\S+) dB/;
$values{'attenuation300'} = $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Final Receive Gain'});
$m->right()->as_text =~ /(\S+) dB/;
$values{'gain'} = $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Transmit'});
$m->right()->as_text =~ /(\d+)/;
$values{'transmit'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Receive'});
$m->right()->as_text =~ /(\d+)/;
$values{'receive'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Receive'});
$m->right()->as_text =~ /(\d+)/;
$values{'receive'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Link Retrains'});
$m->right()->as_text =~ /(\d+)/;
$values{'link-retrains'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'DSL Training Errors'});
$m->right()->as_text =~ /(\d+)/;
$values{'dsl-training-errors'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Training Timeouts'});
$m->right()->as_text =~ /(\d+)/;
$values{'training-timeouts'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Cum. Seconds w/Errors'});
$m->right()->as_text =~ /(\d+)/;
$values{'cum-sec-errors'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Cum. Sec. w/Severe Errors'});
$m->right()->as_text =~ /(\d+)/;
$values{'cum-sec-sev-errors'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Corrected Blocks'});
$m->right()->as_text =~ /(\d+)/;
$values{'corrected-blocks'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'Uncorrectable Blocks'});
$m->right()->as_text =~ /(\d+)/;
$values{'uncorrectable-blocks'} = int $1;
$m = $mech->look_down(_tag => 'td', sub { $_[0]->as_text eq 'DSL Unavailable Seconds'});
$m->right()->as_text =~ /(\d+)/;
$values{'sec-unavailable'} = int $1;
process_values(\%values);
process_bandwidth(\%values);
}
sub nat_page {
my $url = $gatewayAddr."/xslt?PAGE=C_5_5";
$mech->get( $url );
die unless $mech->success();
my (%sessions, $uptime);
my ($m, $raw, @stext);
$m = $mech->look_down(_tag => 'h2', sub { $_[0]->as_text eq 'Current NAT Sessions'});
$raw = $m->right()->as_text;
$raw =~ s/^\n//;
@stext = split("\n", $raw);
$stext[0] =~ /boot: (\d+)/;
$uptime = int $1;
$stext[1] =~ /session table (\d+)\/(\d+) available, (\d+)\/\d+ used/;
($sessions{'used'}, $sessions{'inbound'}) = ($2 - $1, $3);
$sessions{'outbound'} = $sessions{'used'} - $sessions{'inbound'};
my $i = 0;
foreach (@stext) {
$i += 1 if /proto: 6/;
}
($sessions{'tcp'}, $sessions{'udp'}) = ($i, $sessions{'used'} - $i);
print << "EOF";
multigraph 2wire_session_count
inboundSessions.value $sessions{'inbound'}
outboundSessions.value $sessions{'outbound'}
multigraph 2wire_session_type
tcpSessions.value $sessions{'tcp'}
udpSessions.value $sessions{'udp'}
multigraph 2wire_session_uptime
sessionUptime.value $uptime
EOF
}
if($ARGV[0] and $ARGV[0] eq "autoconf") {
autoconf
}
elsif($ARGV[0] and $ARGV[0] eq "config") {
config
}
else {
broadband_page;
nat_page;
}

View file

@ -1,203 +0,0 @@
#!/bin/bash
# -*- sh -*-
: <<=cut
=head1 NAME
accounting_ - Wildcard-plugin for tcp, udp and icmp traffic-accounting (IPv4 or IPv6) through iptables.
=head1 CONFIGURATION
This plugin needs to be run as root for iptables to work.
[accounting_*]
user root
=head2 ENVIRONMENT VARIABLES
This plugin does not use environment variables.
=head2 WILDCARD PLUGIN
This is a wildcard plugin. To monitor traffic going through your iptables,link
accounting_<ipv4|ipv6>_<accountingname> to this file.
For example,
ln -s /opt/munin/lib/plugins/accounting_ /etc/opt/munin/plugins/accounting_ipv4_subnet1
will monitor the tcp, udp and icmp traffic for the accounting named subnet1.
=head2 IPTABLES
You will need to set up iptables rules to create packet counters for
incoming and outgoing traffic. The examples here cover how to create
the rules. Add these lines at the top of your firewall-script.
=head3 Accounting for single ip
If you want to monitor the traffic from the IP 192.168.0.1, you need to add the following
lines (replace iptables with ip6tables if needed):
iptables -I INPUT -d 192.168.0.1 -p icmp -m comment --comment ACCT-accountingname-icmp-in
iptables -I INPUT -d 192.168.0.1 -p udp -m comment --comment ACCT-accountingname-udp-in
iptables -I INPUT -d 192.168.0.1 -p tcp -m comment --comment ACCT-accountingname-tcp-in
iptables -I OUTPUT -s 192.168.0.1 -p icmp -m comment --comment ACCT-accountingname-icmp-out
iptables -I OUTPUT -s 192.168.0.1 -p udp -m comment --comment ACCT-accountingname-udp-out
iptables -I OUTPUT -s 192.168.0.1 -p tcp -m comment --comment ACCT-accountingname-tcp-out
Only the IP itself (192.168.0.1) and the accounting-name (accountingname) need to be replaced by your values.
iptables -I <INPUT|OUTPUT> -d <yourip> -p <tcp|udp|icmp> -m comment --comment ACCT-<yourname>-<tcp|udp|icmp>-in
Then add the plugin to your munin configuration:
ln -s /opt/munin/lib/plugins/accounting_ /etc/opt/munin/plugins/accounting_ipv4_accountingname
=head3 Accounting for subnets
If you want to monitor the traffic from the subnet 192.168.0.1/24, you need to add the following
lines (replace iptables with ip6tables if needed):
iptables -I INPUT -d 192.168.0.1/24 -p icmp -m comment --comment ACCT-subnet1-icmp-in
iptables -I INPUT -d 192.168.0.1/24 -p udp -m comment --comment ACCT-subnet1-udp-in
iptables -I INPUT -d 192.168.0.1/24 -p tcp -m comment --comment ACCT-subnet1-tcp-in
iptables -I OUTPUT -s 192.168.0.1/24 -p icmp -m comment --comment ACCT-subnet1-icmp-out
iptables -I OUTPUT -s 192.168.0.1/24 -p udp -m comment --comment ACCT-subnet1-udp-out
iptables -I OUTPUT -s 192.168.0.1/24 -p tcp -m comment --comment ACCT-subnet1-tcp-out
Then add the plugin to your munin configuration:
ln -s /opt/munin/lib/plugins/accounting_ /etc/opt/munin/plugins/accounting_ipv4_subnet1
=head1 BUGS
Accounting-names should not contain underline "_" in the name. So instead of "This_Is_A_Cool_Name" use "This-Is-A-Cool-Name".
=head1 NOTES
This plugin is based on the ip_ plugin.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=head1 VERSION
1.0
=head1 HISTORY
2013-06-29: initial release
=head1 AUTHOR
Thomas Frey <thomas.frey-munin@hugga.org>
=head1 LICENSE
GPLv2
=cut
PARAM=${0##*accounting_}
SUBCHAIN=$(echo $PARAM | cut -d '_' -f 2)
PROTO=$(echo $PARAM | cut -d '_' -f 1)
if [ $PROTO = "ipv4" ]; then
IPTABLES="/sbin/iptables"
elif [ $PROTO == "ipv6" ]; then
IPTABLES="/sbin/ip6tables"
else
echo "Configuration error: invalid protocol name: not ipv4 or ipv6."
echo "Use accounting_<ipv4|ipv6>_accountingname."
exit 1
fi
if [ "$1" == "autoconf" ]; then
if [ -r /proc/net/dev ]; then
$IPTABLES -L INPUT -v -n -x >/dev/null 2>/dev/null
if [ $? -gt 0 ]; then
echo "no (could not run iptables as user `whoami`)"
exit 1
else
echo yes
exit 0
fi
else
echo "no (/proc/net/dev not found)"
exit 1
fi
fi
if [ "$1" = "suggest" ]; then
if [ $PROTO = "ipv4" ]; then
$IPTABLES -L INPUT -v -x -n 2>/dev/null | sed -n 's/^.*\/\* ACCT\-\([a-zA-Z\-]*\) \*\/.*$/\ipv4_\1/p'
$IPTABLES -L OUTPUT -v -x -n 2>/dev/null | sed -n 's/^.*\/\* ACCT\-\([a-zA-Z\-]*\) \*\/.*$/\ipv4_\1/p'
elif [ $PROTO == "ipv6" ]; then
$IPTABLES -L INPUT -v -x -n 2>/dev/null | sed -n 's/^.*\/\* ACCT\-\([a-zA-Z\-]*\) \*\/.*$/\ipv6_\1/p'
$IPTABLES -L OUTPUT -v -x -n 2>/dev/null | sed -n 's/^.*\/\* ACCT\-\([a-zA-Z\-]*\) \*\/.*$/\ipv6_\1/p'
fi
exit 0
fi
if [ "$1" = "config" ]; then
echo 'multigraph '${0##*/}'_in'
echo 'graph_title '$SUBCHAIN' traffic incoming ('$PROTO')'
echo 'graph_args --base 1024 -l 0'
echo 'graph_vlabel bytes per ${graph_period}'
echo 'graph_order tcpIN udpIN icmpIN'
echo 'graph_category accounting'
echo 'tcpIN.label tcp received'
echo 'tcpIN.cdef tcpIN,8,*'
echo 'tcpIN.type DERIVE'
echo 'tcpIN.draw AREA'
echo 'tcpIN.min 0'
echo 'udpIN.label udp received'
echo 'udpIN.cdef udpIN,8,*'
echo 'udpIN.type DERIVE'
echo 'udpIN.draw STACK'
echo 'udpIN.min 0'
echo 'icmpIN.label icmp received'
echo 'icmpIN.cdef icmpIN,8,*'
echo 'icmpIN.type DERIVE'
echo 'icmpIN.draw STACK'
echo 'icmpIN.min 0'
echo 'multigraph '${0##*/}'_out'
echo 'graph_title '$SUBCHAIN' traffic outgoing ('$PROTO')'
echo 'graph_args --base 1024 -l 0'
echo 'graph_vlabel bytes per ${graph_period}'
echo 'graph_order tcpOUT udpOUT icmpOUT'
echo 'graph_category accounting'
echo 'tcpOUT.label tcp sent'
echo 'tcpOUT.cdef tcpOUT,8,*'
echo 'tcpOUT.type DERIVE'
echo 'tcpOUT.draw AREA'
echo 'tcpOUT.min 0'
echo 'udpOUT.label udp sent'
echo 'udpOUT.cdef udpOUT,8,*'
echo 'udpOUT.type DERIVE'
echo 'udpOUT.draw STACK'
echo 'udpOUT.min 0'
echo 'icmpOUT.label icmp sent'
echo 'icmpOUT.cdef icmpOUT,8,*'
echo 'icmpOUT.type DERIVE'
echo 'icmpOUT.draw STACK'
echo 'icmpOUT.min 0'
exit 0
fi;
echo 'multigraph '${0##*/}'_in'
$IPTABLES -L INPUT -v -n -x | grep "\/\* ACCT\-"$SUBCHAIN"\-tcp\-in \*\/" | tr -s '*' '-' | awk "{ print \"tcpIN.value \" \$2 }"
$IPTABLES -L INPUT -v -n -x | grep "\/\* ACCT\-"$SUBCHAIN"\-udp\-in \*\/" | tr -s '*' '-' | awk "{ print \"udpIN.value \" \$2 }"
$IPTABLES -L INPUT -v -n -x | grep "\/\* ACCT\-"$SUBCHAIN"\-icmp\-in \*\/" | tr -s '*' '-' | awk "{ print \"icmpIN.value \" \$2 }"
echo
echo 'multigraph '${0##*/}'_out'
$IPTABLES -L OUTPUT -v -n -x | grep "\/\* ACCT\-"$SUBCHAIN"\-tcp\-out \*\/" | tr -s '*' '-' | awk "{ print \"tcpOUT.value \" \$2 }"
$IPTABLES -L OUTPUT -v -n -x | grep "\/\* ACCT\-"$SUBCHAIN"\-udp\-out \*\/" | tr -s '*' '-' | awk "{ print \"udpOUT.value \" \$2 }"
$IPTABLES -L OUTPUT -v -n -x | grep "\/\* ACCT\-"$SUBCHAIN"\-icmp\-out \*\/" | tr -s '*' '-' | awk "{ print \"icmpOUT.value \" \$2 }"