From acba11893782be0883ede6a5b4154c052c0689a2 Mon Sep 17 00:00:00 2001 From: XciD Date: Wed, 5 Feb 2014 11:31:24 +0100 Subject: [PATCH] Create rtom_allsessions_spdd For all sessions --- plugins/rtorrent/rtom_allsessions_spdd | 124 +++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 plugins/rtorrent/rtom_allsessions_spdd diff --git a/plugins/rtorrent/rtom_allsessions_spdd b/plugins/rtorrent/rtom_allsessions_spdd new file mode 100644 index 00000000..be226160 --- /dev/null +++ b/plugins/rtorrent/rtom_allsessions_spdd @@ -0,0 +1,124 @@ +#!/usr/bin/perl -w +# +# xmlrpc based munin plugin for monitoring rtorrent's upload/download speed +# 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.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_spdd] +# user username +# env.src socket +# env.socket /home/user/torrent/.socket/rpc.socket,/home/user2/torrent/.socket/rpc2.socket +# env.category Sometext +# +# +#%# 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 rTorrent ".${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 @sockets = split /,/, $ENV{"socket"} || ""; +my $src = $ENV{"src"} || ""; + +my $up = -1; +my $down = -1; + +for $socket (@sockets) +{ + 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 $llen = length $line; + my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; + my $hlen = length $header; + $line = "${hlen}:${header},${line}"; + if ( ( defined $src ) && ( $src eq "socket" ) ) { + socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ); + connect( SOCK, sockaddr_un( $socket ) ); + } + + 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;