提交 c96fee90 编写于 作者: N nicolargo

Refactor the way importants stats are displayed #1826

上级 c5e70b7c
......@@ -42,24 +42,38 @@ swap_critical=90
[cpu]
disable=False
# See https://scoutapm.com/blog/slow_server_flow_chart
#
# I/O wait percentage should be lower than 1/# (# = Logical CPU cores)
# Leave commented to just use the default config:
# Careful=1/#*100-20% / Warning=1/#*100-10% / Critical=1/#*100
#iowait_careful=30
#iowait_warning=40
#iowait_critical=50
#
# Total % is 100 - idle
total_careful=65
total_warning=75
total_critical=85
total_log=True
#
# Default values if not defined: 50/70/90 (except for iowait)
user_careful=50
user_warning=70
user_critical=90
#user_log=False
user_log=False
#user_critical_action=echo {{user}} {{value}} {{max}} > /tmp/cpu.alert
#
system_careful=50
system_warning=70
system_critical=90
system_log=False
#
steal_careful=50
steal_warning=70
steal_critical=90
#steal_log=True
# I/O wait percentage should be lower than 1/# (Logical CPU cores)
# Leave commented to just use the default config (1/#-20% / 1/#-10% / 1/#)
#iowait_careful=30
#iowait_warning=40
#iowait_critical=50
#
# Context switch limit (core / second)
# Leave commented to just use the default config (critical is 50000*# (Logical CPU cores)
#ctx_switches_careful=10000
......
......@@ -19,6 +19,7 @@
"""CPU plugin."""
from glances.logger import logger
from glances.timer import getTimeSinceLastUpdate
from glances.compat import iterkeys
from glances.cpu_percent import cpu_percent
......@@ -196,11 +197,11 @@ class Plugin(GlancesPlugin):
# Add specifics informations
# Alert and log
for key in ['user', 'system', 'iowait']:
for key in ['user', 'system', 'iowait', 'total']:
if key in self.stats:
self.views[key]['decoration'] = self.get_alert_log(self.stats[key], header=key)
# Alert only
for key in ['steal', 'total']:
for key in ['steal']:
if key in self.stats:
self.views[key]['decoration'] = self.get_alert(self.stats[key], header=key)
# Alert only but depend on Core number
......@@ -208,7 +209,7 @@ class Plugin(GlancesPlugin):
if key in self.stats:
self.views[key]['decoration'] = self.get_alert(self.stats[key], maximum=100 * self.stats['cpucore'], header=key)
# Optional
for key in ['nice', 'irq', 'iowait', 'steal', 'ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls']:
for key in ['nice', 'irq', 'idle', 'steal', 'ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls']:
if key in self.stats:
self.views[key]['optional'] = True
......@@ -239,17 +240,19 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
# Total CPU usage
msg = '{:5.1f}%'.format(self.stats['total'])
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, 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:')
ret.append(self.curse_add_line(msg))
msg = '{:5.1f}%'.format(self.stats['idle'])
ret.append(self.curse_add_line(msg))
# Nice CPU
if 'nice' in self.stats:
msg = ' {:8}'.format('nice:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='nice', option='optional')))
msg = '{:5.1f}%'.format(self.stats['nice'])
ret.append(self.curse_add_line(msg, optional=self.get_views(key='nice', option='optional')))
# ctx_switches
if 'ctx_switches' in self.stats:
msg = ' {:8}'.format('ctx_sw:')
......@@ -301,14 +304,14 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
msg = '{:>6}'.format(self.stats['nb_log_core'])
ret.append(self.curse_add_line(msg))
# IOWait CPU
if 'iowait' in self.stats:
msg = ' {:8}'.format('iowait:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='iowait', option='optional')))
msg = '{:5.1f}%'.format(self.stats['iowait'])
# Nice CPU
if 'nice' in self.stats:
msg = ' {:8}'.format('nice:')
ret.append(self.curse_add_line(
msg, self.get_views(key='iowait', option='decoration'),
optional=self.get_views(key='iowait', option='optional')))
msg, optional=self.get_views(key='nice', option='optional')))
msg = '{:5.1f}%'.format(self.stats['nice'])
ret.append(self.curse_add_line(
msg, optional=self.get_views(key='nice', option='optional')))
# soft_interrupts
if 'soft_interrupts' in self.stats:
msg = ' {:8}'.format('sw_int:')
......@@ -318,12 +321,15 @@ class Plugin(GlancesPlugin):
# New line
ret.append(self.curse_new_line())
# Idle CPU
if 'idle' in self.stats and not idle_tag:
msg = '{:8}'.format('idle:')
ret.append(self.curse_add_line(msg))
msg = '{:5.1f}%'.format(self.stats['idle'])
ret.append(self.curse_add_line(msg))
# IOWait CPU
if 'iowait' in self.stats:
msg = '{:8}'.format('iowait:')
ret.append(self.curse_add_line(
msg, optional=self.get_views(key='iowait', option='optional')))
msg = '{:5.1f}%'.format(self.stats['iowait'])
ret.append(self.curse_add_line(
msg, self.get_views(key='iowait', option='decoration'),
optional=self.get_views(key='iowait', option='optional')))
# Steal CPU usage
if 'steal' in self.stats:
msg = ' {:8}'.format('steal:')
......
......@@ -19,6 +19,7 @@
"""Virtual memory plugin."""
from glances.logger import logger
from glances.compat import iterkeys
from glances.plugins.glances_plugin import GlancesPlugin
......@@ -161,7 +162,7 @@ class Plugin(GlancesPlugin):
# Add specifics informations
# Alert and log
self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], maximum=self.stats['total'])
self.views['percent']['decoration'] = self.get_alert_log(self.stats['used'], maximum=self.stats['total'])
# Optional
for key in ['active', 'inactive', 'buffers', 'cached']:
if key in self.stats:
......@@ -184,7 +185,8 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
# Percent memory usage
msg = '{:>7.1%}'.format(self.stats['percent'] / 100)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(
msg, self.get_views(key='percent', option='decoration')))
# Active memory usage
if 'active' in self.stats:
msg = ' {:9}'.format('active:')
......
......@@ -139,8 +139,8 @@ class Plugin(GlancesPlugin):
# Add specifics informations
# Alert and log
if 'used' in self.stats and 'total' in self.stats:
self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], maximum=self.stats['total'])
if 'used' in self.stats and 'total' in self.stats and 'percent' in self.stats:
self.views['percent']['decoration'] = self.get_alert_log(self.stats['used'], maximum=self.stats['total'])
def msg_curse(self, args=None, max_width=None):
"""Return the dict to display in the curse interface."""
......@@ -159,7 +159,8 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
# Percent memory usage
msg = '{:>6.1%}'.format(self.stats['percent'] / 100)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(
msg, self.get_views(key='percent', option='decoration')))
# New line
ret.append(self.curse_new_line())
# Total memory usage
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册