root / plugins / rtorrent / rtom_allsessions_mem @ 791e47a3
Historique | Voir | Annoter | Télécharger (3,66 ko)
| 1 | 4aae9a41 | XciD | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # |
||
| 3 | # xmlrpc based munin plugin for monitoring rtorrent's memory usage |
||
| 4 | # prerequisites: |
||
| 5 | # - rtorrent 0.7.5 or newer compiled with --with-xmlrpc-c |
||
| 6 | 8589c6df | klemens | # check http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide for further information |
| 7 | 4aae9a41 | 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 | # 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 | 80dcbf72 | XciD | # ip rTorrent's ip address - using scgi_port - needed, when "src" is NOT set to "socket" |
| 28 | # port rTorrent's scgi port (scgi_port) - using scgi_port - needed, when "src" is NOT set to "socket" |
||
| 29 | 4aae9a41 | XciD | # category Change graph category |
| 30 | # |
||
| 31 | # Configuration example |
||
| 32 | # |
||
| 33 | 80dcbf72 | XciD | # [rtom_allsessions_*] |
| 34 | 4aae9a41 | XciD | # user username |
| 35 | # env.src socket |
||
| 36 | # env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket |
||
| 37 | # env.category Category |
||
| 38 | # |
||
| 39 | 80dcbf72 | XciD | # [rtom_allsessions_*] |
| 40 | # user username |
||
| 41 | # env.port 5000,5001,5002,5003 |
||
| 42 | # env.category Category |
||
| 43 | # |
||
| 44 | 4aae9a41 | XciD | #%# family=auto |
| 45 | |||
| 46 | |||
| 47 | if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
||
| 48 | exit 1; |
||
| 49 | } |
||
| 50 | |||
| 51 | if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
||
| 52 | my $category = $ENV{"category"} || "";
|
||
| 53 | print "graph_title rTorrent memory usage\n"; |
||
| 54 | print "graph_args --base 1024 --lower-limit 0\n"; |
||
| 55 | print "graph_vlabel Bytes\n"; |
||
| 56 | 4b400a73 | dipohl | print "graph_category filetransfer".${category}."\n";
|
| 57 | 4aae9a41 | XciD | print "mem.label Memory usage\n"; |
| 58 | 81db94e2 | Gabriele Pohl | print "mem.info Memory usage of rTorrent\n"; |
| 59 | 4aae9a41 | XciD | print "mem.type GAUGE\n"; |
| 60 | print "mem.draw LINE2\n"; |
||
| 61 | exit 0; |
||
| 62 | } |
||
| 63 | |||
| 64 | use IO::Socket; |
||
| 65 | my $src = $ENV{"src"} || "";
|
||
| 66 | 80dcbf72 | XciD | my @sockets = split /,/, $ENV{"socket"} || "";
|
| 67 | my $ip = $ENV{"ip"} || "127.0.0.1";
|
||
| 68 | my @ports = split /,/, $ENV{"port"} || "";
|
||
| 69 | 4aae9a41 | XciD | |
| 70 | 80dcbf72 | XciD | my $mem = 0; |
| 71 | 4aae9a41 | XciD | my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; |
| 72 | my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_memory_usage</methodName></methodCall>"; |
||
| 73 | my $llen = length $line; |
||
| 74 | my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
||
| 75 | my $hlen = length $header; |
||
| 76 | |||
| 77 | 80dcbf72 | XciD | if ( ( defined $src ) && ( $src eq "socket" ) ) {
|
| 78 | for $socket (@sockets) |
||
| 79 | {
|
||
| 80 | 4aae9a41 | XciD | socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; |
| 81 | connect( SOCK, sockaddr_un( $socket ) ) or die $!; |
||
| 82 | 80dcbf72 | XciD | my $line = "${hlen}:${header},${line}";
|
| 83 | print SOCK $line; |
||
| 84 | flush SOCK; |
||
| 85 | while ( $line = <SOCK> ) {
|
||
| 86 | if ( $line =~ /$pattern/ ) {
|
||
| 87 | $mem = $mem + $2; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | close (SOCK); |
||
| 91 | } |
||
| 92 | } else {
|
||
| 93 | for $port (@ports) |
||
| 94 | {
|
||
| 95 | socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); |
||
| 96 | connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); |
||
| 97 | my $line = "${hlen}:${header},${line}";
|
||
| 98 | print SOCK $line; |
||
| 99 | flush SOCK; |
||
| 100 | while ( $line = <SOCK> ) {
|
||
| 101 | if ( $line =~ /$pattern/ ) {
|
||
| 102 | $mem = $mem + $2; |
||
| 103 | } |
||
| 104 | 4aae9a41 | XciD | } |
| 105 | 80dcbf72 | XciD | close (SOCK); |
| 106 | 4aae9a41 | XciD | } |
| 107 | } |
||
| 108 | |||
| 109 | print "mem.value ${mem}\n";
|
||
| 110 | |||
| 111 | exit; |
