Projet

Général

Profil

Révision acba1189

IDacba11893782be0883ede6a5b4154c052c0689a2
Parent 71a872cf
Enfant f519cf3a

Ajouté par XciD il y a presque 12 ans

Create rtom_allsessions_spdd

For all sessions

Voir les différences:

plugins/rtorrent/rtom_allsessions_spdd
1
#!/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
#       diff            "yes" for using bps for upload and Bps for download, or anything else for using Bps for both
39
#
40
#
41
# Configuration example
42
#
43
#       [rtom_spdd]
44
#       user username
45
#       env.src socket
46
#       env.socket /home/user/torrent/.socket/rpc.socket,/home/user2/torrent/.socket/rpc2.socket
47
#       env.category Sometext
48
#
49
#
50
#%# family=auto
51

  
52

  
53
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
54
        exit 1;
55
}
56

  
57
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
58
        my $diff = $ENV{"diff"} || "";
59
        my $category = $ENV{"category"} || "";
60
        print "graph_order down up\n";
61
        print "graph_title rTorrent speeds\n";
62
        print "graph_args --base 1024\n";
63
        print "graph_vlabel Bytes per \${graph_period}\n";
64
        print "graph_category rTorrent ".${category}."\n";
65
        print "down.label Download B/s\n";
66
        print "down.info Download speed in Bytes per seconds\n";
67
        print "down.type DERIVE\n";
68
        print "down.min 0\n";
69
        print "down.draw AREA\n";
70
        if ( ( defined $diff ) && ( $diff eq "yes" ) ) {
71
                print "up.label Upload b/s\n";
72
                print "up.info Upload speed in bits per seconds\n";
73
                print "up.cdef up,8,*\n";
74
        } else {
75
                print "up.label Upload B/s\n";
76
                print "up.info Upload speed in Bytes per seconds\n";
77
        }
78
        print "up.type DERIVE\n";
79
        print "up.min 0\n";
80
        print "up.draw LINE2\n";
81
        exit 0;
82
}
83

  
84
use IO::Socket;
85
my @sockets = split /,/, $ENV{"socket"} || "";
86
my $src         = $ENV{"src"} || "";
87

  
88
my $up = -1;
89
my $down = -1;
90

  
91
for $socket (@sockets)
92
{
93
        my $pattern     = qr/<value><(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
94
        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>";
95
        my $llen        = length $line;
96
        my $header      = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
97
        my $hlen        = length $header;
98
        $line           = "${hlen}:${header},${line}";
99
        if ( ( defined $src ) && ( $src eq "socket" ) ) {
100
                socket( SOCK, PF_UNIX, SOCK_STREAM, 0 );
101
                connect( SOCK, sockaddr_un( $socket ) );
102
        }
103

  
104
        print SOCK $line;
105
        flush SOCK;
106
        my $up_tmp = -1;
107
        my $down_tmp = -1;
108
        while (( $up_tmp == -1 ) && ( $line = <SOCK> ) ) {
109
                if ( $line =~ /$pattern/ ) {
110
                        $up_tmp = $2;
111
                }
112
        }
113
        while (( $down_tmp == -1 ) && ( $line = <SOCK> ) ) {
114
                if ( $line =~ /$pattern/ ) {
115
                        $down_tmp = $2;
116
                }
117
        }
118
        close (SOCK);
119
        $up = $up + $up_tmp;
120
        $down = $down + $down_tmp;
121
}
122
print "up.value ${up}\ndown.value ${down}\n";
123

  
124
exit;

Formats disponibles : Unified diff