diff options
author | Nicolas Hennion <nicolas.hennion@thalesaleniaspace.com> | 2021-05-24 13:46:02 +0200 |
---|---|---|
committer | Nicolas Hennion <nicolas.hennion@thalesaleniaspace.com> | 2021-05-24 13:46:02 +0200 |
commit | e40f5555b4183e865e02e595bb3ec833f5a5a1f6 (patch) | |
tree | eb9cb24f31fd867a1934f8428a1032a13b91b58e /glances | |
parent | 958225051afa7ba1ac15b3b92f1115c5d66c06dd (diff) |
CPU is OK, but not diskio and others plugins
Diffstat (limited to 'glances')
-rw-r--r-- | glances/cpu_percent.py | 2 | ||||
-rw-r--r-- | glances/plugins/glances_cpu.py | 43 | ||||
-rw-r--r-- | glances/plugins/glances_diskio.py | 16 | ||||
-rw-r--r-- | glances/standalone.py | 2 | ||||
-rw-r--r-- | glances/stats.py | 2 |
5 files changed, 33 insertions, 32 deletions
diff --git a/glances/cpu_percent.py b/glances/cpu_percent.py index 77763968..335fc373 100644 --- a/glances/cpu_percent.py +++ b/glances/cpu_percent.py @@ -34,9 +34,9 @@ class CpuPercent(object): # cached_time is the minimum time interval between stats updates # since last update is passed (will retrieve old cached info instead) + self.cached_time = 0 self.timer_cpu = Timer(0) self.timer_percpu = Timer(0) - self.cached_time = cached_time def get_key(self): """Return the key of the per CPU list.""" diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 4e8fb0d3..66564065 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -108,39 +108,41 @@ class Plugin(GlancesPlugin): stats = self.get_init_value() stats['total'] = cpu_percent.get() + # Grab: 'user', 'system', 'idle', 'nice', 'iowait', + # 'irq', 'softirq', 'steal', 'guest', 'guest_nice' cpu_times_percent = psutil.cpu_times_percent(interval=0.0) - for stat in ['user', 'system', 'idle', 'nice', 'iowait', - 'irq', 'softirq', 'steal', 'guest', 'guest_nice']: - if hasattr(cpu_times_percent, stat): - stats[stat] = getattr(cpu_times_percent, stat) + for stat in cpu_times_percent._fields: + stats[stat] = getattr(cpu_times_percent, stat) # Additional CPU stats (number of events not as a %; psutil>=4.1.0) - # ctx_switches: number of context switches (voluntary + involuntary) per second - # interrupts: number of interrupts per second - # soft_interrupts: number of software interrupts per second. Always set to 0 on Windows and SunOS. - # syscalls: number of system calls since boot. Always set to 0 on Linux. + # - ctx_switches: number of context switches (voluntary + involuntary) since boot. + # - interrupts: number of interrupts since boot. + # - soft_interrupts: number of software interrupts since boot. Always set to 0 on Windows and SunOS. + # - syscalls: number of system calls since boot. Always set to 0 on Linux. cpu_stats = psutil.cpu_stats() + # 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('cpu') + stats['time_since_update'] = getTimeSinceLastUpdate('cpu') + + # Core number is needed to compute the CTX switch limit + stats['cpucore'] = self.nb_log_core # Previous CPU stats are stored in the cpu_stats_old variable if not hasattr(self, 'cpu_stats_old'): - # First call, we init the cpu_stats_old var - self.cpu_stats_old = cpu_stats + # Init the stats (needed to have the key name for export) + for stat in cpu_stats._fields: + # @TODO: better to set it to None but should refactor views and UI... + stats[stat] = 0 else: + # Others calls... for stat in cpu_stats._fields: if getattr(cpu_stats, stat) is not None: stats[stat] = getattr(cpu_stats, stat) - getattr(self.cpu_stats_old, stat) - stats['time_since_update'] = time_since_update - - # Core number is needed to compute the CTX switch limit - stats['cpucore'] = self.nb_log_core - - # Save stats to compute next step - self.cpu_stats_old = cpu_stats + # Save stats to compute next step + self.cpu_stats_old = cpu_stats return stats @@ -245,11 +247,6 @@ class Plugin(GlancesPlugin): msg = '{:5.1f}%'.format(self.stats['total']) ret.append(self.curse_add_line( msg, self.get_views(key='total', option='decoration'))) - # if idle_tag: - # ret.append(self.curse_add_line( - # msg, self.get_views(key='total', option='decoration'))) - # else: - # ret.append(self.curse_add_line(msg)) # Idle CPU if 'idle' in self.stats and not idle_tag: msg = ' {:8}'.format('idle:') diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index 38705595..d97e491f 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -86,7 +86,7 @@ class Plugin(GlancesPlugin): # read_time: time spent reading from disk (in milliseconds) # write_time: time spent writing to disk (in milliseconds) try: - diskiocounters = psutil.disk_io_counters(perdisk=True) + diskio = psutil.disk_io_counters(perdisk=True) except Exception: return stats @@ -94,7 +94,7 @@ class Plugin(GlancesPlugin): if not hasattr(self, 'diskio_old'): # First call, we init the diskio_old var try: - self.diskio_old = diskiocounters + self.diskio_old = diskio except (IOError, UnboundLocalError): pass else: @@ -103,7 +103,7 @@ class Plugin(GlancesPlugin): # for users of the API time_since_update = getTimeSinceLastUpdate('disk') - diskio_new = diskiocounters + 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'): @@ -130,13 +130,17 @@ class Plugin(GlancesPlugin): 'write_count': write_count, 'read_bytes': read_bytes, 'write_bytes': write_bytes} - # Add alias if exist (define in the configuration file) - if self.has_alias(disk) is not None: - diskstat['alias'] = self.has_alias(disk) 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 diff --git a/glances/standalone.py b/glances/standalone.py index 1e7d070b..d6a07f2f 100644 --- a/glances/standalone.py +++ b/glances/standalone.py @@ -92,7 +92,7 @@ class GlancesStandalone(object): # Init screen self.screen = GlancesStdout(config=config, args=args) elif args.stdout_csv: - logger.info("Stdout CSV mode is ON, following stats will be displayed: {}".format(args.stdout)) + logger.info("Stdout CSV mode is ON, following stats will be displayed: {}".format(args.stdout_csv)) # Init screen self.screen = GlancesStdoutCsv(config=config, args=args) else: diff --git a/glances/stats.py b/glances/stats.py index 9e83eda4..e2d0b724 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -239,7 +239,7 @@ class GlancesStats(object): Each export module is ran in a dedicated thread. """ if self.first_export: - logger.info("Do not export on first iteration because some stats missing") + logger.debug("Do not export stats during the first iteration because some information are missing") self.first_export = False return False |