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

zenus_: Add some debugging

Add a bit of debugging code. Move to positive/negative graphing
This commit is contained in:
Paul Saunders 2012-01-12 12:46:25 +00:00
parent 10b89a6d67
commit 6f0e6960a8

View file

@ -1,235 +1,243 @@
#!/usr/bin/perl #!/usr/bin/perl
# -*- cperl -*- # -*- cperl -*-
=head1 NAME =head1 NAME
zenus_ - Munin plugin to monitor the usage of a Zen Internet Broadband account zenus_ - Munin plugin to monitor the usage of a Zen Internet Broadband account
=head1 APPLICABLE SYSTEMS =head1 APPLICABLE SYSTEMS
Any (Though most likely those connected to a Zen Internet Broadband connection) Any (Though most likely those connected to a Zen Internet Broadband connection)
=head1 CONFIGURATION =head1 CONFIGURATION
This plugin requires the C<zenus> module to be installed. This can be fetched This plugin requires the C<zenus> module to be installed. This can be fetched
from L<http://www.rachaelandtom.info/zenus>. from L<http://www.rachaelandtom.info/zenus>.
Tip: To see if it's already setup correctly, just run this plugin Tip: To see if it's already setup correctly, just run this plugin
with the parameter 'autoconf'. If you get a "yes", everything should with the parameter 'autoconf'. If you get a "yes", everything should
work like a charm already. work like a charm already.
This configuration section shows the defaults of the plugin: This configuration section shows the defaults of the plugin:
[zenus_*] [zenus_*]
env.user env.user
env.pass env.pass
env.account env.account
env.tick 60 env.tick 60
You must supply C<env.user> and C<env.pass>. These will be your PORTAL username and password, NOT your ADSL account details. You must supply C<env.user> and C<env.pass>. These will be your PORTAL username and password, NOT your ADSL account details.
You may either specify the account to report through C<env.account> (e.g. zen12345@zen) or by naming the symlink in your plugins directory (e.g. zenus_zen12345_zen). If no account is specified, the default account will be chosen. You may either specify the account to report through C<env.account> (e.g. zen12345@zen) or by naming the symlink in your plugins directory (e.g. zenus_zen12345_zen). If no account is specified, the default account will be chosen.
C<env.tick> specifies how often (in minutes) the data will be refreshed from upstream. This is to avoid hitting the Zen servers every five minutes. Data is cached between runs. C<env.tick> specifies how often (in minutes) the data will be refreshed from upstream. This is to avoid hitting the Zen servers every five minutes. Data is cached between runs.
=head1 INTERPRETATION =head1 INTERPRETATION
The plugin shows the amount of data downloaded and uploaded since the beginning of the chargable period (i.e. the calendar month). A thick line shows the current download allowance (planned plus banked). A thinner line shows the estimated amount remaining at the end of the month. If you are estimated to exceed your allowance before the end of the month, a second line appears showing the rate at which you're downloading beyond the sustainable rate. The plugin shows the amount of data downloaded and uploaded since the beginning of the chargable period (i.e. the calendar month). A thick line shows the current download allowance (planned plus banked). A thinner line shows the estimated amount remaining at the end of the month. If you are estimated to exceed your allowance before the end of the month, a second line appears showing the rate at which you're downloading beyond the sustainable rate.
Warnings are sent if your estimated allowance drops below 25% of your cap and if the overspeed rate rises above zero. Critical warnings are sent if your estimated allowance drops below 10% of your cap. Warnings are sent if your estimated allowance drops below 25% of your cap and if the overspeed rate rises above zero. Critical warnings are sent if your estimated allowance drops below 10% of your cap.
=head1 MAGIC MARKERS =head1 MAGIC MARKERS
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf suggest #%# capabilities=autoconf suggest
=head1 AUTHOR =head1 AUTHOR
Paul Saunders L<darac@darac.org.uk> Paul Saunders L<darac@darac.org.uk>
=cut =cut
use strict; use strict;
use warnings; use warnings;
use lib $ENV{'MUNIN_LIBDIR'}; use lib $ENV{'MUNIN_LIBDIR'};
use Munin::Plugin; use Munin::Plugin;
use Data::Dump qw(pp); use Data::Dump qw(pp);
use Time::Local;
my $ret = undef;
my $ret = undef;
# Load modules like so
if ( !eval "require zenus;" ) { # Load modules like so
$ret = if ( !eval "require zenus;" ) {
"Could not load zenus. Get it from http://www.rachaelandtom.info/zenus"; $ret =
} "Could not load zenus. Get it from http://www.rachaelandtom.info/zenus\n";
$ret .= "(BTW, \@INC is: " . join( ', ', @INC ) . ")\n";
my $USER = $ENV{user}; }
my $PASS = $ENV{pass};
my $ACCT = $ENV{account} || ""; my $USER = $ENV{user};
my $TICK = $ENV{tick} || 60; # minutes my $PASS = $ENV{pass};
my $ACCT = $ENV{account} || "";
my @name_fields = split /_/, $0; my $TICK = $ENV{tick} || 60; # minutes
if ( scalar @name_fields == 3 ) {
if ( $name_fields[1] eq '' or $name_fields[2] eq '' ) { my @name_fields = split /_/, $0;
print "Misconfigured symlink. See Documentation\n"; if ( scalar @name_fields == 3 ) {
exit 1; if ( $name_fields[1] eq '' or $name_fields[2] eq '' ) {
} print "Misconfigured symlink. See Documentation\n";
else { exit 1;
$ACCT = $name_fields[1] . '@' . $name_fields[2]; }
} else {
} $ACCT = $name_fields[1] . '@' . $name_fields[2];
}
# If there are more or less than 3 components to the filename, }
# we just carry on with the default account
# If there are more or less than 3 components to the filename,
my $lastread; # we just carry on with the default account
sub save_data { my $lastread;
my $hashref = shift;
sub save_data {
# Do we need to save this info my $hashref = shift;
if ( time > $lastread + ( $TICK * 60 ) ) {
# Do we need to save this info
$lastread = time; if ( time > $lastread + ( $TICK * 60 ) ) {
my @save_vector; $lastread = time;
push @save_vector, $lastread;
my @save_vector;
# Push the hash values on to the array push @save_vector, $lastread;
foreach ( keys %$hashref ) {
push @save_vector, $_ . '¬' . $hashref->{$_}; # Push the hash values on to the array
} foreach ( keys %$hashref ) {
push @save_vector, $_ . '¬' . $hashref->{$_};
#Go! }
save_state(@save_vector);
} #Go!
} save_state(@save_vector);
}
sub load_data { }
# Bring the data back in sub load_data {
my @save_vector = restore_state();
# Bring the data back in
# Read the timestamp. Do we need to refresh the data? my @save_vector = restore_state();
$lastread = shift @save_vector;
# Read the timestamp. Do we need to refresh the data?
my $hashref; $lastread = shift @save_vector;
foreach (@save_vector) {
my ( $key, $value ) = split /¬/; my $hashref;
$hashref->{$key} = $value; foreach (@save_vector) {
} my ( $key, $value ) = split /¬/;
if ( !defined $lastread or time >= ( $lastread + ( $TICK * 60 ) ) ) { $hashref->{$key} = $value;
}
# Data is stale if ( !defined $lastread or time >= ( $lastread + ( $TICK * 60 ) ) ) {
#print STDERR "REFRESHING DATA\n"; # Data is stale
my $temphash;
eval { #print STDERR "REFRESHING DATA\n";
zenus::login( $USER, $PASS ); my $temphash;
eval {
( zenus::login( $USER, $PASS );
$temphash->{name}, $temphash->{used},
$temphash->{avail}, $temphash->{per}, (
$temphash->{uploadAmount} $temphash->{name}, $temphash->{used},
) = zenus::getUsage($ACCT); $temphash->{avail}, $temphash->{per},
( $temphash->{uploadAmount}
$temphash->{dayofmonth}, $temphash->{permonth}, ) = zenus::getUsage($ACCT);
$temphash->{avedaily}, $temphash->{maxdaily}, (
$temphash->{daysremain}, $temphash->{estusage}, $temphash->{dayofmonth}, $temphash->{permonth},
$temphash->{daysinmonth} $temphash->{avedaily}, $temphash->{maxdaily},
) $temphash->{daysremain}, $temphash->{estusage},
= zenus::estimateRemaining( $temphash->{used}, $temphash->{daysinmonth}
$temphash->{avail} ); )
$hashref = $temphash; = zenus::estimateRemaining( $temphash->{used},
$temphash->{avail} );
# If zenus threw an error we won't copy the data over, $hashref = $temphash;
# so we still use the cached data.
}; # If zenus threw an error we won't copy the data over,
} # so we still use the cached data.
return $hashref; };
}
} return $hashref;
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) { }
if ($ret) {
print "no ($ret)\n"; if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) {
exit 1; if ($ret) {
} print "no ($ret)\n";
print "yes\n"; exit 1;
exit 0; }
} print "yes\n";
exit 0;
if ( defined $ARGV[0] and $ARGV[0] eq "suggest" ) { }
if ( defined $USER and defined $PASS ) {
zenus::login( $USER, $PASS ); if ( defined $ARGV[0] and $ARGV[0] eq "suggest" ) {
for my $account ( zenus::getAccounts() ) { if ( defined $USER and defined $PASS ) {
if ( defined $account ) { zenus::login( $USER, $PASS );
$account =~ s/\@/_/g; for my $account ( zenus::getAccounts() ) {
print "$account\n"; if ( defined $account ) {
} $account =~ s/\@/_/g;
} print "$account\n";
} }
exit 0; }
} }
exit 0;
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) { }
if ($ret) {
print $ret; if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
exit 1; if ($ret) {
} print $ret;
my $data = load_data(); exit 1;
my $cap = sprintf( "%.3f", $data->{avail} ); }
my $warn = sprintf( "%.3f", $cap * 0.25 ); my $data = load_data();
my $crit = sprintf( "%.3f", $cap * 0.1 ); my $cap = sprintf( "%.3f", $data->{avail} );
print <<EOF; my $warn = sprintf( "%.3f", $cap * 0.25 );
graph_args --base 1000 my $crit = sprintf( "%.3f", $cap * 0.1 );
graph_vlabel GBytes my $datestr = scalar( localtime($lastread) );
graph_category Network print <<EOF;
graph_title Zen Broadband Usage graph_args --base 1000
graph_info Usage of your Zen Broadband account: $data->{name} graph_vlabel GBytes out (-) / in (+)
download.label Downloaded graph_category Network
download.type GAUGE graph_title Zen Broadband Usage
download.info Amount of data downloaded (Limit is $cap GB) graph_info Usage of your Zen Broadband account: $data->{name}
download.draw AREA upload.label Uploaded
upload.label Uploaded upload.type GAUGE
upload.type GAUGE upload.info Amount of data uploaded (No upper limit)
upload.info Amount of data uploaded (No upper limit) upload.draw AREA
upload.draw AREA upload.graph no
allowance.label Allowance upload.colour 00CC00EE
allowance.type GAUGE download.label Transfer
allowance.info Amount of data you are allowed to download this month download.type GAUGE
allowance.draw LINE2 download.info Amount of data downloaded (Limit is $cap GB)
remaining.label Est'd Remaining download.draw AREA
remaining.type GAUGE download.extinfo Last Read was $datestr
remaining.info Estimated amount of data transfer remaining at the end of the month download.negative upload
remaining.draw LINE1 download.colour 00CC00EE
remaining.min 0 allowance.label Allowance
remaining.max $cap allowance.type GAUGE
remaining.warning $warn: allowance.info Amount of data you are allowed to download this month
remaining.critical $crit: allowance.draw LINE2
overrate.label Overspeed Rate remaining.label Est'd Remaining
overrate.type GAUGE remaining.type GAUGE
overrate.info Rate at which you're downloading beyond the sustainable rate remaining.info Estimated amount of data transfer remaining at the end of the month
overrate.draw LINE1 remaining.draw LINE1
overrate.min 0 remaining.min 0
overrate.warning 0: remaining.max $cap
graph_order download upload allowance remaining overrate remaining.warning $warn:
EOF remaining.critical $crit:
overrate.label Overspeed Rate
save_data($data); overrate.type GAUGE
exit 0; overrate.info Rate at which you're downloading beyond the sustainable rate
} overrate.draw LINE1
overrate.min 0
my $data = load_data(); overrate.warning 0:
print "upload.value " . $data->{uploadAmount} . "\n"; #graph_order download upload allowance remaining overrate
print "download.value " . $data->{used} . "\n"; EOF
print "allowance.value " . $data->{avail} . "\n";
my $remain = $data->{avail} - $data->{estusage}; save_data($data);
$remain = 0 if $remain < 0; exit 0;
print "remaining.value " . $remain . "\n"; }
my $overrate = $data->{avedaily} - $data->{maxdaily};
$overrate = 0 if $overrate < 0; my $data = load_data();
print "overrate.value " . $overrate . "\n"; print "upload.value " . $data->{uploadAmount} . "\n";
save_data($data); print "download.value " . $data->{used} . "\n";
exit 0; print "allowance.value " . $data->{avail} . "\n";
my $remain = $data->{avail} - $data->{estusage};
$remain = 0 if $remain < 0;
print "remaining.value " . $remain . "\n";
my $overrate = $data->{avedaily} - $data->{maxdaily};
$overrate = 0 if $overrate < 0;
print "overrate.value " . $overrate . "\n";
save_data($data);
exit 0;