root / plugins / rtorrent / rtom_allsessions_vol @ 121448e7
Historique | Voir | Annoter | Télécharger (4,22 ko)
| 1 | f519cf3a | XciD | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # |
||
| 3 | # xmlrpc based munin plugin for monitoring rtorrent's torrent count |
||
| 4 | # prerequisites: |
||
| 5 | # - rtorrent 0.7.5 or newer compiled with --with-xmlrpc-c |
||
| 6 | 121448e7 | Sledge Sulaweyo | # check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further information |
| 7 | f519cf3a | XciD | # |
| 8 | # written by Gabor Hudiczius |
||
| 9 | # web: http://projects.cyla.homeip.net/rtwi/wiki/rTorrentOMeter |
||
| 10 | # email: ghudiczius@gmail.com |
||
| 11 | # |
||
| 12 | # 0.2.0 - 080619 |
||
| 13 | # support for scgi_port and scgi_local |
||
| 14 | # configurable via munin env variables |
||
| 15 | # initial release |
||
| 16 | # |
||
| 17 | # |
||
| 18 | # Parameters: |
||
| 19 | # |
||
| 20 | 8bfb8180 | Sledge Sulaweyo | # config required |
| 21 | f519cf3a | XciD | # |
| 22 | # |
||
| 23 | # Configurable variables |
||
| 24 | # |
||
| 25 | 8bfb8180 | Sledge Sulaweyo | # src "socket" when using scgi_socket, or anything else when using scgi_port |
| 26 | # socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is set to "socket" |
||
| 27 | # category Change graph category |
||
| 28 | 121448e7 | Sledge Sulaweyo | # api use 'pre09' (pre 0.9.0) or 'current' (0.9.0+) API calls |
| 29 | f519cf3a | XciD | # |
| 30 | # Configuration example |
||
| 31 | # |
||
| 32 | fa1298bf | XciD | # [rtom_allsessions_*] |
| 33 | # user username |
||
| 34 | # env.src socket |
||
| 35 | # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket |
||
| 36 | # env.category Category |
||
| 37 | 8bfb8180 | Sledge Sulaweyo | # env.api current |
| 38 | fa1298bf | XciD | # |
| 39 | # [rtom_allsessions_*] |
||
| 40 | # user username |
||
| 41 | # env.port 5000,5001,5002,5003 |
||
| 42 | # env.category Category |
||
| 43 | 121448e7 | Sledge Sulaweyo | # env.api pre09 |
| 44 | f519cf3a | XciD | # |
| 45 | #%# family=auto |
||
| 46 | |||
| 47 | my @views = ( "default", "started", "stopped", "complete", "incomplete" ); |
||
| 48 | |||
| 49 | if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
||
| 50 | 121448e7 | Sledge Sulaweyo | exit 1; |
| 51 | f519cf3a | XciD | } |
| 52 | |||
| 53 | if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
||
| 54 | 121448e7 | Sledge Sulaweyo | my $category = $ENV{"category"} || "";
|
| 55 | print "graph_args --base 1000 -r --lower-limit 0\n"; |
||
| 56 | print "graph_title rTorrent volume\n"; |
||
| 57 | print "graph_vlabel active torrents\n"; |
||
| 58 | print "graph_category torrent ".${category}."\n";
|
||
| 59 | print "complete.label complete\n"; |
||
| 60 | print "complete.draw AREA\n"; |
||
| 61 | print "complete.info complete torrents\n"; |
||
| 62 | print "incomplete.label incomplete\n"; |
||
| 63 | print "incomplete.draw STACK\n"; |
||
| 64 | print "incomplete.info incomplete torrents\n"; |
||
| 65 | print "stopped.label stopped\n"; |
||
| 66 | print "stopped.draw LINE2\n"; |
||
| 67 | print "stopped.info stopped torrents\n"; |
||
| 68 | print "started.label started\n"; |
||
| 69 | print "started.draw LINE2\n"; |
||
| 70 | print "started.info started torrents\n"; |
||
| 71 | print "default.label total\n"; |
||
| 72 | print "default.draw LINE2\n"; |
||
| 73 | print "default.info all torrents\n"; |
||
| 74 | print "hashing.graph no\n"; |
||
| 75 | print "seeding.graph no\n"; |
||
| 76 | print "active.graph no\n"; |
||
| 77 | exit 0; |
||
| 78 | f519cf3a | XciD | } |
| 79 | |||
| 80 | use IO::Socket; |
||
| 81 | |||
| 82 | my $src = $ENV{"src"} || "";
|
||
| 83 | fa1298bf | XciD | my @sockets = split /,/, $ENV{"socket"} || "";
|
| 84 | my $ip = $ENV{"ip"} || "127.0.0.1";
|
||
| 85 | my @ports = split /,/, $ENV{"port"} || "";
|
||
| 86 | 121448e7 | Sledge Sulaweyo | my $api = $ENV{"api"} || "pre09";
|
| 87 | f519cf3a | XciD | |
| 88 | 8bfb8180 | Sledge Sulaweyo | my $pattern = qr/<value><string>([A-Z0-9]+)<\/string><\/value>/; |
| 89 | f519cf3a | XciD | |
| 90 | foreach ( @views ) {
|
||
| 91 | 121448e7 | Sledge Sulaweyo | my $num = 0; |
| 92 | my $line = ""; |
||
| 93 | if ($api =~ /pre09/) {
|
||
| 94 | $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>";
|
||
| 95 | } else {
|
||
| 96 | $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>";
|
||
| 97 | } |
||
| 98 | my $llen = length $line; |
||
| 99 | my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
||
| 100 | my $hlen = length $header; |
||
| 101 | f519cf3a | XciD | |
| 102 | 121448e7 | Sledge Sulaweyo | if ( ( defined $src ) && ( $src eq "socket" ) ) {
|
| 103 | for $socket (@sockets) |
||
| 104 | {
|
||
| 105 | socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; |
||
| 106 | connect( SOCK, sockaddr_un( $socket ) ) or die $!; |
||
| 107 | my $line = "${hlen}:${header},${line}";
|
||
| 108 | print SOCK $line; |
||
| 109 | flush SOCK; |
||
| 110 | while ( $line = <SOCK> ) {
|
||
| 111 | if ( $line =~ /$pattern/ ) {
|
||
| 112 | $num++; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | close (SOCK); |
||
| 116 | } |
||
| 117 | } else {
|
||
| 118 | for $port (@ports) |
||
| 119 | {
|
||
| 120 | socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); |
||
| 121 | connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); |
||
| 122 | my $line = "${hlen}:${header},${line}";
|
||
| 123 | print SOCK $line; |
||
| 124 | flush SOCK; |
||
| 125 | while ( $line = <SOCK> ) {
|
||
| 126 | if ( $line =~ /$pattern/ ) {
|
||
| 127 | $num++; |
||
| 128 | 8bfb8180 | Sledge Sulaweyo | } |
| 129 | 121448e7 | Sledge Sulaweyo | } |
| 130 | close (SOCK); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | print "${_}.value ${num}\n";
|
||
| 134 | f519cf3a | XciD | } |
| 135 | |||
| 136 | exit; |
