From a874ea8ddc49a9d1b915409e5df247f9d1e54174 Mon Sep 17 00:00:00 2001 From: Nicolas Hennion Date: Mon, 24 May 2021 14:37:48 +0200 Subject: Correct issue in stdout cvs header field --- glances/outputs/glances_stdout_csv.py | 4 +- glances/plugins/glances_cpu.py | 4 -- glances/plugins/glances_diskio.py | 105 +++++++++++++++++----------------- 3 files changed, 54 insertions(+), 59 deletions(-) diff --git a/glances/outputs/glances_stdout_csv.py b/glances/outputs/glances_stdout_csv.py index 7fd34a1f..681b71ca 100644 --- a/glances/outputs/glances_stdout_csv.py +++ b/glances/outputs/glances_stdout_csv.py @@ -2,7 +2,7 @@ # # This file is part of Glances. # -# Copyright (C) 2019 Nicolargo +# Copyright (C) 2021 Nicolargo # # Glances is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -77,7 +77,7 @@ class GlancesStdoutCsv(object): if isinstance(i, dict) and 'key' in i: for k in i.keys(): line += '{}.{}.{}{}'.format(plugin, - str(i['key']), + str(i[i['key']]), str(k), self.separator) else: diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 66564065..1e582dc3 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -75,10 +75,6 @@ class Plugin(GlancesPlugin): except Exception: self.nb_log_core = 1 - # Force a first update because we need two update to have the first stat - self.update() - self.refresh_timer.set(0) - @GlancesPlugin._check_decorator @GlancesPlugin._log_result_decorator def update(self): diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index d97e491f..29365e63 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -91,60 +91,59 @@ class Plugin(GlancesPlugin): return stats # Previous disk IO stats are stored in the diskio_old variable - if not hasattr(self, 'diskio_old'): - # First call, we init the diskio_old var + # By storing time data we enable Rx/s and Tx/s calculations in the + # XML/RPC API, which would otherwise be overly difficult work + # for users of the API + time_since_update = getTimeSinceLastUpdate('disk') + + diskio = diskio + for disk in diskio: + # By default, RamFS is not displayed (issue #714) + if self.args is not None and not self.args.diskio_show_ramfs and disk.startswith('ram'): + continue + + # Do not take hide disk into account + if self.is_hide(disk): + continue + + # Compute count and bit rate try: - self.diskio_old = diskio - except (IOError, UnboundLocalError): - pass - else: - # By storing time data we enable Rx/s and Tx/s calculations in the - # XML/RPC API, which would otherwise be overly difficult work - # for users of the API - time_since_update = getTimeSinceLastUpdate('disk') - - diskio_new = diskio - for disk in diskio_new: - # By default, RamFS is not displayed (issue #714) - if self.args is not None and not self.args.diskio_show_ramfs and disk.startswith('ram'): - continue - - # Do not take hide disk into account - if self.is_hide(disk): - continue - - # Compute count and bit rate - try: - read_count = (diskio_new[disk].read_count - - self.diskio_old[disk].read_count) - write_count = (diskio_new[disk].write_count - - self.diskio_old[disk].write_count) - read_bytes = (diskio_new[disk].read_bytes - - self.diskio_old[disk].read_bytes) - write_bytes = (diskio_new[disk].write_bytes - - self.diskio_old[disk].write_bytes) - diskstat = { - 'time_since_update': time_since_update, - 'disk_name': n(disk), - 'read_count': read_count, - 'write_count': write_count, - 'read_bytes': read_bytes, - 'write_bytes': write_bytes} - except KeyError: - continue - else: - # Add alias if exist (define in the configuration file) - if self.has_alias(disk) is not None: - diskstat['alias'] = self.has_alias(disk) - - # Add the dict key - diskstat['key'] = self.get_key() - - # Ad dthe current disk stat to the list - stats.append(diskstat) - - # Save stats to compute next bitrate - self.diskio_old = diskio_new + diskstat = { + 'time_since_update': time_since_update, + 'disk_name': n(disk), + 'read_count': diskio[disk].read_count - \ + self.diskio_old[disk].read_count, + 'write_count': diskio[disk].write_count - \ + self.diskio_old[disk].write_count, + 'read_bytes': diskio[disk].read_bytes - \ + self.diskio_old[disk].read_bytes, + 'write_bytes': diskio[disk].write_bytes - \ + self.diskio_old[disk].write_bytes + } + except (KeyError, AttributeError): + diskstat = { + 'time_since_update': time_since_update, + 'disk_name': n(disk), + 'read_count': 0, + 'write_count': 0, + 'read_bytes': 0, + 'write_bytes': 0} + + # Add alias if exist (define in the configuration file) + if self.has_alias(disk) is not None: + diskstat['alias'] = self.has_alias(disk) + + # Add the dict key + diskstat['key'] = self.get_key() + + # Ad dthe current disk stat to the list + stats.append(diskstat) + + # Save stats to compute next bitrate + try: + self.diskio_old = diskio + except (IOError, UnboundLocalError): + pass elif self.input_method == 'snmp': # Update stats using SNMP # No standard way for the moment... -- cgit v1.2.3