root / plugins / rtorrent / rtom_spdd @ 81db94e2
Historique | Voir | Annoter | Télécharger (5,08 ko)
| 1 | 16434a44 | Gabor Hudiczius | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # |
||
| 3 | # xmlrpc based munin plugin for monitoring rtorrent's upload/download speed |
||
| 4 | # prerequisites: |
||
| 5 | # - rtorrent 0.7.5 or newer compiled with --with-xmlrpc-c |
||
| 6 | # check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further informations |
||
| 7 | # |
||
| 8 | # written by Gabor Hudiczius |
||
| 9 | # web: http://projects.cyla.homeip.net/rtwi/wiki/rTorrentOMeter |
||
| 10 | # email: ghudiczius@gmail.com |
||
| 11 | # |
||
| 12 | # 0.0.0 - 071218 |
||
| 13 | # initial release |
||
| 14 | # |
||
| 15 | # 0.0.1 - 071220 |
||
| 16 | # minor textbugs fixed |
||
| 17 | # |
||
| 18 | # 0.1.0d - 080519 |
||
| 19 | # full rewrite in perl |
||
| 20 | # support for scgi_port and scgi_local |
||
| 21 | # configurable via munin env variables |
||
| 22 | # different ul/dl scale can be set for asymmetric connections |
||
| 23 | # using get_(up|down)_total, and derive |
||
| 24 | # |
||
| 25 | # 0.2.0 - 080619 |
||
| 26 | # upload and download limit displayed on the graph |
||
| 27 | # |
||
| 28 | # |
||
| 29 | # Parameters: |
||
| 30 | # |
||
| 31 | # config required |
||
| 32 | # |
||
| 33 | # |
||
| 34 | # Configurable variables |
||
| 35 | # |
||
| 36 | # src "socket" when using scgi_socket, or anything else when using scgi_port |
||
| 37 | # socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is set to "socket" |
||
| 38 | # ip rTorrent's ip address - using scgi_port - needed, when "src" is NOT set to "socket" |
||
| 39 | # port rTorrent's scgi port (scgi_port) - using scgi_port - needed, when "src" is NOT set to "socket" |
||
| 40 | e15ed8cb | XciD | # category Change graph category |
| 41 | 16434a44 | Gabor Hudiczius | # diff "yes" for using bps for upload and Bps for download, or anything else for using Bps for both |
| 42 | # |
||
| 43 | # |
||
| 44 | # Configuration example |
||
| 45 | # |
||
| 46 | # [rtom_spdd] |
||
| 47 | # user username |
||
| 48 | # env.src socket |
||
| 49 | # env.socket /home/user/torrent/.socket/rpc.socket |
||
| 50 | e15ed8cb | XciD | # env.category Sometext |
| 51 | 16434a44 | Gabor Hudiczius | # |
| 52 | # [rtom_spdd] |
||
| 53 | # env.ip 127.0.0.1 |
||
| 54 | # env.port 5000 |
||
| 55 | # |
||
| 56 | # |
||
| 57 | #%# family=auto |
||
| 58 | |||
| 59 | |||
| 60 | if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
||
| 61 | exit 1; |
||
| 62 | } |
||
| 63 | |||
| 64 | if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
||
| 65 | my $diff = $ENV{"diff"} || "";
|
||
| 66 | e15ed8cb | XciD | my $category = $ENV{"category"} || "";
|
| 67 | 16434a44 | Gabor Hudiczius | print "graph_order down up\n"; |
| 68 | print "graph_title rTorrent speeds\n"; |
||
| 69 | print "graph_args --base 1024\n"; |
||
| 70 | print "graph_vlabel Bytes per \${graph_period}\n";
|
||
| 71 | 81db94e2 | Gabriele Pohl | print "graph_category torrent ".${category}."\n";
|
| 72 | 16434a44 | Gabor Hudiczius | print "down.label Download B/s\n"; |
| 73 | print "down.info Download speed in Bytes per seconds\n"; |
||
| 74 | print "down.type DERIVE\n"; |
||
| 75 | print "down.min 0\n"; |
||
| 76 | print "down.draw AREA\n"; |
||
| 77 | if ( ( defined $diff ) && ( $diff eq "yes" ) ) {
|
||
| 78 | print "up.label Upload b/s\n"; |
||
| 79 | print "up.info Upload speed in bits per seconds\n"; |
||
| 80 | print "up.cdef up,8,*\n"; |
||
| 81 | } else {
|
||
| 82 | print "up.label Upload B/s\n"; |
||
| 83 | print "up.info Upload speed in Bytes per seconds\n"; |
||
| 84 | } |
||
| 85 | print "up.type DERIVE\n"; |
||
| 86 | print "up.min 0\n"; |
||
| 87 | print "up.draw LINE2\n"; |
||
| 88 | print "downrate.label Download limit B/s\n"; |
||
| 89 | print "downrate.info Download limit in Bytes per seconds\n"; |
||
| 90 | print "downrate.draw LINE2\n"; |
||
| 91 | if ( ( defined $diff ) && ( $diff eq "yes" ) ) {
|
||
| 92 | print "uprate.label Upload limit b/s\n"; |
||
| 93 | print "uprate.info Upload limit in bits per seconds\n"; |
||
| 94 | print "uprate.cdef uprate,8,*\n"; |
||
| 95 | } else {
|
||
| 96 | print "uprate.label Upload limit B/s\n"; |
||
| 97 | print "uprate.info Upload limit in Bytes per seconds\n"; |
||
| 98 | } |
||
| 99 | print "uprate.draw LINE2\n"; |
||
| 100 | exit 0; |
||
| 101 | } |
||
| 102 | |||
| 103 | use IO::Socket; |
||
| 104 | |||
| 105 | my $src = $ENV{"src"} || "";
|
||
| 106 | my $ip = $ENV{"ip"} || "127.0.0.1";
|
||
| 107 | my $port = $ENV{"port"} || "5000";
|
||
| 108 | my $socket = $ENV{"socket"} || "";
|
||
| 109 | |||
| 110 | my $pattern = qr/<value><(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
|
||
| 111 | |||
| 112 | my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>system.multicall</methodName><params><param><value><array><data><value><struct><member><name>methodName</name><value><string>get_up_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_down_total</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_upload_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value><value><struct><member><name>methodName</name><value><string>get_download_rate</string></value></member><member><name>params</name><value><array><data/></array></value></member></struct></value></data></array></value></param></params></methodCall>"; |
||
| 113 | my $llen = length $line; |
||
| 114 | my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
||
| 115 | my $hlen = length $header; |
||
| 116 | $line = "${hlen}:${header},${line}";
|
||
| 117 | |||
| 118 | if ( ( defined $src ) && ( $src eq "socket" ) ) {
|
||
| 119 | socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ); |
||
| 120 | connect( SOCK, sockaddr_un( $socket ) ); |
||
| 121 | } else {
|
||
| 122 | socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); |
||
| 123 | connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); |
||
| 124 | } |
||
| 125 | |||
| 126 | print SOCK $line; |
||
| 127 | flush SOCK; |
||
| 128 | |||
| 129 | my $up = -1; |
||
| 130 | my $down = -1; |
||
| 131 | my $uprate = -1; |
||
| 132 | my $downrate = -1; |
||
| 133 | while ( ( $up == -1 ) && ( $line = <SOCK> ) ) {
|
||
| 134 | if ( $line =~ /$pattern/ ) {
|
||
| 135 | $up = $2; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | while ( ( $down == -1 ) && ( $line = <SOCK> ) ) {
|
||
| 139 | if ( $line =~ /$pattern/ ) {
|
||
| 140 | $down = $2; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | while ( ( $uprate == -1 ) && ( $line = <SOCK> ) ) {
|
||
| 144 | if ( $line =~ /$pattern/ ) {
|
||
| 145 | $uprate = $2; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | while ( ( $downrate == -1 ) && ( $line = <SOCK> ) ) {
|
||
| 149 | if ( $line =~ /$pattern/ ) {
|
||
| 150 | $downrate = $2; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | close (SOCK); |
||
| 154 | |||
| 155 | print "up.value ${up}\ndown.value ${down}\nuprate.value ${uprate}\ndownrate.value ${downrate}\n";
|
||
| 156 | |||
| 157 | exit; |
