mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
71a872cfb6
For multiple sessions
123 lines
3.4 KiB
Perl
123 lines
3.4 KiB
Perl
#!/usr/bin/perl -w
|
|
#
|
|
# xmlrpc based munin plugin for monitoring rtorrent's peer count
|
|
# prerequisites:
|
|
# - rtorrent 0.7.5 or newer compiled with --with-xmlrpc-c
|
|
# check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further informations
|
|
#
|
|
# written by Gabor Hudiczius
|
|
# web: http://projects.cyla.homeip.net/rtwi/wiki/rTorrentOMeter
|
|
# email: ghudiczius@gmail.com
|
|
#
|
|
# 0.2.0 - 080619
|
|
# support for scgi_port and scgi_local
|
|
# configurable via munin env variables
|
|
# initial release
|
|
#
|
|
#
|
|
# Parameters:
|
|
#
|
|
# config required
|
|
#
|
|
#
|
|
# Configurable variables
|
|
#
|
|
# src "socket" when using scgi_socket, or anything else when using scgi_port
|
|
# socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is set to "socket"
|
|
# category Change graph category
|
|
#
|
|
# Configuration example
|
|
#
|
|
# [rtom_peers]
|
|
# user username
|
|
# env.src socket
|
|
# env.socket /home/usernametorrent/.socket/rpc.socket,/home/usernametorrent/.socket/rpc2.socket
|
|
# env.category Category
|
|
#
|
|
#%# family=auto
|
|
|
|
|
|
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
|
exit 1;
|
|
}
|
|
|
|
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
|
my $category = $ENV{"category"} || "";
|
|
print "graph_title rTorrent peer statistics\n";
|
|
print "graph_args --base 1000 --lower-limit 0\n";
|
|
print "graph_vlabel peers\n";
|
|
print "graph_category rTorrent ".${category}."\n";
|
|
print "outgoing.label outgoing\n";
|
|
print "outgoing.draw AREA\n";
|
|
print "outgoing.info number of outgoing connections\n";
|
|
print "incoming.label incoming\n";
|
|
print "incoming.draw STACK\n";
|
|
print "incoming.info number of incoming connections\n";
|
|
print "plain.label plain text\n";
|
|
print "plain.draw LINE2\n";
|
|
print "plain.info number of plain text connections\n";
|
|
print "encrypted.label encrypted\n";
|
|
print "encrypted.draw LINE2\n";
|
|
print "encrypted.info number of encrypted connections\n";
|
|
print "total.label total\n";
|
|
print "total.draw LINE2\n";
|
|
print "total.info total number of connections\n";
|
|
exit 0;
|
|
}
|
|
|
|
use IO::Socket;
|
|
|
|
my @sockets = split /,/, $ENV{"socket"} || "";
|
|
my $mem = 0;
|
|
my $src = $ENV{"src"} || "";
|
|
|
|
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
|
|
my $tpattern = qr/[0-9A-F]{20}/;
|
|
|
|
my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall</methodName><params><param><value><string>main</string></value></param><param><value><string>d.get_hash=</string></value></param><param><value><string>p.multicall=,p.is_encrypted=,p.is_incoming=</string></value></param></params></methodCall>";
|
|
my $llen = length $line;
|
|
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
|
my $hlen = length $header;
|
|
$line = "${hlen}:${header},${line}";
|
|
|
|
my $tor = 0;
|
|
my $tot = 0;
|
|
my $enc = 0;
|
|
my $inc = 0;
|
|
my $pline = "";
|
|
my $ppline = "";
|
|
my $out = 0;
|
|
my $pla = 0;
|
|
|
|
for $socket (@sockets)
|
|
{
|
|
if ( ( defined $src ) && ( $src eq "socket" ) ) {
|
|
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 );
|
|
connect( SOCK, sockaddr_un( $socket ) );
|
|
}
|
|
|
|
print SOCK $line;
|
|
flush SOCK;
|
|
|
|
while ( $line = <SOCK> ) {
|
|
if ( $line =~ /$tpattern/ ) {
|
|
$tor += 1;
|
|
} elsif ( $line =~ /$pattern/ ) {
|
|
$tot += 1;
|
|
$enc += $2;
|
|
$line = <SOCK>;
|
|
$line =~ /$pattern/;
|
|
$inc += $2;
|
|
}
|
|
$ppline = $pline;
|
|
$pline = $line;
|
|
}
|
|
close (SOCK);
|
|
|
|
$out = $out + $tot - $inc;
|
|
$pla = $pla + $tot - $enc;
|
|
}
|
|
print "torrents.value ${tor}\ntotal.value ${tot}\nencrypted.value ${enc}\nplain.value ${pla}\nincoming.value ${inc}\noutgoing.value ${out}\n";
|
|
|
|
exit;
|