2014-02-05 11:32:00 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# xmlrpc based munin plugin for monitoring rtorrent's torrent count
|
|
|
|
# prerequisites:
|
|
|
|
# - rtorrent 0.7.5 or newer compiled with --with-xmlrpc-c
|
2018-07-10 16:58:28 +02:00
|
|
|
# check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further information
|
2014-02-05 11:32:00 +01:00
|
|
|
#
|
|
|
|
# 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:
|
|
|
|
#
|
2018-07-06 16:41:11 +02:00
|
|
|
# config required
|
2014-02-05 11:32:00 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# Configurable variables
|
|
|
|
#
|
2018-07-06 16:41:11 +02:00
|
|
|
# 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
|
2018-07-10 16:58:28 +02:00
|
|
|
# api use 'pre09' (pre 0.9.0) or 'current' (0.9.0+) API calls
|
2014-02-05 11:32:00 +01:00
|
|
|
#
|
|
|
|
# Configuration example
|
|
|
|
#
|
2014-02-25 10:50:59 +01:00
|
|
|
# [rtom_allsessions_*]
|
|
|
|
# user username
|
|
|
|
# env.src socket
|
|
|
|
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
|
|
|
|
# env.category Category
|
2018-07-06 16:41:11 +02:00
|
|
|
# env.api current
|
2014-02-25 10:50:59 +01:00
|
|
|
#
|
|
|
|
# [rtom_allsessions_*]
|
|
|
|
# user username
|
|
|
|
# env.port 5000,5001,5002,5003
|
|
|
|
# env.category Category
|
2018-07-10 16:58:28 +02:00
|
|
|
# env.api pre09
|
2014-02-05 11:32:00 +01:00
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
|
|
|
|
my @views = ( "default", "started", "stopped", "complete", "incomplete" );
|
|
|
|
|
|
|
|
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
2018-07-10 16:58:28 +02:00
|
|
|
exit 1;
|
2014-02-05 11:32:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
2018-07-10 16:58:28 +02:00
|
|
|
my $category = $ENV{"category"} || "";
|
|
|
|
print "graph_args --base 1000 -r --lower-limit 0\n";
|
|
|
|
print "graph_title rTorrent volume\n";
|
|
|
|
print "graph_vlabel active torrents\n";
|
|
|
|
print "graph_category torrent ".${category}."\n";
|
|
|
|
print "complete.label complete\n";
|
|
|
|
print "complete.draw AREA\n";
|
|
|
|
print "complete.info complete torrents\n";
|
|
|
|
print "incomplete.label incomplete\n";
|
|
|
|
print "incomplete.draw STACK\n";
|
|
|
|
print "incomplete.info incomplete torrents\n";
|
|
|
|
print "stopped.label stopped\n";
|
|
|
|
print "stopped.draw LINE2\n";
|
|
|
|
print "stopped.info stopped torrents\n";
|
|
|
|
print "started.label started\n";
|
|
|
|
print "started.draw LINE2\n";
|
|
|
|
print "started.info started torrents\n";
|
|
|
|
print "default.label total\n";
|
|
|
|
print "default.draw LINE2\n";
|
|
|
|
print "default.info all torrents\n";
|
|
|
|
print "hashing.graph no\n";
|
|
|
|
print "seeding.graph no\n";
|
|
|
|
print "active.graph no\n";
|
|
|
|
exit 0;
|
2014-02-05 11:32:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
use IO::Socket;
|
|
|
|
|
|
|
|
my $src = $ENV{"src"} || "";
|
2014-02-25 10:50:59 +01:00
|
|
|
my @sockets = split /,/, $ENV{"socket"} || "";
|
|
|
|
my $ip = $ENV{"ip"} || "127.0.0.1";
|
|
|
|
my @ports = split /,/, $ENV{"port"} || "";
|
2018-07-10 16:58:28 +02:00
|
|
|
my $api = $ENV{"api"} || "pre09";
|
2014-02-05 11:32:00 +01:00
|
|
|
|
2018-07-06 16:41:11 +02:00
|
|
|
my $pattern = qr/<value><string>([A-Z0-9]+)<\/string><\/value>/;
|
2014-02-05 11:32:00 +01:00
|
|
|
|
|
|
|
foreach ( @views ) {
|
2018-07-10 16:58:28 +02:00
|
|
|
my $num = 0;
|
|
|
|
my $line = "";
|
|
|
|
if ($api =~ /pre09/) {
|
|
|
|
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall</methodName><params><param><value><string>${_}</string></value></param><param><value><string>d.get_hash=</string></value></param></params></methodCall>";
|
|
|
|
} else {
|
|
|
|
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall2</methodName><params><param><value><string></string></value></param><param><value><string>${_}</string></value></param><param><value><string>d.hash=</string></value></param></params></methodCall>";
|
|
|
|
}
|
|
|
|
my $llen = length $line;
|
|
|
|
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
|
|
|
my $hlen = length $header;
|
2014-02-05 11:32:00 +01:00
|
|
|
|
2018-07-10 16:58:28 +02:00
|
|
|
if ( ( defined $src ) && ( $src eq "socket" ) ) {
|
|
|
|
for $socket (@sockets)
|
|
|
|
{
|
|
|
|
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
|
|
|
|
connect( SOCK, sockaddr_un( $socket ) ) or die $!;
|
|
|
|
my $line = "${hlen}:${header},${line}";
|
|
|
|
print SOCK $line;
|
|
|
|
flush SOCK;
|
|
|
|
while ( $line = <SOCK> ) {
|
|
|
|
if ( $line =~ /$pattern/ ) {
|
|
|
|
$num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (SOCK);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for $port (@ports)
|
|
|
|
{
|
|
|
|
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
|
|
|
|
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
|
|
|
|
my $line = "${hlen}:${header},${line}";
|
|
|
|
print SOCK $line;
|
|
|
|
flush SOCK;
|
|
|
|
while ( $line = <SOCK> ) {
|
|
|
|
if ( $line =~ /$pattern/ ) {
|
|
|
|
$num++;
|
2018-07-06 16:41:11 +02:00
|
|
|
}
|
2018-07-10 16:58:28 +02:00
|
|
|
}
|
|
|
|
close (SOCK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print "${_}.value ${num}\n";
|
2014-02-05 11:32:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|