2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Merge pull request #921 from sulaweyo/master

rtorrent version 0.9.7 compatible
This commit is contained in:
Lars Kruse 2018-07-15 17:18:15 +02:00 committed by GitHub
commit 579548697c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 294 additions and 260 deletions

View file

@ -27,6 +27,7 @@
# ip rTorrent's ip address - using scgi_port - needed, when "src" is NOT set to "socket" # ip rTorrent's ip address - using scgi_port - needed, when "src" is NOT set to "socket"
# port rTorrent's scgi port (scgi_port) - using scgi_port - needed, when "src" is NOT set to "socket" # port rTorrent's scgi port (scgi_port) - using scgi_port - needed, when "src" is NOT set to "socket"
# category Change graph category # category Change graph category
# api use "pre09" (pre 0.9.0) or "current" (0.9.0+) API calls
# #
# Configuration example # Configuration example
# #
@ -35,6 +36,7 @@
# env.src socket # env.src socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category # env.category Category
# env.api current
# #
# [rtom_allsessions_*] # [rtom_allsessions_*]
# user username # user username
@ -45,20 +47,20 @@
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
exit 1; exit 1;
} }
if ( $ARGV[0] and $ARGV[0] eq "config" ) { if ( $ARGV[0] and $ARGV[0] eq "config" ) {
my $category = $ENV{"category"} || ""; my $category = $ENV{"category"} || "";
print "graph_title rTorrent memory usage\n"; print "graph_title rTorrent memory usage\n";
print "graph_args --base 1024 --lower-limit 0\n"; print "graph_args --base 1024 --lower-limit 0\n";
print "graph_vlabel Bytes\n"; print "graph_vlabel Bytes\n";
print "graph_category filetransfer".${category}."\n"; print "graph_category filetransfer".${category}."\n";
print "mem.label Memory usage\n"; print "mem.label Memory usage\n";
print "mem.info Memory usage of rTorrent\n"; print "mem.info Memory usage of rTorrent\n";
print "mem.type GAUGE\n"; print "mem.type GAUGE\n";
print "mem.draw LINE2\n"; print "mem.draw LINE2\n";
exit 0; exit 0;
} }
use IO::Socket; use IO::Socket;
@ -66,44 +68,50 @@ my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || ""; my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1"; my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || ""; my @ports = split /,/, $ENV{"port"} || "";
my $api = $ENV{"api"} || "current";
my $mem = 0; my $mem = 0;
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_memory_usage</methodName></methodCall>"; my $line = "";
if ($api =~ /pre09/) {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_memory_usage</methodName></methodCall>";
} else {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>pieces.memory.current</methodName></methodCall>";
}
my $llen = length $line; my $llen = length $line;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header; my $hlen = length $header;
if ( ( defined $src ) && ( $src eq "socket" ) ) { if ( ( defined $src ) && ( $src eq "socket" ) ) {
for $socket (@sockets) for $socket (@sockets)
{ {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!; connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
while ( $line = <SOCK> ) { while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$mem = $mem + $2; $mem = $mem + $2;
} }
} }
close (SOCK); close (SOCK);
} }
} else { } else {
for $port (@ports) for $port (@ports)
{ {
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
while ( $line = <SOCK> ) { while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$mem = $mem + $2; $mem = $mem + $2;
} }
} }
close (SOCK); close (SOCK);
} }
} }
print "mem.value ${mem}\n"; print "mem.value ${mem}\n";

View file

@ -17,14 +17,15 @@
# #
# Parameters: # Parameters:
# #
# config required # config required
# #
# #
# Configurable variables # Configurable variables
# #
# src "socket" when using scgi_socket, or anything else when using scgi_port # 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" # socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is set to "socket"
# category Change graph category # category Change graph category
# api use "pre09" (pre 0.9.0) or "current" (0.9.0+) API calls
# #
# Configuration example # Configuration example
# #
@ -33,6 +34,7 @@
# env.src socket # env.src socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category # env.category Category
# env.api current
# #
# [rtom_allsessions_*] # [rtom_allsessions_*]
# user username # user username
@ -43,31 +45,31 @@
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
exit 1; exit 1;
} }
if ( $ARGV[0] and $ARGV[0] eq "config" ) { if ( $ARGV[0] and $ARGV[0] eq "config" ) {
my $category = $ENV{"category"} || ""; my $category = $ENV{"category"} || "";
print "graph_title rTorrent peer statistics\n"; print "graph_title rTorrent peer statistics\n";
print "graph_args --base 1000 --lower-limit 0\n"; print "graph_args --base 1000 --lower-limit 0\n";
print "graph_vlabel peers\n"; print "graph_vlabel peers\n";
print "graph_category filetransfer".${category}."\n"; print "graph_category filetransfer".${category}."\n";
print "outgoing.label outgoing\n"; print "outgoing.label outgoing\n";
print "outgoing.draw AREA\n"; print "outgoing.draw AREA\n";
print "outgoing.info number of outgoing connections\n"; print "outgoing.info number of outgoing connections\n";
print "incoming.label incoming\n"; print "incoming.label incoming\n";
print "incoming.draw STACK\n"; print "incoming.draw STACK\n";
print "incoming.info number of incoming connections\n"; print "incoming.info number of incoming connections\n";
print "plain.label plain text\n"; print "plain.label plain text\n";
print "plain.draw LINE2\n"; print "plain.draw LINE2\n";
print "plain.info number of plain text connections\n"; print "plain.info number of plain text connections\n";
print "encrypted.label encrypted\n"; print "encrypted.label encrypted\n";
print "encrypted.draw LINE2\n"; print "encrypted.draw LINE2\n";
print "encrypted.info number of encrypted connections\n"; print "encrypted.info number of encrypted connections\n";
print "total.label total\n"; print "total.label total\n";
print "total.draw LINE2\n"; print "total.draw LINE2\n";
print "total.info total number of connections\n"; print "total.info total number of connections\n";
exit 0; exit 0;
} }
use IO::Socket; use IO::Socket;
@ -76,14 +78,20 @@ my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || ""; my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1"; my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || ""; my @ports = split /,/, $ENV{"port"} || "";
my $api = $ENV{"api"} || "current";
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $tpattern = qr/[0-9A-F]{20}/; 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 $line = "";
my $llen = length $line; if ($api =~ /pre09/) {
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; $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 $hlen = length $header; } else {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall2</methodName><params><param><value><string></string></value></param><param><value><string>main</string></value></param><param><value><string>d.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;
my $tor = 0; my $tor = 0;
my $tot = 0; my $tot = 0;
@ -96,55 +104,55 @@ my $pla = 0;
if ( ( defined $src ) && ( $src eq "socket" ) ) { if ( ( defined $src ) && ( $src eq "socket" ) ) {
for $socket (@sockets) for $socket (@sockets)
{ {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!; connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
while ( $line = <SOCK> ) { while ( $line = <SOCK> ) {
if ( $line =~ /$tpattern/ ) { if ( $line =~ /$tpattern/ ) {
$tor += 1; $tor += 1;
} elsif ( $line =~ /$pattern/ ) { } elsif ( $line =~ /$pattern/ ) {
$tot += 1; $tot += 1;
$enc += $2; $enc += $2;
$line = <SOCK>; $line = <SOCK>;
$line =~ /$pattern/; $line =~ /$pattern/;
$inc += $2; $inc += $2;
} }
$ppline = $pline; $ppline = $pline;
$pline = $line; $pline = $line;
} }
close (SOCK); close (SOCK);
$out = $out + $tot - $inc; $out = $out + $tot - $inc;
$pla = $pla + $tot - $enc; $pla = $pla + $tot - $enc;
} }
} else { } else {
for $port (@ports) for $port (@ports)
{ {
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
while ( $line = <SOCK> ) { while ( $line = <SOCK> ) {
if ( $line =~ /$tpattern/ ) { if ( $line =~ /$tpattern/ ) {
$tor += 1; $tor += 1;
} elsif ( $line =~ /$pattern/ ) { } elsif ( $line =~ /$pattern/ ) {
$tot += 1; $tot += 1;
$enc += $2; $enc += $2;
$line = <SOCK>; $line = <SOCK>;
$line =~ /$pattern/; $line =~ /$pattern/;
$inc += $2; $inc += $2;
} }
$ppline = $pline; $ppline = $pline;
$pline = $line; $pline = $line;
} }
close (SOCK); close (SOCK);
$out = $out + $tot - $inc; $out = $out + $tot - $inc;
$pla = $pla + $tot - $enc; $pla = $pla + $tot - $enc;
} }
} }

View file

@ -36,6 +36,7 @@
# src "socket" when using scgi_socket, or anything else when using scgi_port # 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" # socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is set to "socket"
# diff "yes" for using bps for upload and Bps for download, or anything else for using Bps for both # diff "yes" for using bps for upload and Bps for download, or anything else for using Bps for both
# api use "pre09" (pre 0.9.0) or "current" (0.9.0+) API calls
# #
# #
# Configuration example # Configuration example
@ -45,6 +46,7 @@
# env.src socket # env.src socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category # env.category Category
# env.api pre09
# #
# [rtom_allsessions_*] # [rtom_allsessions_*]
# user username # user username
@ -55,34 +57,34 @@
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
exit 1; exit 1;
} }
if ( $ARGV[0] and $ARGV[0] eq "config" ) { if ( $ARGV[0] and $ARGV[0] eq "config" ) {
my $diff = $ENV{"diff"} || ""; my $diff = $ENV{"diff"} || "";
my $category = $ENV{"category"} || ""; my $category = $ENV{"category"} || "";
print "graph_order down up\n"; print "graph_order down up\n";
print "graph_title rTorrent speeds\n"; print "graph_title rTorrent speeds\n";
print "graph_args --base 1024\n"; print "graph_args --base 1024\n";
print "graph_vlabel Bytes per \${graph_period}\n"; print "graph_vlabel Bytes per \${graph_period}\n";
print "graph_category filetransfer".${category}."\n"; print "graph_category filetransfer".${category}."\n";
print "down.label Download B/s\n"; print "down.label Download B/s\n";
print "down.info Download speed in Bytes per seconds\n"; print "down.info Download speed in Bytes per seconds\n";
print "down.type DERIVE\n"; print "down.type DERIVE\n";
print "down.min 0\n"; print "down.min 0\n";
print "down.draw AREA\n"; print "down.draw AREA\n";
if ( ( defined $diff ) && ( $diff eq "yes" ) ) { if ( ( defined $diff ) && ( $diff eq "yes" ) ) {
print "up.label Upload b/s\n"; print "up.label Upload b/s\n";
print "up.info Upload speed in bits per seconds\n"; print "up.info Upload speed in bits per seconds\n";
print "up.cdef up,8,*\n"; print "up.cdef up,8,*\n";
} else { } else {
print "up.label Upload B/s\n"; print "up.label Upload B/s\n";
print "up.info Upload speed in Bytes per seconds\n"; print "up.info Upload speed in Bytes per seconds\n";
} }
print "up.type DERIVE\n"; print "up.type DERIVE\n";
print "up.min 0\n"; print "up.min 0\n";
print "up.draw LINE2\n"; print "up.draw LINE2\n";
exit 0; exit 0;
} }
use IO::Socket; use IO::Socket;
@ -90,9 +92,16 @@ my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || ""; my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1"; my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || ""; my @ports = split /,/, $ENV{"port"} || "";
my $api = $ENV{"api"} || "current";
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; my $pattern = qr/<value><(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>system.multicall</methodName><params><param><value><array><data><value><struct><member><name>methodName</name><value><string>get_up_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_down_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_upload_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_download_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value></data></array></value></param></params></methodCall>"; my $line = "";
if ($api =~ /pre09/) {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>system.multicall</methodName><params><param><value><array><data><value><struct><member><name>methodName</name><value><string>get_up_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_down_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_upload_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_download_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value></data></array></value></param></params></methodCall>";
} else {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>system.multicall</methodName><params><param><value><array><data><value><struct><member><name>methodName</name><value><string>throttle.global_up.total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>throttle.global_down.total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>throttle.global_up.max_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>throttle.global_down.max_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value></data></array></value></param></params></methodCall>";
}
my $llen = length $line; my $llen = length $line;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header; my $hlen = length $header;
@ -101,53 +110,53 @@ my $up = -1;
my $down = -1; my $down = -1;
if ( ( defined $src ) && ( $src eq "socket" ) ) { if ( ( defined $src ) && ( $src eq "socket" ) ) {
for $socket (@sockets) for $socket (@sockets)
{ {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!; connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
my $up_tmp = -1; my $up_tmp = -1;
my $down_tmp = -1; my $down_tmp = -1;
while (( $up_tmp == -1 ) && ( $line = <SOCK> ) ) { while (( $up_tmp == -1 ) && ( $line = <SOCK> ) ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$up_tmp = $2; $up_tmp = $2;
} }
} }
while (( $down_tmp == -1 ) && ( $line = <SOCK> ) ) { while (( $down_tmp == -1 ) && ( $line = <SOCK> ) ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$down_tmp = $2; $down_tmp = $2;
} }
} }
close (SOCK); close (SOCK);
$up = $up + $up_tmp; $up = $up + $up_tmp;
$down = $down + $down_tmp; $down = $down + $down_tmp;
} }
} else { } else {
for $port (@ports) for $port (@ports)
{ {
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
my $up_tmp = -1; my $up_tmp = -1;
my $down_tmp = -1; my $down_tmp = -1;
while (( $up_tmp == -1 ) && ( $line = <SOCK> ) ) { while (( $up_tmp == -1 ) && ( $line = <SOCK> ) ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$up_tmp = $2; $up_tmp = $2;
} }
} }
while (( $down_tmp == -1 ) && ( $line = <SOCK> ) ) { while (( $down_tmp == -1 ) && ( $line = <SOCK> ) ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$down_tmp = $2; $down_tmp = $2;
} }
} }
close (SOCK); close (SOCK);
$up = $up + $up_tmp; $up = $up + $up_tmp;
$down = $down + $down_tmp; $down = $down + $down_tmp;
} }
} }

View file

@ -17,14 +17,15 @@
# #
# Parameters: # Parameters:
# #
# config required # config required
# #
# #
# Configurable variables # Configurable variables
# #
# src "socket" when using scgi_socket, or anything else when using scgi_port # 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" # socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is set to "socket"
# category Change graph category # category Change graph category
# api use "pre09" (pre 0.9.0) or 'current' (0.9.0+) API calls
# #
# Configuration example # Configuration example
# #
@ -33,45 +34,47 @@
# env.src socket # env.src socket
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
# env.category Category # env.category Category
# env.api current
# #
# [rtom_allsessions_*] # [rtom_allsessions_*]
# user username # user username
# env.port 5000,5001,5002,5003 # env.port 5000,5001,5002,5003
# env.category Category # env.category Category
# env.api pre09
# #
#%# family=auto #%# family=auto
my @views = ( "default", "started", "stopped", "complete", "incomplete" ); my @views = ( "default", "started", "stopped", "complete", "incomplete" );
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
exit 1; exit 1;
} }
if ( $ARGV[0] and $ARGV[0] eq "config" ) { if ( $ARGV[0] and $ARGV[0] eq "config" ) {
my $category = $ENV{"category"} || ""; my $category = $ENV{"category"} || "";
print "graph_args --base 1000 -r --lower-limit 0\n"; print "graph_args --base 1000 -r --lower-limit 0\n";
print "graph_title rTorrent volume\n"; print "graph_title rTorrent volume\n";
print "graph_vlabel active torrents\n"; print "graph_vlabel active torrents\n";
print "graph_category filetransfer".${category}."\n"; print "graph_category filetransfer".${category}."\n";
print "complete.label complete\n"; print "complete.label complete\n";
print "complete.draw AREA\n"; print "complete.draw AREA\n";
print "complete.info complete torrents\n"; print "complete.info complete torrents\n";
print "incomplete.label incomplete\n"; print "incomplete.label incomplete\n";
print "incomplete.draw STACK\n"; print "incomplete.draw STACK\n";
print "incomplete.info incomplete torrents\n"; print "incomplete.info incomplete torrents\n";
print "stopped.label stopped\n"; print "stopped.label stopped\n";
print "stopped.draw LINE2\n"; print "stopped.draw LINE2\n";
print "stopped.info stopped torrents\n"; print "stopped.info stopped torrents\n";
print "started.label started\n"; print "started.label started\n";
print "started.draw LINE2\n"; print "started.draw LINE2\n";
print "started.info started torrents\n"; print "started.info started torrents\n";
print "default.label total\n"; print "default.label total\n";
print "default.draw LINE2\n"; print "default.draw LINE2\n";
print "default.info all torrents\n"; print "default.info all torrents\n";
print "hashing.graph no\n"; print "hashing.graph no\n";
print "seeding.graph no\n"; print "seeding.graph no\n";
print "active.graph no\n"; print "active.graph no\n";
exit 0; exit 0;
} }
use IO::Socket; use IO::Socket;
@ -80,48 +83,54 @@ my $src = $ENV{"src"} || "";
my @sockets = split /,/, $ENV{"socket"} || ""; my @sockets = split /,/, $ENV{"socket"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1"; my $ip = $ENV{"ip"} || "127.0.0.1";
my @ports = split /,/, $ENV{"port"} || ""; my @ports = split /,/, $ENV{"port"} || "";
my $api = $ENV{"api"} || "current";
my $pattern = qr/<value><string>([A-Z0-9]+)<\/string><\/value>/; my $pattern = qr/<value><string>([A-Z0-9]+)<\/string><\/value>/;
foreach ( @views ) { foreach ( @views ) {
my $num = 0; my $num = 0;
my $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>"; my $line = "";
my $llen = length $line; if ($api =~ /pre09/) {
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; $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>";
my $hlen = length $header; } 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;
if ( ( defined $src ) && ( $src eq "socket" ) ) { if ( ( defined $src ) && ( $src eq "socket" ) ) {
for $socket (@sockets) for $socket (@sockets)
{ {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!; connect( SOCK, sockaddr_un( $socket ) ) or die $!;
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
while ( $line = <SOCK> ) { while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$num++; $num++;
} }
} }
close (SOCK); close (SOCK);
} }
} else { } else {
for $port (@ports) for $port (@ports)
{ {
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
my $line = "${hlen}:${header},${line}"; my $line = "${hlen}:${header},${line}";
print SOCK $line; print SOCK $line;
flush SOCK; flush SOCK;
while ( $line = <SOCK> ) { while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) { if ( $line =~ /$pattern/ ) {
$num++; $num++;
} }
} }
close (SOCK); close (SOCK);
} }
} }
print "${_}.value ${num}\n"; print "${_}.value ${num}\n";
} }
exit; exit;