提交 0e7685ff 编写于 作者: N Nicolas Hennion

MEMSWAP + CPU ok on Windows SNMP fallback mode

上级 9dda132c
...@@ -98,13 +98,21 @@ class Plugin(GlancesPlugin): ...@@ -98,13 +98,21 @@ class Plugin(GlancesPlugin):
# Give also the number of core (number of element in the table) # Give also the number of core (number of element in the table)
# print snmp_oid[self.get_short_system_name()] # print snmp_oid[self.get_short_system_name()]
try: try:
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid[self.get_short_system_name()], cpu_stats = self.set_stats_snmp(snmp_oid=snmp_oid[self.get_short_system_name()],
bulk=True) bulk=True)
except KeyError: except KeyError:
self.reset() self.reset()
# TODO: iter through CPU... startswith('percent') # Iter through CPU and compute the idle CPU stats
self.stats['idle'] = self.stats['percent.3'] self.stats['nb_log_core'] = 0
self.stats['idle'] = 0
for c in cpu_stats:
if c.startswith('percent'):
self.stats['idle'] += float(cpu_stats['percent.3'])
self.stats['nb_log_core'] += 1
if self.stats['nb_log_core'] > 0:
self.stats['idle'] = self.stats['idle'] / self.stats['nb_log_core']
self.stats['idle'] = 100 - self.stats['idle']
else: else:
# Default behavor # Default behavor
...@@ -117,9 +125,9 @@ class Plugin(GlancesPlugin): ...@@ -117,9 +125,9 @@ class Plugin(GlancesPlugin):
self.reset() self.reset()
return self.stats return self.stats
# Convert SNMP stats to float # Convert SNMP stats to float
for key in self.stats.iterkeys(): for key in self.stats.iterkeys():
self.stats[key] = float(self.stats[key]) self.stats[key] = float(self.stats[key])
return self.stats return self.stats
...@@ -133,12 +141,17 @@ class Plugin(GlancesPlugin): ...@@ -133,12 +141,17 @@ class Plugin(GlancesPlugin):
return ret return ret
# Build the string message # Build the string message
# If user stat is not here, display only idle / total CPU usage (for exemple on Windows OS)
idle_tag = 'user' not in self.stats
# Header # Header
msg = '{0:8}'.format(_("CPU")) msg = '{0:8}'.format(_("CPU"))
ret.append(self.curse_add_line(msg, "TITLE")) ret.append(self.curse_add_line(msg, "TITLE"))
# Total CPU usage # Total CPU usage
msg = '{0:>6.1%}'.format((100 - self.stats['idle']) / 100) msg = '{0:>6.1%}'.format((100 - self.stats['idle']) / 100)
ret.append(self.curse_add_line(msg)) if idle_tag:
ret.append(self.curse_add_line(msg, self.get_alert_log((100 - self.stats['idle']) / 100, header="system")))
else:
ret.append(self.curse_add_line(msg))
# Nice CPU # Nice CPU
if 'nice' in self.stats: if 'nice' in self.stats:
msg = ' {0:8}'.format(_("nice:")) msg = ' {0:8}'.format(_("nice:"))
...@@ -152,7 +165,12 @@ class Plugin(GlancesPlugin): ...@@ -152,7 +165,12 @@ class Plugin(GlancesPlugin):
msg = '{0:8}'.format(_("user:")) msg = '{0:8}'.format(_("user:"))
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
msg = '{0:>6.1%}'.format(self.stats['user'] / 100) msg = '{0:>6.1%}'.format(self.stats['user'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['user'], header="user"))) ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['user'], header="user")))
elif 'idle' in self.stats:
msg = '{0:8}'.format(_("idle:"))
ret.append(self.curse_add_line(msg))
msg = '{0:>6.1%}'.format(self.stats['idle'] / 100)
ret.append(self.curse_add_line(msg))
# IRQ CPU # IRQ CPU
if 'irq' in self.stats: if 'irq' in self.stats:
msg = ' {0:8}'.format(_("irq:")) msg = ' {0:8}'.format(_("irq:"))
...@@ -162,11 +180,16 @@ class Plugin(GlancesPlugin): ...@@ -162,11 +180,16 @@ class Plugin(GlancesPlugin):
# New line # New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# System CPU # System CPU
if 'system' in self.stats: if 'system' in self.stats and not idle_tag:
msg = '{0:8}'.format(_("system:")) msg = '{0:8}'.format(_("system:"))
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
msg = '{0:>6.1%}'.format(self.stats['system'] / 100) msg = '{0:>6.1%}'.format(self.stats['system'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['system'], header="system"))) ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['system'], header="system")))
else:
msg = '{0:8}'.format(_("core:"))
ret.append(self.curse_add_line(msg))
msg = '{0:>6}'.format(self.stats['nb_log_core'])
ret.append(self.curse_add_line(msg))
# IOWait CPU # IOWait CPU
if 'iowait' in self.stats: if 'iowait' in self.stats:
msg = ' {0:8}'.format(_("iowait:")) msg = ' {0:8}'.format(_("iowait:"))
...@@ -176,7 +199,7 @@ class Plugin(GlancesPlugin): ...@@ -176,7 +199,7 @@ class Plugin(GlancesPlugin):
# New line # New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())
# Idle CPU # Idle CPU
if 'idle' in self.stats: if 'idle' in self.stats and not idle_tag:
msg = '{0:8}'.format(_("idle:")) msg = '{0:8}'.format(_("idle:"))
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
msg = '{0:>6.1%}'.format(self.stats['idle'] / 100) msg = '{0:>6.1%}'.format(self.stats['idle'] / 100)
......
...@@ -117,9 +117,9 @@ class Plugin(GlancesPlugin): ...@@ -117,9 +117,9 @@ class Plugin(GlancesPlugin):
except KeyError: except KeyError:
self.reset() self.reset()
else: else:
for fs in fs_stat: for fs in fs_stat:
# Memory stats are grabed in the same OID table (ignore it) # The Physical Memory gives statistics on RAM usage and availability.
if fs == 'Virtual Memory': if fs == 'Physical Memory':
self.stats['total'] = int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit']) self.stats['total'] = int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
self.stats['used'] = int(fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit']) self.stats['used'] = int(fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit'])
self.stats['percent'] = float(self.stats['used'] * 100 / self.stats['total']) self.stats['percent'] = float(self.stats['used'] * 100 / self.stats['total'])
......
...@@ -26,8 +26,12 @@ import psutil ...@@ -26,8 +26,12 @@ import psutil
# SNMP OID # SNMP OID
# Total Swap Size: .1.3.6.1.4.1.2021.4.3.0 # Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
# Available Swap Space: .1.3.6.1.4.1.2021.4.4.0 # Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
snmp_oid = {'total': '1.3.6.1.4.1.2021.4.3.0', snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.3.0',
'free': '1.3.6.1.4.1.2021.4.4.0'} 'free': '1.3.6.1.4.1.2021.4.4.0'},
'windows': {'mnt_point': '1.3.6.1.2.1.25.2.3.1.3',
'alloc_unit': '1.3.6.1.2.1.25.2.3.1.4',
'size': '1.3.6.1.2.1.25.2.3.1.5',
'used': '1.3.6.1.2.1.25.2.3.1.6'}}
class Plugin(GlancesPlugin): class Plugin(GlancesPlugin):
...@@ -80,21 +84,39 @@ class Plugin(GlancesPlugin): ...@@ -80,21 +84,39 @@ class Plugin(GlancesPlugin):
self.stats[swap] = getattr(sm_stats, swap) self.stats[swap] = getattr(sm_stats, swap)
elif self.get_input() == 'snmp': elif self.get_input() == 'snmp':
# Update stats using SNMP # Update stats using SNMP
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid) if self.get_short_system_name() == 'windows':
# Mem stats for Windows OS are stored in the FS table
if self.stats['total'] == '': try:
self.reset() fs_stat = self.set_stats_snmp(snmp_oid=snmp_oid[self.get_short_system_name()],
return self.stats bulk=True)
except KeyError:
for key in self.stats.iterkeys(): self.reset()
if self.stats[key] != '': else:
self.stats[key] = float(self.stats[key]) * 1024 for fs in fs_stat:
# The virtual memory concept is used by the operating system to extend (virtually) the physical
# used=total-free # memory and thus to run more programs by swapping unused memory zone (page) to a disk file.
self.stats['used'] = self.stats['total'] - self.stats['free'] if fs == 'Virtual Memory':
self.stats['total'] = int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
# percent: the percentage usage calculated as (total - available) / total * 100. self.stats['used'] = int(fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit'])
self.stats['percent'] = float((self.stats['total'] - self.stats['free']) / self.stats['total'] * 100) self.stats['percent'] = float(self.stats['used'] * 100 / self.stats['total'])
self.stats['free'] = self.stats['total'] - self.stats['used']
break
else:
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
if self.stats['total'] == '':
self.reset()
return self.stats
for key in self.stats.iterkeys():
if self.stats[key] != '':
self.stats[key] = float(self.stats[key]) * 1024
# used=total-free
self.stats['used'] = self.stats['total'] - self.stats['free']
# percent: the percentage usage calculated as (total - available) / total * 100.
self.stats['percent'] = float((self.stats['total'] - self.stats['free']) / self.stats['total'] * 100)
return self.stats return self.stats
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册