Merge branch 'issue1265' into develop

This commit is contained in:
nicolargo 2018-05-19 10:38:01 +02:00
commit 3db4e105d3
3 changed files with 33 additions and 24 deletions

1
NEWS
View File

@ -28,6 +28,7 @@ Enhancements and new features:
* Add time zone to the current time #1249
* Use https URLs for checking external IP #1253
* Add labels support to Promotheus exporter #1255
* Overlap in Web UI when monitoring a machine with 16 cpu threads #1265
One more thing ! A new Grafana Dash is available with:
* Network interface variable

View File

@ -19,6 +19,7 @@
"""Per-CPU plugin."""
from glances.logger import logger
from glances.cpu_percent import cpu_percent
from glances.plugins.glances_plugin import GlancesPlugin
@ -76,6 +77,10 @@ class Plugin(GlancesPlugin):
# Init the return message
ret = []
# Only process if stats exist...
if not self.stats or self.is_disable():
return ret
# No per CPU stat ? Exit...
if not self.stats:
msg = 'PER CPU not available'
@ -83,35 +88,36 @@ class Plugin(GlancesPlugin):
return ret
# Build the string message
# Header
msg = '{:8}'.format('PER CPU')
ret.append(self.curse_add_line(msg, "TITLE"))
if self.is_disable('quicklook'):
msg = '{:7}'.format('PER CPU')
ret.append(self.curse_add_line(msg, "TITLE"))
# Total per-CPU usage
for cpu in self.stats:
try:
msg = '{:6.1f}%'.format(cpu['total'])
except TypeError:
# TypeError: string indices must be integers (issue #1027)
msg = '{:>6}%'.format('?')
ret.append(self.curse_add_line(msg))
# Stats per-CPU
# Per CPU stats displayed per line
for stat in ['user', 'system', 'idle', 'iowait', 'steal']:
if stat not in self.stats[0]:
continue
ret.append(self.curse_new_line())
msg = '{:8}'.format(stat + ':')
msg = '{:>7}'.format(stat)
ret.append(self.curse_add_line(msg))
for cpu in self.stats:
# Per CPU stats displayed per column
for cpu in self.stats:
ret.append(self.curse_new_line())
if self.is_disable('quicklook'):
try:
msg = '{:6.1f}%'.format(cpu[stat])
msg = '{:6.1f}%'.format(cpu['total'])
except TypeError:
# TypeError: string indices must be integers (issue #1027)
msg = '{:>6}%'.format('?')
ret.append(self.curse_add_line(msg))
for stat in ['user', 'system', 'idle', 'iowait', 'steal']:
if stat not in self.stats[0]:
continue
try:
msg = '{:6.1f}%'.format(cpu[stat])
except TypeError:
msg = '{:>6}%'.format('?')
ret.append(self.curse_add_line(msg,
self.get_alert(cpu[stat], header=stat)))
self.get_alert(cpu[stat],
header=stat)))
# Return the message with decoration
return ret

View File

@ -124,18 +124,20 @@ class GlancesPlugin(object):
"""Return the key of the list."""
return None
def is_enable(self):
def is_enable(self, plugin_name=None):
"""Return true if plugin is enabled."""
if not plugin_name:
plugin_name = self.plugin_name
try:
d = getattr(self.args, 'disable_' + self.plugin_name)
d = getattr(self.args, 'disable_' + plugin_name)
except AttributeError:
return True
else:
return d is False
def is_disable(self):
def is_disable(self, plugin_name=None):
"""Return true if plugin is disabled."""
return not self.is_enable()
return not self.is_enable(plugin_name=plugin_name)
def _json_dumps(self, d):
"""Return the object 'd' in a JSON format.