From 80dcbf723189e0735b0dd5365965af99c4398f72 Mon Sep 17 00:00:00 2001 From: XciD Date: Tue, 25 Feb 2014 10:35:06 +0100 Subject: [PATCH] Update rtom_allsessions_mem Add ip / port function --- plugins/rtorrent/rtom_allsessions_mem | 54 +++++++++++++++++++-------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/plugins/rtorrent/rtom_allsessions_mem b/plugins/rtorrent/rtom_allsessions_mem index 42dcc077..0187eadf 100644 --- a/plugins/rtorrent/rtom_allsessions_mem +++ b/plugins/rtorrent/rtom_allsessions_mem @@ -24,16 +24,23 @@ # # 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_all] +# [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 @@ -55,33 +62,48 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { } use IO::Socket; -my @sockets = split /,/, $ENV{"socket"} || ""; -my $mem = 0; 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 = "get_memory_usage"; my $llen = length $line; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $hlen = length $header; -$line = "${hlen}:${header},${line}"; -for $socket (@sockets) -{ - if ( ( defined $src ) && ( $src eq "socket" ) ) { +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 $!; - } - - print SOCK $line; - flush SOCK; - - while ( $line = ) { - if ( $line =~ /$pattern/ ) { - $mem = $mem + $2; + 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); } - close (SOCK); } print "mem.value ${mem}\n";