mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 18:38:30 +00:00
Improve code style
This commit is contained in:
parent
5fd233c510
commit
1c0739641f
1 changed files with 24 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python2
|
||||||
#
|
#
|
||||||
# Munin Wildcard Plugin for Deluge torrent client
|
# Munin Wildcard Plugin for Deluge torrent client
|
||||||
#
|
#
|
||||||
|
@ -51,6 +51,8 @@ import os
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
|
|
||||||
|
|
||||||
setupLogger()
|
setupLogger()
|
||||||
|
|
||||||
plugin_version = "1.0.0"
|
plugin_version = "1.0.0"
|
||||||
|
@ -147,14 +149,14 @@ class StatClient:
|
||||||
|
|
||||||
def on_num_connections(self, num_connections):
|
def on_num_connections(self, num_connections):
|
||||||
log.debug("Got num_connections from the daemon : {0}".format(
|
log.debug("Got num_connections from the daemon : {0}".format(
|
||||||
str(num_connections)))
|
num_connections))
|
||||||
print "{0}.value {1}".format(
|
print("{0}.value {1}".format(
|
||||||
names_for_munin["numConnections"], num_connections)
|
names_for_munin["numConnections"], num_connections))
|
||||||
self.end_session("Done")
|
self.end_session("Done")
|
||||||
|
|
||||||
def on_bandwidth(self, values):
|
def on_bandwidth(self, values):
|
||||||
log.debug(
|
log.debug(
|
||||||
"Got bandwidth info from the daemon : {0}".format(str(values)))
|
"Got bandwidth info from the daemon : {0}".format(values))
|
||||||
|
|
||||||
download_rate = values['download_rate']
|
download_rate = values['download_rate']
|
||||||
payload_download_rate = values['payload_download_rate']
|
payload_download_rate = values['payload_download_rate']
|
||||||
|
@ -163,15 +165,14 @@ class StatClient:
|
||||||
payload_upload_rate = values['payload_upload_rate']
|
payload_upload_rate = values['payload_upload_rate']
|
||||||
overhead_upload_rate = upload_rate - payload_upload_rate
|
overhead_upload_rate = upload_rate - payload_upload_rate
|
||||||
|
|
||||||
print "{0}.value {1}".format(
|
print("{0}.value {1}".format(
|
||||||
names_for_munin["payloadDownloadRate"], payload_download_rate)
|
names_for_munin["payloadDownloadRate"], payload_download_rate))
|
||||||
print "{0}.value {1}".format(
|
print("{0}.value {1}".format(
|
||||||
names_for_munin["overheadDownloadRate"], overhead_download_rate)
|
names_for_munin["overheadDownloadRate"], overhead_download_rate))
|
||||||
print "{0}.value {1}".format(
|
print("{0}.value {1}".format(
|
||||||
names_for_munin["payloadUploadRate"], payload_upload_rate)
|
names_for_munin["payloadUploadRate"], payload_upload_rate))
|
||||||
print "{0}.value {1}".format(
|
print("{0}.value {1}".format(
|
||||||
names_for_munin["overheadUploadRate"], overhead_upload_rate)
|
names_for_munin["overheadUploadRate"], overhead_upload_rate))
|
||||||
|
|
||||||
self.end_session("Done")
|
self.end_session("Done")
|
||||||
|
|
||||||
def on_session_state(self, torrent_ids):
|
def on_session_state(self, torrent_ids):
|
||||||
|
@ -210,24 +211,24 @@ class StatClient:
|
||||||
self.states[state] = self.states[state] + 1
|
self.states[state] = self.states[state] + 1
|
||||||
|
|
||||||
def on_all_torrent_info_fetched(self, res):
|
def on_all_torrent_info_fetched(self, res):
|
||||||
log.debug("on_all_torrent_info_fetched : {0}".format(str(self.states)))
|
log.debug("on_all_torrent_info_fetched : {0}".format(self.states))
|
||||||
|
|
||||||
for state in self.states:
|
for state in self.states:
|
||||||
print "{0}.value {1}".format(
|
print("{0}.value {1}".format(
|
||||||
names_for_munin["state." + state], self.states[state])
|
names_for_munin["state." + state], self.states[state]))
|
||||||
|
|
||||||
self.end_session("Done")
|
self.end_session("Done")
|
||||||
|
|
||||||
|
|
||||||
def get_mode():
|
def get_mode():
|
||||||
script_name = list(os.path.split(sys.argv[0]))[1]
|
script_name = os.path.basename(sys.argv[0])
|
||||||
mode = script_name[string.rindex(script_name, '_') + 1:]
|
mode = script_name[string.rindex(script_name, '_') + 1:]
|
||||||
|
|
||||||
log.debug("Mode : {0}".format(str(mode)))
|
log.debug("Mode : {0}".format(mode))
|
||||||
|
|
||||||
if not mode in modes:
|
if mode not in modes:
|
||||||
log.error("Unknown mode '{0}'".format(mode))
|
log.error("Unknown mode '{0}'".format(mode))
|
||||||
log.info("Available modes are : {0}".format(str(modes)))
|
log.info("Available modes are : {0}".format(modes))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return mode
|
return mode
|
||||||
|
@ -280,9 +281,8 @@ def print_config(mode):
|
||||||
elif mode == "states":
|
elif mode == "states":
|
||||||
print("graph_title Torrents states")
|
print("graph_title Torrents states")
|
||||||
|
|
||||||
graph_order = ""
|
graph_order = " ".join(
|
||||||
for state_name in torrent_states:
|
[names_for_munin["state.{}".format(name)] for name in torrent_states])
|
||||||
graph_order += names_for_munin["state." + state_name] + " "
|
|
||||||
|
|
||||||
print("graph_order " + graph_order)
|
print("graph_order " + graph_order)
|
||||||
print("graph_args --base 1000 -r --lower-limit 0")
|
print("graph_args --base 1000 -r --lower-limit 0")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue