Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / transmission @ 17f78427

Historique | Voir | Annoter | Télécharger (4,68 ko)

1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
"""
4
: << =cut
5

    
6
=head1 NAME
7

    
8
transmission - Munin plugin to monitor Transmission bittorrent daemon
9

    
10
=head1 DESCRIPTION
11

    
12
This plugin implements the multigraph protocol and provides the following graphs
13
  transmission_throughput - monitor traffic volumes of Transmission torrents
14
  transmission_activity - plugin to monitor traffic speed of Transmission torrents
15

    
16
This plugin requires python and the transmissionrpc python module.
17
See http://pypi.python.org/pypi/transmissionrpc/
18

    
19
=head1 CONFIGURATION
20

    
21
    [transmission]
22
        env.host 10.0.0.1
23
        env.port 9093
24
        env.user transmission
25
        env.pass secret
26

    
27
    [transmission_*]
28
        env.host 10.0.0.1
29
        env.port 9093
30
        env.user transmission
31
        env.pass secret
32

    
33

    
34
=head1 AUTHOR
35

    
36
Thomas Léveil
37

    
38
=head1 LICENSE
39

    
40
Permission to use, copy, and modify this software with or without fee
41
is hereby granted, provided that this entire notice is included in
42
all source code copies of any software which is or includes a copy or
43
modification of this software.
44

    
45
THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
46
IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
47
REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
48
MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
49
PURPOSE.
50

    
51
=head1 CONTRIBUTE
52

    
53
find this plugin on github at http://github.com/VolatileMesh/munin-plugins
54

    
55
=head1 MAGIC MARKERS
56

    
57
 #%# family=auto contrib
58
 #%# capabilities=autoconf
59

    
60
=head1 VERSION
61

    
62
    1.1
63

    
64
=head1 CHANGELOG
65

    
66
=head2 1.0 - 2010/11/12
67

    
68
    first release
69

    
70
=head2 1.1 - 2011/05/29
71

    
72
    fix transmission error handling
73

    
74
=cut
75
"""
76
__version__ = '1.1'
77

    
78

    
79
import os, sys
80
from string import Template
81

    
82
plugin_name=list(os.path.split(sys.argv[0]))[1]
83
host = os.getenv('host','localhost')
84
port = os.getenv('port',9091)
85
user = os.getenv('user')
86
passwd = os.getenv('pass')
87

    
88

    
89
def config():
90
    conf = Template("""multigraph ${plugin_name}_throughput
91
graph_title Transmission throughput for ${host}
92
graph_vlabel bytes/${graph_period} in (-) / out (+)
93
graph_args --base 1000
94
graph_category network
95
graph_info This graph shows the throughput for Transmission torrents
96
down.label throughput
97
down.type COUNTER
98
down.draw LINE1
99
down.min 0
100
down.graph no
101
up.label sent
102
up.negative down
103
up.type COUNTER
104
up.draw LINE1
105
up.min 0
106

    
107
multigraph ${plugin_name}_activity
108
graph_title Transmission activity for ${host}
109
graph_vlabel torrents
110
graph_args --base 1000
111
graph_category network
112
graph_info This graph shows the number of Transmission torrents
113
total.label total
114
total.draw AREA
115
total.min 0
116
total.colour AFE3FF
117
active.label active
118
active.draw AREA
119
active.min 0
120
active.colour 77FF6F
121
paused.label paused
122
paused.draw LINE1
123
paused.min 0
124
paused.colour 8F8F8F
125
""")
126
    print conf.safe_substitute(plugin_name=plugin_name, host=host)
127
    sys.exit(0)
128

    
129

    
130
def autoconf():
131
    try:
132
        import transmissionrpc
133
        print('yes')
134
    except ImportError:
135
        print 'no python module \'transmissionrpc\' missing'
136

    
137

    
138

    
139
def fetch():
140
    import transmissionrpc
141

    
142
    try:
143
        client = transmissionrpc.Client(host, port=port, user=user, password=passwd)
144
    except transmissionrpc.TransmissionError, err:
145
        print err
146
        sys.exit(1)
147

    
148
    stats = client.session_stats(10)
149
    print_values_throughput(stats)
150
    print_values_activity(stats)
151

    
152

    
153
def print_values_activity(stats):
154
    print "multigraph {plugin_name}_activity".format(plugin_name=plugin_name)
155
    try:
156
        print "total.value %s" % stats.torrentCount
157
    except:
158
        print "total.value U"
159

    
160
    try:
161
        print "active.value %s" % stats.activeTorrentCount
162
    except:
163
        print "active.value U"
164

    
165
    try:
166
        print "paused.value %s" % stats.pausedTorrentCount
167
    except:
168
        print "paused.value U"
169

    
170

    
171
def print_values_throughput(stats):
172
    print "multigraph {plugin_name}_throughput".format(plugin_name=plugin_name)
173
    try:
174
        print "down.value %s" % stats.cumulative_stats['downloadedBytes']
175
    except:
176
        print "down.value U"
177

    
178
    try:
179
        print "up.value %s" % stats.cumulative_stats['uploadedBytes']
180
    except:
181
        print "up.value U"
182

    
183

    
184

    
185
def dumpstats():
186
    import transmissionrpc
187
    try:
188
        client = transmissionrpc.Client(host, port=port, user=user, password=passwd)
189
    except transmissionrpc.transmission.TransmissionError, err:
190
        print err
191
        sys.exit(1)
192
    stats = client.session_stats(10)
193
    print stats
194

    
195

    
196
if __name__ == '__main__':
197
    if len(sys.argv)>1 :
198
        if sys.argv[1]=="dumpstats" :
199
			dumpstats()
200
        elif sys.argv[1]=="config" :
201
            config()
202
        elif sys.argv[1]=="autoconf" :
203
            autoconf()
204
        elif sys.argv[1]!="":
205
            raise ValueError, "unknown parameter '%s'" % sys.argv[1]
206

    
207
fetch()
208
sys.exit(0)