root / plugins / rtorrent / rtom_allsessions_vol @ 8589c6df
Historique | Voir | Annoter | Télécharger (3,78 ko)
| 1 |
#!/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 |
# check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further information |
| 7 |
# |
| 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 |
# config required |
| 21 |
# |
| 22 |
# |
| 23 |
# Configurable variables |
| 24 |
# |
| 25 |
# 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 |
# |
| 29 |
# Configuration example |
| 30 |
# |
| 31 |
# [rtom_allsessions_*] |
| 32 |
# user username |
| 33 |
# env.src socket |
| 34 |
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket |
| 35 |
# env.category Category |
| 36 |
# |
| 37 |
# [rtom_allsessions_*] |
| 38 |
# user username |
| 39 |
# env.port 5000,5001,5002,5003 |
| 40 |
# env.category Category |
| 41 |
# |
| 42 |
#%# family=auto |
| 43 |
|
| 44 |
my @views = ( "default", "started", "stopped", "complete", "incomplete" ); |
| 45 |
|
| 46 |
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
| 47 |
exit 1; |
| 48 |
} |
| 49 |
|
| 50 |
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
| 51 |
my $category = $ENV{"category"} || "";
|
| 52 |
print "graph_args --base 1000 -r --lower-limit 0\n"; |
| 53 |
print "graph_title rTorrent volume\n"; |
| 54 |
print "graph_vlabel active torrents\n"; |
| 55 |
print "graph_category filetransfer".${category}."\n";
|
| 56 |
print "complete.label complete\n"; |
| 57 |
print "complete.draw AREA\n"; |
| 58 |
print "complete.info complete torrents\n"; |
| 59 |
print "incomplete.label incomplete\n"; |
| 60 |
print "incomplete.draw STACK\n"; |
| 61 |
print "incomplete.info incomplete torrents\n"; |
| 62 |
print "stopped.label stopped\n"; |
| 63 |
print "stopped.draw LINE2\n"; |
| 64 |
print "stopped.info stopped torrents\n"; |
| 65 |
print "started.label started\n"; |
| 66 |
print "started.draw LINE2\n"; |
| 67 |
print "started.info started torrents\n"; |
| 68 |
print "default.label total\n"; |
| 69 |
print "default.draw LINE2\n"; |
| 70 |
print "default.info all torrents\n"; |
| 71 |
print "hashing.graph no\n"; |
| 72 |
print "seeding.graph no\n"; |
| 73 |
print "active.graph no\n"; |
| 74 |
exit 0; |
| 75 |
} |
| 76 |
|
| 77 |
use IO::Socket; |
| 78 |
|
| 79 |
my $src = $ENV{"src"} || "";
|
| 80 |
my @sockets = split /,/, $ENV{"socket"} || "";
|
| 81 |
my $ip = $ENV{"ip"} || "127.0.0.1";
|
| 82 |
my @ports = split /,/, $ENV{"port"} || "";
|
| 83 |
|
| 84 |
my $pattern = qr/<value><string>([A-Z0-9]+)<\/string><\/value>/; |
| 85 |
|
| 86 |
foreach ( @views ) {
|
| 87 |
my $num = 0; |
| 88 |
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>";
|
| 89 |
my $llen = length $line; |
| 90 |
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
| 91 |
my $hlen = length $header; |
| 92 |
|
| 93 |
if ( ( defined $src ) && ( $src eq "socket" ) ) {
|
| 94 |
for $socket (@sockets) |
| 95 |
{
|
| 96 |
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; |
| 97 |
connect( SOCK, sockaddr_un( $socket ) ) or die $!; |
| 98 |
my $line = "${hlen}:${header},${line}";
|
| 99 |
print SOCK $line; |
| 100 |
flush SOCK; |
| 101 |
while ( $line = <SOCK> ) {
|
| 102 |
if ( $line =~ /$pattern/ ) {
|
| 103 |
$num++; |
| 104 |
} |
| 105 |
} |
| 106 |
close (SOCK); |
| 107 |
} |
| 108 |
} else {
|
| 109 |
for $port (@ports) |
| 110 |
{
|
| 111 |
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); |
| 112 |
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); |
| 113 |
my $line = "${hlen}:${header},${line}";
|
| 114 |
print SOCK $line; |
| 115 |
flush SOCK; |
| 116 |
while ( $line = <SOCK> ) {
|
| 117 |
if ( $line =~ /$pattern/ ) {
|
| 118 |
$num++; |
| 119 |
} |
| 120 |
} |
| 121 |
close (SOCK); |
| 122 |
} |
| 123 |
} |
| 124 |
print "${_}.value ${num}\n";
|
| 125 |
} |
| 126 |
|
| 127 |
exit; |
