mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Update the Deluge plugin to handle Deluge 2.x
Version 1.0.0 of this plugin requires version 1 of Deluge. Deluge 2 was released in June 2019. This commits bumps the plugin to version 2.0.0. This plugin has three modes. The modes "bandwidth" and "states" are working equally to the previous version. The third mode, "connections", is changed. The connections mode previously printed one value: the total number of connections. That RPC call is removed in Deluge 2, and I'm instead using `get_session_status`, which delegates the call to libtorrent [1]. libtorrent is much better documented, so it's easier to work with compared to Deluge. "Number of peers" replaces the previous "number of connections", and I've added half open peers, and peers interested in download and upload slots to the same graph. [1]. https://libtorrent.org/manual-ref.html#session-statistics
This commit is contained in:
parent
0ab2cff07c
commit
13b9078f76
1 changed files with 53 additions and 33 deletions
|
@ -1,14 +1,14 @@
|
||||||
#! /usr/bin/env python2
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
"""=cut
|
"""=cut
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
deluge_ - Munin wildcard plugin to monitor Deluge torrent client
|
deluge_ - Munin wildcard plugin to monitor the Deluge torrent client
|
||||||
|
|
||||||
=head1 REQUIREMENTS
|
=head1 REQUIREMENTS
|
||||||
|
|
||||||
- Python2.5+ (Deluge itself won't work with python3)
|
- Python3+
|
||||||
- Deluge
|
- Deluge2+
|
||||||
|
|
||||||
This plugin also uses
|
This plugin also uses
|
||||||
- deluge.ui.client
|
- deluge.ui.client
|
||||||
|
@ -19,13 +19,13 @@ These modules are required by Deluge itself.
|
||||||
=head1 INSTALLATION
|
=head1 INSTALLATION
|
||||||
|
|
||||||
This plugin has 3 modes :
|
This plugin has 3 modes :
|
||||||
- connections : monitors the number of connections
|
- peers : monitors the number of peers
|
||||||
- bandwidth : monitors the bandwidth (up, up overhead, down, down overhead)
|
- bandwidth : monitors the bandwidth (up, up overhead, down, down overhead)
|
||||||
- states : monitors the torrents' states
|
- states : monitors the torrents' states
|
||||||
|
|
||||||
To use one of these modes, link the this plugin as 'deluge_<mode>'
|
To use one of these modes, link the this plugin as 'deluge_<mode>'
|
||||||
For example :
|
For example :
|
||||||
ln -s /path/to/deluge_ /etc/munin/plugins/deluge_connections
|
ln -s /path/to/deluge_ /etc/munin/plugins/deluge_peers
|
||||||
|
|
||||||
=head1 CONFIGURATION
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
@ -58,10 +58,10 @@ set the env.XDG_CONFIG_HOME if needed.
|
||||||
|
|
||||||
=head1 INTERPRETATION
|
=head1 INTERPRETATION
|
||||||
|
|
||||||
=head2 connections
|
=head2 peers
|
||||||
|
|
||||||
In the "connections" mode, this plugin shows a graph with the number of
|
In the "peers" mode, this plugin shows a graph with the number of
|
||||||
connections
|
total peers, half open peers, and peers interested in upload and download slots
|
||||||
|
|
||||||
=head2 bandwidth
|
=head2 bandwidth
|
||||||
|
|
||||||
|
@ -83,11 +83,12 @@ Downloading, Seeding, Paused, Error, Queued, Checking, Other
|
||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
1.0.0
|
2.0.0
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
||||||
Neraud (https://github.com/Neraud)
|
Neraud (https://github.com/Neraud)
|
||||||
|
kmkr (https://github.com/kmkr)
|
||||||
|
|
||||||
=head1 LICENSE
|
=head1 LICENSE
|
||||||
|
|
||||||
|
@ -105,17 +106,17 @@ import sys
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from deluge.log import setupLogger
|
from deluge.log import setup_logger
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
setupLogger()
|
setup_logger()
|
||||||
except (ImportError, NameError):
|
except (ImportError, NameError):
|
||||||
successful_import = False
|
successful_import = False
|
||||||
else:
|
else:
|
||||||
successful_import = True
|
successful_import = True
|
||||||
|
|
||||||
|
|
||||||
plugin_version = "1.0.0"
|
plugin_version = "2.0.0"
|
||||||
|
|
||||||
log = logging.getLogger("delugeStats")
|
log = logging.getLogger("delugeStats")
|
||||||
log.setLevel(logging.WARNING)
|
log.setLevel(logging.WARNING)
|
||||||
|
@ -139,7 +140,7 @@ names_for_munin = {
|
||||||
'state.Error': 'error',
|
'state.Error': 'error',
|
||||||
'state.Queued': 'queued',
|
'state.Queued': 'queued',
|
||||||
'state.Checking': 'checking',
|
'state.Checking': 'checking',
|
||||||
'state.Other': 'other'
|
'state.Other': 'other',
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent_states = ["Downloading",
|
torrent_states = ["Downloading",
|
||||||
|
@ -150,7 +151,17 @@ torrent_states = ["Downloading",
|
||||||
"Checking",
|
"Checking",
|
||||||
"Other"]
|
"Other"]
|
||||||
|
|
||||||
modes = ["bandwidth", "connections", "states"]
|
modes = ["bandwidth", "peers", "states"]
|
||||||
|
|
||||||
|
connection_keys = [
|
||||||
|
{ 'id': 'peer.num_peers_connected', 'label': 'Total' },
|
||||||
|
{ 'id': 'peer.num_peers_half_open', 'label': 'Half open' },
|
||||||
|
{ 'id': 'peer.num_peers_up_interested', 'label': 'Interested (upload)' },
|
||||||
|
{ 'id': 'peer.num_peers_down_interested', 'label': 'Interested (download)' }
|
||||||
|
]
|
||||||
|
|
||||||
|
def for_munin(value):
|
||||||
|
return value.replace('.', '').replace('_', '')
|
||||||
|
|
||||||
|
|
||||||
class StatClient:
|
class StatClient:
|
||||||
|
@ -182,15 +193,19 @@ class StatClient:
|
||||||
errbackArgs=("Connection failed: check settings and try again."))
|
errbackArgs=("Connection failed: check settings and try again."))
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
def on_connect_success(self, result):
|
def on_connect_success(self, result):
|
||||||
log.debug("Connection was successful")
|
log.debug("Connection was successful")
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
||||||
if self.mode == "connections":
|
if self.mode == "peers":
|
||||||
log.debug("Calling get_num_connections")
|
log.debug("Calling get_session_status")
|
||||||
client.core.get_num_connections().addCallbacks(
|
keys = []
|
||||||
self.on_num_connections,
|
for connection_key in connection_keys:
|
||||||
self.end_session, errbackArgs=("get_num_connections failed"))
|
keys.append(connection_key['id'])
|
||||||
|
client.core.get_session_status(keys=keys).addCallbacks(
|
||||||
|
self.on_peer_session_status,
|
||||||
|
self.end_session, errbackArgs=("get_session_status failed"))
|
||||||
elif self.mode == "bandwidth":
|
elif self.mode == "bandwidth":
|
||||||
log.debug("Calling get_session_status")
|
log.debug("Calling get_session_status")
|
||||||
interesting_status = [
|
interesting_status = [
|
||||||
|
@ -206,11 +221,17 @@ class StatClient:
|
||||||
self.on_session_state,
|
self.on_session_state,
|
||||||
self.end_session,
|
self.end_session,
|
||||||
errbackArgs=("get_session_state failed"))
|
errbackArgs=("get_session_state failed"))
|
||||||
|
else:
|
||||||
|
log.error("Unknown mode '%s'", mode)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def on_num_connections(self, num_connections):
|
def on_peer_session_status(self, result):
|
||||||
log.debug("Got num_connections from the daemon : %s", num_connections)
|
log.debug("Got result from the daemon : %s", result)
|
||||||
print("{0}.value {1}".format(
|
for connection_key in connection_keys:
|
||||||
names_for_munin["numConnections"], num_connections))
|
print(
|
||||||
|
f"{for_munin(connection_key['id'])}.value "
|
||||||
|
f"{result[connection_key['id']]}"
|
||||||
|
)
|
||||||
self.end_session("Done")
|
self.end_session("Done")
|
||||||
|
|
||||||
def on_bandwidth(self, values):
|
def on_bandwidth(self, values):
|
||||||
|
@ -277,7 +298,7 @@ class StatClient:
|
||||||
|
|
||||||
def get_mode():
|
def get_mode():
|
||||||
script_name = os.path.basename(sys.argv[0])
|
script_name = os.path.basename(sys.argv[0])
|
||||||
mode = script_name[string.rindex(script_name, '_') + 1:]
|
mode = script_name[script_name.rindex('_') + 1:]
|
||||||
|
|
||||||
log.debug("Mode : %s", mode)
|
log.debug("Mode : %s", mode)
|
||||||
|
|
||||||
|
@ -290,18 +311,17 @@ def get_mode():
|
||||||
|
|
||||||
|
|
||||||
def print_config(mode):
|
def print_config(mode):
|
||||||
if mode == "connections":
|
if mode == "peers":
|
||||||
print("graph_title Number of connections")
|
print("graph_title Number of peers")
|
||||||
print("graph_args --base 1000 -l 0")
|
print("graph_args --base 1000 -l 0")
|
||||||
print("graph_vlabel connections")
|
print("graph_vlabel peers")
|
||||||
print("graph_scale yes")
|
print("graph_scale yes")
|
||||||
print("graph_category filetransfer")
|
print("graph_category filetransfer")
|
||||||
print(
|
print(
|
||||||
"graph_info This graph shows the number of connections used by Deluge Torrent")
|
"graph_info This graph shows the number of peers for the Deluge Torrent client")
|
||||||
print(names_for_munin["numConnections"] + ".label connections")
|
for connection_key in connection_keys:
|
||||||
print(names_for_munin["numConnections"] + ".min 0")
|
print(f"{for_munin(connection_key['id'])}.label {connection_key['label']}")
|
||||||
print(names_for_munin["numConnections"]
|
print(f"{for_munin(connection_key['id'])}.min 0")
|
||||||
+ ".info The number of connections used by Deluge Torrent")
|
|
||||||
elif mode == "bandwidth":
|
elif mode == "bandwidth":
|
||||||
print("graph_title Bandwidth usage")
|
print("graph_title Bandwidth usage")
|
||||||
print("graph_order payloadDownloadRate overheadDownloadRate payloadUploadRate "
|
print("graph_order payloadDownloadRate overheadDownloadRate payloadUploadRate "
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue