Projet

Général

Profil

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

root / plugins / network / transmission @ 92483a04

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

1 2c16d33c Morgan Soulard
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3 b75c8e25 Thomas Leveil
"""
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 17f78427 Lars Kruse
This plugin requires python and the transmissionrpc python module.
17 1cda52e5 Thomas L?veil
See http://pypi.python.org/pypi/transmissionrpc/
18
19 b75c8e25 Thomas Leveil
=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 e5e2ae23 Kenyon Ralph
Thomas Léveil
37 b75c8e25 Thomas Leveil
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 1cda52e5 Thomas L?veil
find this plugin on github at http://github.com/VolatileMesh/munin-plugins
54 b75c8e25 Thomas Leveil
55
=head1 MAGIC MARKERS
56
57
 #%# family=auto contrib
58
 #%# capabilities=autoconf
59
60
=head1 VERSION
61
62 078fb31f Thomas L?veil
    1.1
63 b75c8e25 Thomas Leveil
64
=head1 CHANGELOG
65
66
=head2 1.0 - 2010/11/12
67 17f78427 Lars Kruse
68 b75c8e25 Thomas Leveil
    first release
69 078fb31f Thomas L?veil
70
=head2 1.1 - 2011/05/29
71 17f78427 Lars Kruse
72 078fb31f Thomas L?veil
    fix transmission error handling
73 17f78427 Lars Kruse
74 b75c8e25 Thomas Leveil
=cut
75
"""
76 078fb31f Thomas L?veil
__version__ = '1.1'
77 b75c8e25 Thomas Leveil
78
79 92483a04 Olivier Mehani
import os
80
import sys
81 b75c8e25 Thomas Leveil
from string import Template
82
83 92483a04 Olivier Mehani
plugin_name = list(os.path.split(sys.argv[0]))[1]
84
host = os.getenv('host', 'localhost')
85
port = os.getenv('port', 9091)
86 b75c8e25 Thomas Leveil
user = os.getenv('user')
87
passwd = os.getenv('pass')
88 897de1bb Olivier Mehani
title_host = '' if host in ['localhost', '127.0.0.1', '::1'] else ' on ' + host
89 b75c8e25 Thomas Leveil
90
91
def config():
92
    conf = Template("""multigraph ${plugin_name}_throughput
93 897de1bb Olivier Mehani
graph_title Transmission throughput${title_host}
94 b75c8e25 Thomas Leveil
graph_vlabel bytes/${graph_period} in (-) / out (+)
95
graph_args --base 1000
96
graph_category network
97 e254623b Olivier Mehani
graph_info This graph shows the throughput for Transmission torrents on ${host}
98 b75c8e25 Thomas Leveil
down.label throughput
99
down.type COUNTER
100 6ca9f65a Olivier Mehani
down.draw AREA
101 b75c8e25 Thomas Leveil
down.min 0
102 1cda52e5 Thomas L?veil
down.graph no
103 6ca9f65a Olivier Mehani
up.label Bps
104 1cda52e5 Thomas L?veil
up.negative down
105
up.type COUNTER
106 6ca9f65a Olivier Mehani
up.draw AREA
107 1cda52e5 Thomas L?veil
up.min 0
108 b75c8e25 Thomas Leveil
109
multigraph ${plugin_name}_activity
110 897de1bb Olivier Mehani
graph_title Transmission activity${title_host}
111 b75c8e25 Thomas Leveil
graph_vlabel torrents
112
graph_args --base 1000
113
graph_category network
114 e254623b Olivier Mehani
graph_info This graph shows the number of Transmission torrents on ${host}
115 b75c8e25 Thomas Leveil
active.label active
116
active.draw AREA
117
active.min 0
118 e254623b Olivier Mehani
active.colour COLOUR0
119 b75c8e25 Thomas Leveil
paused.label paused
120 6ca9f65a Olivier Mehani
paused.draw STACK
121 b75c8e25 Thomas Leveil
paused.min 0
122 e254623b Olivier Mehani
paused.colour COLOUR8
123 b75c8e25 Thomas Leveil
""")
124 897de1bb Olivier Mehani
    print conf.safe_substitute(plugin_name=plugin_name, host=host, title_host=title_host)
125 b75c8e25 Thomas Leveil
    sys.exit(0)
126
127
128
def autoconf():
129
    try:
130
        import transmissionrpc
131
        print('yes')
132
    except ImportError:
133
        print 'no python module \'transmissionrpc\' missing'
134
135
136
def fetch():
137
    import transmissionrpc
138 17f78427 Lars Kruse
139 b75c8e25 Thomas Leveil
    try:
140
        client = transmissionrpc.Client(host, port=port, user=user, password=passwd)
141 078fb31f Thomas L?veil
    except transmissionrpc.TransmissionError, err:
142 b75c8e25 Thomas Leveil
        print err
143
        sys.exit(1)
144
145
    stats = client.session_stats(10)
146
    print_values_throughput(stats)
147
    print_values_activity(stats)
148 17f78427 Lars Kruse
149
150 b75c8e25 Thomas Leveil
def print_values_activity(stats):
151
    print "multigraph {plugin_name}_activity".format(plugin_name=plugin_name)
152
    try:
153
        print "active.value %s" % stats.activeTorrentCount
154
    except:
155
        print "active.value U"
156 17f78427 Lars Kruse
157 b75c8e25 Thomas Leveil
    try:
158
        print "paused.value %s" % stats.pausedTorrentCount
159
    except:
160
        print "paused.value U"
161
162
163
def print_values_throughput(stats):
164
    print "multigraph {plugin_name}_throughput".format(plugin_name=plugin_name)
165
    try:
166
        print "down.value %s" % stats.cumulative_stats['downloadedBytes']
167
    except:
168
        print "down.value U"
169 17f78427 Lars Kruse
170 b75c8e25 Thomas Leveil
    try:
171
        print "up.value %s" % stats.cumulative_stats['uploadedBytes']
172
    except:
173
        print "up.value U"
174 17f78427 Lars Kruse
175 b75c8e25 Thomas Leveil
176
def dumpstats():
177
    import transmissionrpc
178
    try:
179
        client = transmissionrpc.Client(host, port=port, user=user, password=passwd)
180
    except transmissionrpc.transmission.TransmissionError, err:
181
        print err
182
        sys.exit(1)
183
    stats = client.session_stats(10)
184
    print stats
185
186 17f78427 Lars Kruse
187 b75c8e25 Thomas Leveil
if __name__ == '__main__':
188 92483a04 Olivier Mehani
    if len(sys.argv) > 1 :
189
        if sys.argv[1] == "dumpstats" :
190
            dumpstats()
191
        elif sys.argv[1] == "config" :
192 b75c8e25 Thomas Leveil
            config()
193 92483a04 Olivier Mehani
        elif sys.argv[1] == "autoconf" :
194 b75c8e25 Thomas Leveil
            autoconf()
195 92483a04 Olivier Mehani
        elif sys.argv[1] != "":
196 b75c8e25 Thomas Leveil
            raise ValueError, "unknown parameter '%s'" % sys.argv[1]
197 d5be273c Paul Fariello
198
fetch()
199
sys.exit(0)