提交 e40f5555 编写于 作者: N Nicolas Hennion

CPU is OK, but not diskio and others plugins

上级 95822505
...@@ -34,9 +34,9 @@ class CpuPercent(object): ...@@ -34,9 +34,9 @@ class CpuPercent(object):
# cached_time is the minimum time interval between stats updates # cached_time is the minimum time interval between stats updates
# since last update is passed (will retrieve old cached info instead) # since last update is passed (will retrieve old cached info instead)
self.cached_time = 0
self.timer_cpu = Timer(0) self.timer_cpu = Timer(0)
self.timer_percpu = Timer(0) self.timer_percpu = Timer(0)
self.cached_time = cached_time
def get_key(self): def get_key(self):
"""Return the key of the per CPU list.""" """Return the key of the per CPU list."""
......
...@@ -108,39 +108,41 @@ class Plugin(GlancesPlugin): ...@@ -108,39 +108,41 @@ class Plugin(GlancesPlugin):
stats = self.get_init_value() stats = self.get_init_value()
stats['total'] = cpu_percent.get() 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) cpu_times_percent = psutil.cpu_times_percent(interval=0.0)
for stat in ['user', 'system', 'idle', 'nice', 'iowait', for stat in cpu_times_percent._fields:
'irq', 'softirq', 'steal', 'guest', 'guest_nice']: stats[stat] = getattr(cpu_times_percent, stat)
if hasattr(cpu_times_percent, stat):
stats[stat] = getattr(cpu_times_percent, stat)
# Additional CPU stats (number of events not as a %; psutil>=4.1.0) # Additional CPU stats (number of events not as a %; psutil>=4.1.0)
# ctx_switches: number of context switches (voluntary + involuntary) per second # - ctx_switches: number of context switches (voluntary + involuntary) since boot.
# interrupts: number of interrupts per second # - interrupts: number of interrupts since boot.
# soft_interrupts: number of software interrupts per second. Always set to 0 on Windows and SunOS. # - 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. # - syscalls: number of system calls since boot. Always set to 0 on Linux.
cpu_stats = psutil.cpu_stats() cpu_stats = psutil.cpu_stats()
# By storing time data we enable Rx/s and Tx/s calculations in the # By storing time data we enable Rx/s and Tx/s calculations in the
# XML/RPC API, which would otherwise be overly difficult work # XML/RPC API, which would otherwise be overly difficult work
# for users of the API # 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 # Previous CPU stats are stored in the cpu_stats_old variable
if not hasattr(self, 'cpu_stats_old'): if not hasattr(self, 'cpu_stats_old'):
# First call, we init the cpu_stats_old var # Init the stats (needed to have the key name for export)
self.cpu_stats_old = cpu_stats for stat in cpu_stats._fields:
# @TODO: better to set it to None but should refactor views and UI...
stats[stat] = 0
else: else:
# Others calls...
for stat in cpu_stats._fields: for stat in cpu_stats._fields:
if getattr(cpu_stats, stat) is not None: if getattr(cpu_stats, stat) is not None:
stats[stat] = getattr(cpu_stats, stat) - getattr(self.cpu_stats_old, stat) stats[stat] = getattr(cpu_stats, stat) - getattr(self.cpu_stats_old, stat)
stats['time_since_update'] = time_since_update # Save stats to compute next step
self.cpu_stats_old = cpu_stats
# 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
return stats return stats
...@@ -245,11 +247,6 @@ class Plugin(GlancesPlugin): ...@@ -245,11 +247,6 @@ class Plugin(GlancesPlugin):
msg = '{:5.1f}%'.format(self.stats['total']) msg = '{:5.1f}%'.format(self.stats['total'])
ret.append(self.curse_add_line( ret.append(self.curse_add_line(
msg, self.get_views(key='total', option='decoration'))) 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 # Idle CPU
if 'idle' in self.stats and not idle_tag: if 'idle' in self.stats and not idle_tag:
msg = ' {:8}'.format('idle:') msg = ' {:8}'.format('idle:')
......
...@@ -86,7 +86,7 @@ class Plugin(GlancesPlugin): ...@@ -86,7 +86,7 @@ class Plugin(GlancesPlugin):
# read_time: time spent reading from disk (in milliseconds) # read_time: time spent reading from disk (in milliseconds)
# write_time: time spent writing to disk (in milliseconds) # write_time: time spent writing to disk (in milliseconds)
try: try:
diskiocounters = psutil.disk_io_counters(perdisk=True) diskio = psutil.disk_io_counters(perdisk=True)
except Exception: except Exception:
return stats return stats
...@@ -94,7 +94,7 @@ class Plugin(GlancesPlugin): ...@@ -94,7 +94,7 @@ class Plugin(GlancesPlugin):
if not hasattr(self, 'diskio_old'): if not hasattr(self, 'diskio_old'):
# First call, we init the diskio_old var # First call, we init the diskio_old var
try: try:
self.diskio_old = diskiocounters self.diskio_old = diskio
except (IOError, UnboundLocalError): except (IOError, UnboundLocalError):
pass pass
else: else:
...@@ -103,7 +103,7 @@ class Plugin(GlancesPlugin): ...@@ -103,7 +103,7 @@ class Plugin(GlancesPlugin):
# for users of the API # for users of the API
time_since_update = getTimeSinceLastUpdate('disk') time_since_update = getTimeSinceLastUpdate('disk')
diskio_new = diskiocounters diskio_new = diskio
for disk in diskio_new: for disk in diskio_new:
# By default, RamFS is not displayed (issue #714) # 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'): if self.args is not None and not self.args.diskio_show_ramfs and disk.startswith('ram'):
...@@ -130,13 +130,17 @@ class Plugin(GlancesPlugin): ...@@ -130,13 +130,17 @@ class Plugin(GlancesPlugin):
'write_count': write_count, 'write_count': write_count,
'read_bytes': read_bytes, 'read_bytes': read_bytes,
'write_bytes': write_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: except KeyError:
continue continue
else: 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() diskstat['key'] = self.get_key()
# Ad dthe current disk stat to the list
stats.append(diskstat) stats.append(diskstat)
# Save stats to compute next bitrate # Save stats to compute next bitrate
......
...@@ -92,7 +92,7 @@ class GlancesStandalone(object): ...@@ -92,7 +92,7 @@ class GlancesStandalone(object):
# Init screen # Init screen
self.screen = GlancesStdout(config=config, args=args) self.screen = GlancesStdout(config=config, args=args)
elif args.stdout_csv: 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 # Init screen
self.screen = GlancesStdoutCsv(config=config, args=args) self.screen = GlancesStdoutCsv(config=config, args=args)
else: else:
......
...@@ -239,7 +239,7 @@ class GlancesStats(object): ...@@ -239,7 +239,7 @@ class GlancesStats(object):
Each export module is ran in a dedicated thread. Each export module is ran in a dedicated thread.
""" """
if self.first_export: 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 self.first_export = False
return False return False
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册