mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 18:38:30 +00:00
make the graphs more like the if_ plugin
Show traffic in bits instead of bytes, use negative values for incoming traffic, improve wording, simplify authentication, add documentation.
This commit is contained in:
parent
0ff56fc90e
commit
8ea0ef8248
1 changed files with 90 additions and 91 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
#
|
#
|
||||||
# tor_bandwidth_acct - munin plugin to monitor Tor routers traffic
|
# tor-bandwidth-usage - munin plugin to monitor Tor traffic
|
||||||
#
|
#
|
||||||
# To use this plugin you need the following:
|
# To use this plugin you need the following:
|
||||||
# o Enable accounting on torrc configuration file (even if you dont want to limit bandwidth usage,
|
# o Enable accounting on torrc configuration file (even if you dont want to limit bandwidth usage,
|
||||||
|
@ -9,145 +9,144 @@
|
||||||
# AccountingStart day 12:00
|
# AccountingStart day 12:00
|
||||||
# AccountingMax 100 GB
|
# AccountingMax 100 GB
|
||||||
# o Enable CookieAuthentication (CookieAuthentication 1 in torrc) or define a HashedControlPassword
|
# o Enable CookieAuthentication (CookieAuthentication 1 in torrc) or define a HashedControlPassword
|
||||||
|
# o Add something like the following to /etc/munin/plugin-conf.d/munin-node:
|
||||||
|
# [tor-bandwidth-usage]
|
||||||
|
# user debian-tor
|
||||||
|
# env.cookiefile /var/run/tor/control.authcookie
|
||||||
#
|
#
|
||||||
# tested with Tor releases: 0.2.1.28, 0.2.1.29
|
|
||||||
#
|
#
|
||||||
# Author: tazoi <dev AT tazoi DOT it>, based on a plugin by Ævar Arnfjörð Bjarmason <avarab@gmail.com
|
# tested with Tor releases: 0.2.1.28, 0.2.1.29, 0.2.2.35
|
||||||
|
#
|
||||||
|
# Author: tazoi <dev AT tazoi DOT it>, based on a plugin by Ævar Arnfjörð Bjarmason <avarab@gmail.com>
|
||||||
#
|
#
|
||||||
# Parameters understood (defined in file /etc/munin/plugin-conf.d/munin-node or in environment)
|
# Parameters understood (defined in file /etc/munin/plugin-conf.d/munin-node or in environment)
|
||||||
# host - Change which host to graph (default localhost)
|
# host - Change which host to graph (default localhost)
|
||||||
# port - Change which port to connect to (default 9051)
|
# port - Change which port to connect to (default 9051)
|
||||||
# password - Plain-text control channel password (see torrc
|
# password - Plain-text control channel password (see torrc
|
||||||
# HashedControlPassword parameter)
|
# HashedControlPassword parameter)
|
||||||
# cookiefile - Name of the file containing the control channel cookie
|
# cookiefile - Name of the file containing the control channel cookie
|
||||||
# (see torrc CookieAuthentication parameter)
|
# (see torrc CookieAuthentication parameter)
|
||||||
#
|
#
|
||||||
# Using HashedControlPassword authentication has the problem that you must
|
# Using HashedControlPassword authentication has the problem that you
|
||||||
# include the plain-text password in the munin config file. To have any
|
# must include the plain-text password in the munin config file. To
|
||||||
# effect, that file shouldn't be world-readable.
|
# have any effect, that file shouldn't be world-readable.
|
||||||
# If you're using CookieAuthentication, you should run this plugin as a user
|
|
||||||
# which has read access to the tor datafiles. Also note that bugs in versions
|
|
||||||
# upto and including 0.1.1.20 prevent CookieAuthentication from working.
|
|
||||||
#
|
#
|
||||||
# Usage: place in /etc/munin/node.d/ or in /etc/munin/plugins (or link it there using ln -s)
|
# If you're using CookieAuthentication, you should run this plugin as
|
||||||
|
# a user which has read access to the tor datafiles. Also note that
|
||||||
|
# bugs in versions upto and including 0.1.1.20 prevent
|
||||||
|
# CookieAuthentication from working.
|
||||||
#
|
#
|
||||||
# Parameters understood:
|
# Usage: place in /etc/munin/plugins (or link it there using ln -s)
|
||||||
# config (required)
|
|
||||||
# autoconf (optional - used by munin-config)
|
|
||||||
#
|
|
||||||
# todo:
|
|
||||||
# try using "graph_period" option "to make graph_sums usable"
|
|
||||||
#
|
|
||||||
# Magic markers - optional - used by installation scripts and
|
|
||||||
# munin-config:
|
|
||||||
#
|
#
|
||||||
#%# family=contrib
|
#%# family=contrib
|
||||||
#%# capabilities=autoconf
|
#%# capabilities=autoconf
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use feature ':5.10';
|
||||||
use IO::Socket::INET;
|
use IO::Socket::INET;
|
||||||
|
use Munin::Plugin;
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
our $address = $ENV{host} || "localhost"; # Default: localhost
|
my $address = $ENV{host} || "localhost";
|
||||||
our $port = $ENV{port} || 9051; # Default: 9051
|
my $port = $ENV{port} || 9051;
|
||||||
|
|
||||||
# Don't edit below this line
|
# Don't edit below this line
|
||||||
|
|
||||||
sub Authenticate
|
sub Authenticate
|
||||||
{
|
{
|
||||||
my ($socket) = @_;
|
my ($socket) = @_;
|
||||||
my $authline = "AUTHENTICATE";
|
my $authline = "AUTHENTICATE";
|
||||||
if (defined($ENV{cookiefile})) {
|
if (defined($ENV{cookiefile})) {
|
||||||
if (open(COOKIE, "<$ENV{cookiefile}")) {
|
if (open(COOKIE, "<$ENV{cookiefile}")) {
|
||||||
binmode COOKIE;
|
my $cookie;
|
||||||
my $cookie;
|
binmode COOKIE;
|
||||||
$authline .= " ";
|
read(COOKIE, $cookie, 32);
|
||||||
while (read(COOKIE, $cookie, 32)) {
|
close COOKIE;
|
||||||
foreach my $byte (unpack "C*", $cookie) {
|
$authline .= ' "' . $cookie . '"';
|
||||||
$authline .= sprintf "%02x", $byte;
|
}
|
||||||
}
|
} elsif (defined($ENV{password})) {
|
||||||
}
|
$authline .= ' "' . $ENV{password} . '"';
|
||||||
close COOKIE;
|
}
|
||||||
}
|
say $socket "$authline";
|
||||||
} elsif (defined($ENV{password})) {
|
my $replyline = <$socket>;
|
||||||
$authline .= ' "' . $ENV{password} . '"';
|
if (substr($replyline, 0, 1) != '2') {
|
||||||
}
|
$replyline =~ s/\s*$//;
|
||||||
print $socket "$authline\r\n";
|
return "Failed to authenticate: $replyline";
|
||||||
my $replyline = <$socket>;
|
}
|
||||||
if (substr($replyline, 0, 1) != '2') {
|
|
||||||
$replyline =~ s/\s*$//;
|
|
||||||
return "Failed to authenticate: $replyline";
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
|
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
|
||||||
# Try to connect to the daemon
|
# Try to connect to the daemon
|
||||||
my $socket = IO::Socket::INET->new("$address:$port")
|
my $socket = IO::Socket::INET->new("$address:$port") or my $failed = 1;
|
||||||
or my $failed = 1;
|
|
||||||
|
|
||||||
if ($failed) {
|
if ($failed) {
|
||||||
print "no (failed to connect to $address port $port)\n";
|
say "no (failed to connect to $address port $port)";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $msg = Authenticate($socket);
|
my $msg = Authenticate($socket);
|
||||||
if (defined($msg)) {
|
if (defined($msg)) {
|
||||||
print $socket "QUIT\r\n";
|
say $socket "QUIT";
|
||||||
close($socket);
|
close($socket);
|
||||||
print "no ($msg)\n";
|
say "no ($msg)";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print $socket "QUIT\r\n";
|
say $socket "QUIT";
|
||||||
close($socket);
|
close($socket);
|
||||||
print "yes\n";
|
say "yes";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ARGV[0] and $ARGV[0] eq "config") {
|
if ($ARGV[0] and $ARGV[0] eq "config") {
|
||||||
print "graph_title Tor bandwidth usage (in/out)\n";
|
say "graph_order down up";
|
||||||
print "graph_args --base 1000\n";
|
say "graph_title Tor traffic";
|
||||||
print "graph_vlabel bytes/sec\n";
|
say "graph_args --base 1000";
|
||||||
print "graph_category Tor\n";
|
say "graph_vlabel bits in (-) / out (+) per \${graph_period}";
|
||||||
print "graph_info This graph shows the flowing incoming/outgoing bytes on a Tor node\n";
|
say "graph_category network";
|
||||||
print "down.label Download\n";
|
say "graph_info This graph shows the traffic through this Tor node.";
|
||||||
print "down.type DERIVE\n";
|
say "down.label received";
|
||||||
print "down.min 0\n";
|
say "down.type DERIVE";
|
||||||
print "up.label Upload\n";
|
say 'down.graph no';
|
||||||
print "up.type DERIVE\n";
|
say "down.cdef down,8,*";
|
||||||
print "up.min 0\n";
|
say "down.min 0";
|
||||||
|
say "up.label b/s";
|
||||||
|
say "up.type DERIVE";
|
||||||
|
say "up.negative down";
|
||||||
|
say "up.cdef up,8,*";
|
||||||
|
say "up.min 0";
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $socket = IO::Socket::INET->new("$address:$port")
|
my $socket = IO::Socket::INET->new("$address:$port")
|
||||||
or die("Couldn't connect to $address port $port: $!");
|
or die("Couldn't connect to $address port $port: $!");
|
||||||
|
|
||||||
my $msg = Authenticate($socket);
|
my $msg = Authenticate($socket);
|
||||||
if (defined($msg)) {
|
if (defined($msg)) {
|
||||||
print $socket "QUIT\r\n";
|
say $socket "QUIT";
|
||||||
close($socket);
|
close($socket);
|
||||||
die "$msg\n";
|
die "$msg\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print $socket "GETINFO accounting/bytes\r\n";
|
say $socket "GETINFO accounting/bytes";
|
||||||
my $down = 0;
|
my $down = 0;
|
||||||
my $up = 0;
|
my $up = 0;
|
||||||
my $replyline = <$socket>;
|
my $replyline = <$socket>;
|
||||||
chomp($replyline);
|
chomp($replyline);
|
||||||
if ( $replyline =~ /^250-accounting\/bytes=(\d+)\s(\d+)\r$/ ) {
|
if ($replyline =~ /^250-accounting\/bytes=(\d+)\s(\d+)/) {
|
||||||
$down = $1;
|
$down = $1;
|
||||||
$up = $2;
|
$up = $2;
|
||||||
} else {
|
} else {
|
||||||
die "Failed to get accounting info: $replyline\n";
|
die "Failed to get accounting info: $replyline\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print $socket "QUIT\r\n";
|
say $socket "QUIT";
|
||||||
close($socket);
|
close($socket);
|
||||||
|
|
||||||
print "down.value $down\n";
|
say "down.value $down";
|
||||||
print "up.value $up\n";
|
say "up.value $up";
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue