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
#!/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
80
import sys
81
from string import Template
82

    
83
plugin_name = list(os.path.split(sys.argv[0]))[1]
84
host = os.getenv('host', 'localhost')
85
port = os.getenv('port', 9091)
86
user = os.getenv('user')
87
passwd = os.getenv('pass')
88
title_host = '' if host in ['localhost', '127.0.0.1', '::1'] else ' on ' + host
89

    
90

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

    
109
multigraph ${plugin_name}_activity
110
graph_title Transmission activity${title_host}
111
graph_vlabel torrents
112
graph_args --base 1000
113
graph_category network
114
graph_info This graph shows the number of Transmission torrents on ${host}
115
active.label active
116
active.draw AREA
117
active.min 0
118
active.colour COLOUR0
119
paused.label paused
120
paused.draw STACK
121
paused.min 0
122
paused.colour COLOUR8
123
""")
124
    print conf.safe_substitute(plugin_name=plugin_name, host=host, title_host=title_host)
125
    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

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

    
145
    stats = client.session_stats(10)
146
    print_values_throughput(stats)
147
    print_values_activity(stats)
148

    
149

    
150
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

    
157
    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

    
170
    try:
171
        print "up.value %s" % stats.cumulative_stats['uploadedBytes']
172
    except:
173
        print "up.value U"
174

    
175

    
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

    
187
if __name__ == '__main__':
188
    if len(sys.argv) > 1 :
189
        if sys.argv[1] == "dumpstats" :
190
            dumpstats()
191
        elif sys.argv[1] == "config" :
192
            config()
193
        elif sys.argv[1] == "autoconf" :
194
            autoconf()
195
        elif sys.argv[1] != "":
196
            raise ValueError, "unknown parameter '%s'" % sys.argv[1]
197

    
198
fetch()
199
sys.exit(0)