From 7571f146fa2f95ef702c827ced44f619e3f1cef5 Mon Sep 17 00:00:00 2001 From: oopoa Date: Sun, 15 Jun 2014 00:14:47 +0800 Subject: [PATCH 1/2] add api for bandwidth statistics --- sabnzbd/api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sabnzbd/api.py b/sabnzbd/api.py index eae84f0..78778e0 100644 --- a/sabnzbd/api.py +++ b/sabnzbd/api.py @@ -790,8 +790,22 @@ def _api_config_undefined(output, kwargs): return report(output, _MSG_NOT_IMPLEMENTED) +def _api_bandwidth(name, output, kwargs): + """ API: accepts output """ + sum_t, sum_m, sum_w, sum_d = BPSMeter.do.get_sums() + bw = {'total': sum_t, 'month': sum_m, 'week': sum_w, 'day': sum_d} + + bw['servers'] = {} + for svr in config.get_servers(): + t, m, w, d = BPSMeter.do.amounts(svr) + bw['servers'][svr] = {'total': t or 0, 'month': m or 0, 'week': w or 0, 'day': d or 0} + + return report(output, keyword='bandwidth', data=bw) + + #------------------------------------------------------------------------------ _api_table = { + 'bandwidth' : _api_bandwidth, 'get_config' : _api_get_config, 'set_config' : _api_set_config, 'del_config' : _api_del_config, From 0849039bb42acf8518e047ad68d0ecc7b49ab0cf Mon Sep 17 00:00:00 2001 From: kcrayon Date: Fri, 20 Jun 2014 12:02:31 +0800 Subject: [PATCH 2/2] rename to server_stats --- sabnzbd/api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sabnzbd/api.py b/sabnzbd/api.py index 78778e0..4815957 100644 --- a/sabnzbd/api.py +++ b/sabnzbd/api.py @@ -790,22 +790,22 @@ def _api_config_undefined(output, kwargs): return report(output, _MSG_NOT_IMPLEMENTED) -def _api_bandwidth(name, output, kwargs): +def _api_server_stats(name, output, kwargs): """ API: accepts output """ sum_t, sum_m, sum_w, sum_d = BPSMeter.do.get_sums() - bw = {'total': sum_t, 'month': sum_m, 'week': sum_w, 'day': sum_d} + stats = {'total': sum_t, 'month': sum_m, 'week': sum_w, 'day': sum_d} - bw['servers'] = {} + stats['servers'] = {} for svr in config.get_servers(): t, m, w, d = BPSMeter.do.amounts(svr) - bw['servers'][svr] = {'total': t or 0, 'month': m or 0, 'week': w or 0, 'day': d or 0} + stats['servers'][svr] = {'total': t or 0, 'month': m or 0, 'week': w or 0, 'day': d or 0} - return report(output, keyword='bandwidth', data=bw) + return report(output, keyword='', data=stats) #------------------------------------------------------------------------------ _api_table = { - 'bandwidth' : _api_bandwidth, + 'server_stats' : _api_server_stats, 'get_config' : _api_get_config, 'set_config' : _api_set_config, 'del_config' : _api_del_config,