From 8a3d7e49a37afe50a17f765bb46c115ae372fb75 Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Tue, 10 May 2016 11:27:40 +0200 Subject: [PATCH] Correct network plugin duplication code and enhance Docker plugin --- glances/plugins/glances_docker.py | 10 +++++++- glances/plugins/glances_network.py | 37 ++++++++++++++---------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index 9ec587db..6c7c5993 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -523,9 +523,17 @@ class Plugin(GlancesPlugin): msg = '{0:>7}'.format('?') ret.append(self.curse_add_line(msg)) # NET RX/TX + if args.byte: + # Bytes per second (for dummy) + to_bit = 1 + unit = '' + else: + # Bits per second (for real network administrator | Default) + to_bit = 8 + unit = 'b' for r in ['rx', 'tx']: try: - value = self.auto_unit(int(container['network'][r] // container['network']['time_since_update'] * 8)) + "b" + value = self.auto_unit(int(container['network'][r] // container['network']['time_since_update'] * to_bit)) + unit msg = '{0:>7}'.format(value) except KeyError: msg = '{0:>7}'.format('?') diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index 17e02348..68a8f7cb 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -285,30 +285,27 @@ class Plugin(GlancesPlugin): if len(ifname) > ifname_max_width: # Cut interface name if it is too long ifname = '_' + ifname[-ifname_max_width + 1:] + if args.byte: # Bytes per second (for dummy) - if args.network_cumul: - rx = self.auto_unit(int(i['cumulative_rx'])) - tx = self.auto_unit(int(i['cumulative_tx'])) - sx = self.auto_unit(int(i['cumulative_tx']) + - int(i['cumulative_tx'])) - else: - rx = self.auto_unit(int(i['rx'] // i['time_since_update'])) - tx = self.auto_unit(int(i['tx'] // i['time_since_update'])) - sx = self.auto_unit(int(i['rx'] // i['time_since_update']) + - int(i['tx'] // i['time_since_update'])) + to_bit = 1 + unit = '' else: # Bits per second (for real network administrator | Default) - if args.network_cumul: - rx = self.auto_unit(int(i['cumulative_rx'] * 8)) + "b" - tx = self.auto_unit(int(i['cumulative_tx'] * 8)) + "b" - sx = self.auto_unit(int(i['cumulative_rx'] * 8) + - int(i['cumulative_tx'] * 8)) + "b" - else: - rx = self.auto_unit(int(i['rx'] // i['time_since_update'] * 8)) + "b" - tx = self.auto_unit(int(i['tx'] // i['time_since_update'] * 8)) + "b" - sx = self.auto_unit(int(i['rx'] // i['time_since_update'] * 8) + - int(i['tx'] // i['time_since_update'] * 8)) + "b" + to_bit = 8 + unit = 'b' + + if args.network_cumul: + rx = self.auto_unit(int(i['cumulative_rx'] * to_bit)) + unit + tx = self.auto_unit(int(i['cumulative_tx'] * to_bit)) + unit + sx = self.auto_unit(int(i['cumulative_rx'] * to_bit) + + int(i['cumulative_tx'] * to_bit)) + unit + else: + rx = self.auto_unit(int(i['rx'] // i['time_since_update'] * to_bit)) + unit + tx = self.auto_unit(int(i['tx'] // i['time_since_update'] * to_bit)) + unit + sx = self.auto_unit(int(i['rx'] // i['time_since_update'] * to_bit) + + int(i['tx'] // i['time_since_update'] * to_bit)) + unit + # New line ret.append(self.curse_new_line()) msg = '{0:{width}}'.format(ifname, width=ifname_max_width)