From 8bfb81806d1e1489512d5936b1733c5e769e0d0c Mon Sep 17 00:00:00 2001 From: Sledge Sulaweyo Date: Fri, 6 Jul 2018 16:41:11 +0200 Subject: [PATCH] drop seperate files and make api version configureable --- plugins/rtorrent/rtom_allsessions_097_mem | 111 -------------- plugins/rtorrent/rtom_allsessions_097_peers | 152 ------------------- plugins/rtorrent/rtom_allsessions_097_spdd | 157 -------------------- plugins/rtorrent/rtom_allsessions_097_vol | 127 ---------------- plugins/rtorrent/rtom_allsessions_mem | 16 +- plugins/rtorrent/rtom_allsessions_peers | 20 ++- plugins/rtorrent/rtom_allsessions_spdd | 15 +- plugins/rtorrent/rtom_allsessions_vol | 145 +++++++++--------- 8 files changed, 115 insertions(+), 628 deletions(-) delete mode 100644 plugins/rtorrent/rtom_allsessions_097_mem delete mode 100644 plugins/rtorrent/rtom_allsessions_097_peers delete mode 100644 plugins/rtorrent/rtom_allsessions_097_spdd delete mode 100644 plugins/rtorrent/rtom_allsessions_097_vol diff --git a/plugins/rtorrent/rtom_allsessions_097_mem b/plugins/rtorrent/rtom_allsessions_097_mem deleted file mode 100644 index 29190896..00000000 --- a/plugins/rtorrent/rtom_allsessions_097_mem +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/perl -w -# -# xmlrpc based munin plugin for monitoring rtorrent's memory usage -# prerequisites: -# - rtorrent 0.9.7 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" -# 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" -# category Change graph category -# -# Configuration example -# -# [rtom_allsessions_*] -# user username -# env.src socket -# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket -# env.category Category -# -# [rtom_allsessions_*] -# user username -# env.port 5000,5001,5002,5003 -# 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 memory usage\n"; - print "graph_args --base 1024 --lower-limit 0\n"; - print "graph_vlabel Bytes\n"; - print "graph_category torrent ".${category}."\n"; - print "mem.label Memory usage\n"; - print "mem.info Memory usage of rTorrent\n"; - print "mem.type GAUGE\n"; - print "mem.draw LINE2\n"; - exit 0; -} - -use IO::Socket; -my $src = $ENV{"src"} || ""; -my @sockets = split /,/, $ENV{"socket"} || ""; -my $ip = $ENV{"ip"} || "127.0.0.1"; -my @ports = split /,/, $ENV{"port"} || ""; - -my $mem = 0; -my $pattern = qr/<(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; -my $line = "pieces.memory.current"; -my $llen = length $line; -my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; -my $hlen = length $header; - -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 = ) { - if ( $line =~ /$pattern/ ) { - $mem = $mem + $2; - } - } - 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 = ) { - if ( $line =~ /$pattern/ ) { - $mem = $mem + $2; - } - } - close (SOCK); - } -} - -print "mem.value ${mem}\n"; - -exit; diff --git a/plugins/rtorrent/rtom_allsessions_097_peers b/plugins/rtorrent/rtom_allsessions_097_peers deleted file mode 100644 index f4eb0b44..00000000 --- a/plugins/rtorrent/rtom_allsessions_097_peers +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/perl -w -# -# xmlrpc based munin plugin for monitoring rtorrent's peer count -# prerequisites: -# - rtorrent 0.9.7 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_allsessions_*] -# user username -# env.src socket -# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket -# env.category Category -# -# [rtom_allsessions_*] -# user username -# env.port 5000,5001,5002,5003 -# 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 torrent ".${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 $src = $ENV{"src"} || ""; -my @sockets = split /,/, $ENV{"socket"} || ""; -my $ip = $ENV{"ip"} || "127.0.0.1"; -my @ports = split /,/, $ENV{"port"} || ""; - -my $pattern = qr/<(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; -my $tpattern = qr/[0-9A-F]{20}/; - -my $line = "d.multicall2maind.hash=p.multicall=,p.is_encrypted=,p.is_incoming="; -my $llen = length $line; -my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; -my $hlen = length $header; -my $tor = 0; -my $tot = 0; -my $enc = 0; -my $inc = 0; -my $pline = ""; -my $ppline = ""; -my $out = 0; -my $pla = 0; - - -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 = ) { - if ( $line =~ /$tpattern/ ) { - $tor += 1; - } elsif ( $line =~ /$pattern/ ) { - $tot += 1; - $enc += $2; - $line = ; - $line =~ /$pattern/; - $inc += $2; - } - $ppline = $pline; - $pline = $line; - } - close (SOCK); - $out = $out + $tot - $inc; - $pla = $pla + $tot - $enc; - } -} 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 = ) { - if ( $line =~ /$tpattern/ ) { - $tor += 1; - } elsif ( $line =~ /$pattern/ ) { - $tot += 1; - $enc += $2; - $line = ; - $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; diff --git a/plugins/rtorrent/rtom_allsessions_097_spdd b/plugins/rtorrent/rtom_allsessions_097_spdd deleted file mode 100644 index a33db538..00000000 --- a/plugins/rtorrent/rtom_allsessions_097_spdd +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/perl -w -# -# xmlrpc based munin plugin for monitoring rtorrent's upload/download speed -# prerequisites: -# - rtorrent 0.9.7 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.0.0 - 071218 -# initial release -# -# 0.0.1 - 071220 -# minor textbugs fixed -# -# 0.1.0d - 080519 -# full rewrite in perl -# support for scgi_port and scgi_local -# configurable via munin env variables -# different ul/dl scale can be set for asymmetric connections -# using get_(up|down)_total, and derive -# -# 0.2.0 - 080619 -# upload and download limit displayed on the graph -# -# -# 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" -# diff "yes" for using bps for upload and Bps for download, or anything else for using Bps for both -# -# -# Configuration example -# -# [rtom_allsessions_*] -# user username -# env.src socket -# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket -# env.category Category -# -# [rtom_allsessions_*] -# user username -# env.port 5000,5001,5002,5003 -# env.category Category -# -#%# family=auto - - -if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { - exit 1; -} - -if ( $ARGV[0] and $ARGV[0] eq "config" ) { - my $diff = $ENV{"diff"} || ""; - my $category = $ENV{"category"} || ""; - print "graph_order down up\n"; - print "graph_title rTorrent speeds\n"; - print "graph_args --base 1024\n"; - print "graph_vlabel Bytes per \${graph_period}\n"; - print "graph_category torrent ".${category}."\n"; - print "down.label Download B/s\n"; - print "down.info Download speed in Bytes per seconds\n"; - print "down.type DERIVE\n"; - print "down.min 0\n"; - print "down.draw AREA\n"; - if ( ( defined $diff ) && ( $diff eq "yes" ) ) { - print "up.label Upload b/s\n"; - print "up.info Upload speed in bits per seconds\n"; - print "up.cdef up,8,*\n"; - } else { - print "up.label Upload B/s\n"; - print "up.info Upload speed in Bytes per seconds\n"; - } - print "up.type DERIVE\n"; - print "up.min 0\n"; - print "up.draw LINE2\n"; - exit 0; -} - -use IO::Socket; -my $src = $ENV{"src"} || ""; -my @sockets = split /,/, $ENV{"socket"} || ""; -my $ip = $ENV{"ip"} || "127.0.0.1"; -my @ports = split /,/, $ENV{"port"} || ""; - -my $pattern = qr/<(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; -my $line = "system.multicallmethodNamethrottle.global_up.totalparamsmethodNamethrottle.global_down.totalparamsmethodNamethrottle.global_up.max_rateparamsmethodNamethrottle.global_down.max_rateparams"; -my $llen = length $line; -my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; -my $hlen = length $header; - -my $up = -1; -my $down = -1; - -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; - my $up_tmp = -1; - my $down_tmp = -1; - while (( $up_tmp == -1 ) && ( $line = ) ) { - if ( $line =~ /$pattern/ ) { - $up_tmp = $2; - } - } - while (( $down_tmp == -1 ) && ( $line = ) ) { - if ( $line =~ /$pattern/ ) { - $down_tmp = $2; - } - } - close (SOCK); - $up = $up + $up_tmp; - $down = $down + $down_tmp; - } -} 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; - my $up_tmp = -1; - my $down_tmp = -1; - while (( $up_tmp == -1 ) && ( $line = ) ) { - if ( $line =~ /$pattern/ ) { - $up_tmp = $2; - } - } - while (( $down_tmp == -1 ) && ( $line = ) ) { - if ( $line =~ /$pattern/ ) { - $down_tmp = $2; - } - } - close (SOCK); - $up = $up + $up_tmp; - $down = $down + $down_tmp; - } -} - - - -print "up.value ${up}\ndown.value ${down}\n"; - -exit; diff --git a/plugins/rtorrent/rtom_allsessions_097_vol b/plugins/rtorrent/rtom_allsessions_097_vol deleted file mode 100644 index 6b14e4f7..00000000 --- a/plugins/rtorrent/rtom_allsessions_097_vol +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/perl -w -# -# xmlrpc based munin plugin for monitoring rtorrent's torrent count -# prerequisites: -# - rtorrent 0.9.7 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_allsessions_*] -# user username -# env.src socket -# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket -# env.category Category -# -# [rtom_allsessions_*] -# user username -# env.port 5000,5001,5002,5003 -# env.category Category -# -#%# family=auto - -my @views = ( "default", "started", "stopped", "complete", "incomplete" ); - -if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { - exit 1; -} - -if ( $ARGV[0] and $ARGV[0] eq "config" ) { - 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; -} - -use IO::Socket; - -my $src = $ENV{"src"} || ""; -my @sockets = split /,/, $ENV{"socket"} || ""; -my $ip = $ENV{"ip"} || "127.0.0.1"; -my @ports = split /,/, $ENV{"port"} || ""; - -my $pattern = qr/([A-Z0-9]+)<\/string><\/value>/; - -foreach ( @views ) { - my $num = 0; - my $line = "d.multicall2${_}d.hash="; - my $llen = length $line; - my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; - my $hlen = length $header; - - 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 = ) { - 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 = ) { - if ( $line =~ /$pattern/ ) { - $num++; - } - } - close (SOCK); - } - } - print "${_}.value ${num}\n"; -} - -exit; diff --git a/plugins/rtorrent/rtom_allsessions_mem b/plugins/rtorrent/rtom_allsessions_mem index 1b12be09..1c83292b 100755 --- a/plugins/rtorrent/rtom_allsessions_mem +++ b/plugins/rtorrent/rtom_allsessions_mem @@ -27,6 +27,7 @@ # 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" # category Change graph category +# api use 'legacy' (pre 0.9.0) or current (0.9.0+) API calls # # Configuration example # @@ -35,6 +36,7 @@ # env.src socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.category Category +# env.api current # # [rtom_allsessions_*] # user username @@ -66,10 +68,16 @@ my $src = $ENV{"src"} || ""; my @sockets = split /,/, $ENV{"socket"} || ""; my $ip = $ENV{"ip"} || "127.0.0.1"; my @ports = split /,/, $ENV{"port"} || ""; +my $api = $ENV{"api"} || "legacy"; -my $mem = 0; +my $mem = 0; my $pattern = qr/<(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; -my $line = "get_memory_usage"; +my $line = ""; +if ($api =~ /legacy/) { + $line = "get_memory_usage"; +} else { + $line = "pieces.memory.current"; +} my $llen = length $line; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $hlen = length $header; @@ -88,10 +96,10 @@ if ( ( defined $src ) && ( $src eq "socket" ) ) { } } 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}"; diff --git a/plugins/rtorrent/rtom_allsessions_peers b/plugins/rtorrent/rtom_allsessions_peers index a3cc1705..e0ea4532 100755 --- a/plugins/rtorrent/rtom_allsessions_peers +++ b/plugins/rtorrent/rtom_allsessions_peers @@ -22,9 +22,10 @@ # # 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 +# 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 +# api use 'legacy' (pre 0.9.0) or current (0.9.0+) API calls # # Configuration example # @@ -33,6 +34,7 @@ # env.src socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.category Category +# env.api current # # [rtom_allsessions_*] # user username @@ -76,11 +78,17 @@ my $src = $ENV{"src"} || ""; my @sockets = split /,/, $ENV{"socket"} || ""; my $ip = $ENV{"ip"} || "127.0.0.1"; my @ports = split /,/, $ENV{"port"} || ""; +my $api = $ENV{"api"} || "legacy"; my $pattern = qr/<(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; my $tpattern = qr/[0-9A-F]{20}/; -my $line = "d.multicallmaind.get_hash=p.multicall=,p.is_encrypted=,p.is_incoming="; +my $line = ""; +if ($api =~ /legacy/) { + $line = "d.multicallmaind.get_hash=p.multicall=,p.is_encrypted=,p.is_incoming="; +} else { + $line = "d.multicall2maind.hash=p.multicall=,p.is_encrypted=,p.is_incoming="; +} my $llen = length $line; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $hlen = length $header; @@ -119,10 +127,10 @@ if ( ( defined $src ) && ( $src eq "socket" ) ) { close (SOCK); $out = $out + $tot - $inc; $pla = $pla + $tot - $enc; - } + } } 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}"; diff --git a/plugins/rtorrent/rtom_allsessions_spdd b/plugins/rtorrent/rtom_allsessions_spdd index ed89061a..26e51435 100755 --- a/plugins/rtorrent/rtom_allsessions_spdd +++ b/plugins/rtorrent/rtom_allsessions_spdd @@ -36,6 +36,7 @@ # 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" # diff "yes" for using bps for upload and Bps for download, or anything else for using Bps for both +# api use 'legacy' (pre 0.9.0) or current (0.9.0+) API calls # # # Configuration example @@ -45,6 +46,7 @@ # env.src socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.category Category +# env.api current # # [rtom_allsessions_*] # user username @@ -90,9 +92,16 @@ my $src = $ENV{"src"} || ""; my @sockets = split /,/, $ENV{"socket"} || ""; my $ip = $ENV{"ip"} || "127.0.0.1"; my @ports = split /,/, $ENV{"port"} || ""; +my $api = $ENV{"api"} || "legacy"; my $pattern = qr/<(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; -my $line = "system.multicallmethodNameget_up_totalparamsmethodNameget_down_totalparamsmethodNameget_upload_rateparamsmethodNameget_download_rateparams"; +my $line = ""; +if ($api =~ /legacy/) { + $line = "system.multicallmethodNameget_up_totalparamsmethodNameget_down_totalparamsmethodNameget_upload_rateparamsmethodNameget_download_rateparams"; +} else { + $line = "system.multicallmethodNamethrottle.global_up.totalparamsmethodNamethrottle.global_down.totalparamsmethodNamethrottle.global_up.max_rateparamsmethodNamethrottle.global_down.max_rateparams"; +} + my $llen = length $line; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $hlen = length $header; @@ -123,10 +132,10 @@ if ( ( defined $src ) && ( $src eq "socket" ) ) { close (SOCK); $up = $up + $up_tmp; $down = $down + $down_tmp; - } + } } 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}"; diff --git a/plugins/rtorrent/rtom_allsessions_vol b/plugins/rtorrent/rtom_allsessions_vol index 830575f4..fe99af9b 100755 --- a/plugins/rtorrent/rtom_allsessions_vol +++ b/plugins/rtorrent/rtom_allsessions_vol @@ -3,7 +3,7 @@ # xmlrpc based munin plugin for monitoring rtorrent's torrent count # prerequisites: # - rtorrent 0.7.5 or newer compiled with --with-xmlrpc-c -# check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further information +# check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further informations # # written by Gabor Hudiczius # web: http://projects.cyla.homeip.net/rtwi/wiki/rTorrentOMeter @@ -17,14 +17,15 @@ # # Parameters: # -# config required +# 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 +# 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 +# api use 'legacy' (pre 0.9.0) or current (0.9.0+) API calls # # Configuration example # @@ -33,45 +34,47 @@ # env.src socket # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket # env.category Category +# env.api current # # [rtom_allsessions_*] # user username # env.port 5000,5001,5002,5003 # env.category Category +# env.api legacy # #%# family=auto my @views = ( "default", "started", "stopped", "complete", "incomplete" ); if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { - exit 1; + exit 1; } if ( $ARGV[0] and $ARGV[0] eq "config" ) { - 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 filetransfer".${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; + 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; } use IO::Socket; @@ -80,48 +83,54 @@ my $src = $ENV{"src"} || ""; my @sockets = split /,/, $ENV{"socket"} || ""; my $ip = $ENV{"ip"} || "127.0.0.1"; my @ports = split /,/, $ENV{"port"} || ""; +my $api = $ENV{"api"} || "legacy"; -my $pattern = qr/([A-Z0-9]+)<\/string><\/value>/; +my $pattern = qr/([A-Z0-9]+)<\/string><\/value>/; foreach ( @views ) { - my $num = 0; - my $line = "d.multicall${_}d.get_hash="; - my $llen = length $line; - my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; - my $hlen = length $header; + my $num = 0; + my $line = ""; + if ($api =~ /legacy/) { + $line = "d.multicall${_}d.get_hash="; + } else { + $line = "d.multicall2${_}d.hash="; + } + my $llen = length $line; + my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; + my $hlen = length $header; - 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 = ) { - 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 = ) { - if ( $line =~ /$pattern/ ) { - $num++; - } - } - close (SOCK); - } - } - print "${_}.value ${num}\n"; + 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 = ) { + 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 = ) { + if ( $line =~ /$pattern/ ) { + $num++; + } + } + close (SOCK); + } + } + print "${_}.value ${num}\n"; } exit;