mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-29 20:21:35 +03:00
Difficult to get CPU core number via SNMP. Bypass
This commit is contained in:
parent
7d4024a9f0
commit
ff5bbefa1b
@ -243,6 +243,6 @@ class GlancesStatsClientSNMP(GlancesStats):
|
||||
try:
|
||||
self._plugins[p].update(input='snmp')
|
||||
except Exception as e:
|
||||
# print "ERROR: %s" % e
|
||||
# print "ERROR with plugin %s: %s" % (p, e)
|
||||
pass
|
||||
|
||||
|
@ -37,26 +37,42 @@ class Plugin(GlancesPlugin):
|
||||
# The core number is displayed by the load plugin
|
||||
self.display_curse = False
|
||||
|
||||
# Return a dict (with both physical and log cpu number) instead of a integer
|
||||
self.stats = None
|
||||
# Init the stat
|
||||
self.reset()
|
||||
|
||||
def update(self):
|
||||
def reset(self):
|
||||
"""
|
||||
Reset/init the stat using the input method
|
||||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
Update core stats
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
Stats is a dict (with both physical and log cpu number) instead of a integer
|
||||
"""
|
||||
|
||||
# Reset the stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
|
||||
# Return a dict with:
|
||||
# - phys: physical cores only (hyper thread CPUs are excluded)
|
||||
# - log: logical CPUs in the system
|
||||
# Return None if undefine
|
||||
core_stats = {}
|
||||
try:
|
||||
core_stats["phys"] = psutil.cpu_count(logical=False)
|
||||
core_stats["log"] = psutil.cpu_count()
|
||||
self.stats["phys"] = psutil.cpu_count(logical=False)
|
||||
self.stats["log"] = psutil.cpu_count()
|
||||
except NameError:
|
||||
core_stats = None
|
||||
self.reset()
|
||||
|
||||
self.stats = core_stats
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# http://stackoverflow.com/questions/5662467/how-to-find-out-the-number-of-cpus-using-snmp
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
@ -128,8 +128,6 @@ class Plugin(GlancesPlugin):
|
||||
self.stats.append(fs_current)
|
||||
diskIndex += 1
|
||||
|
||||
# print self.stats
|
||||
|
||||
return self.stats
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
|
@ -46,9 +46,6 @@ class Plugin(GlancesPlugin):
|
||||
def __init__(self):
|
||||
GlancesPlugin.__init__(self)
|
||||
|
||||
# Instance for the CorePlugin in order to display the core number
|
||||
self.core_plugin = CorePlugin()
|
||||
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
# Set the message position
|
||||
@ -76,6 +73,13 @@ class Plugin(GlancesPlugin):
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
# Call CorePlugin in order to display the core number
|
||||
if not hasattr(self, 'nb_log_core'):
|
||||
try:
|
||||
self.nb_log_core = CorePlugin().update(input)["log"]
|
||||
except:
|
||||
self.nb_log_core = 0
|
||||
|
||||
if input == 'local':
|
||||
# Update stats using the standard system lib
|
||||
# Get the load using the os standard lib
|
||||
@ -115,7 +119,8 @@ class Plugin(GlancesPlugin):
|
||||
msg = "{0:8}".format(_("LOAD"))
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
# Core number
|
||||
msg = "{0:>6}".format(str(self.core_plugin.update()["log"])+_("core"))
|
||||
if (self.nb_log_core > 0):
|
||||
msg = "{0:>6}".format(str(self.nb_log_core)+_("core"))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# New line
|
||||
ret.append(self.curse_new_line())
|
||||
@ -131,7 +136,7 @@ class Plugin(GlancesPlugin):
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = "{0:>6}".format(format(self.stats['min5'], '.2f'))
|
||||
ret.append(self.curse_add_line(
|
||||
msg, self.get_alert(self.stats['min5'], max=100 * self.core_plugin.update()["log"])))
|
||||
msg, self.get_alert(self.stats['min5'], max=100 * self.nb_log_core)))
|
||||
# New line
|
||||
ret.append(self.curse_new_line())
|
||||
# 15min load
|
||||
@ -139,6 +144,6 @@ class Plugin(GlancesPlugin):
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = "{0:>6}".format(format(self.stats['min15'], '.2f'))
|
||||
ret.append(self.curse_add_line(
|
||||
msg, self.get_alert_log(self.stats['min15'], max=100 * self.core_plugin.update()["log"])))
|
||||
msg, self.get_alert_log(self.stats['min15'], max=100 * self.nb_log_core)))
|
||||
|
||||
return ret
|
||||
|
@ -135,7 +135,7 @@ class Plugin(GlancesPlugin):
|
||||
self.stats.extend(self.hddtemp_plugin.stats)
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO
|
||||
# No standard: http://www.net-snmp.org/wiki/index.php/Net-SNMP_and_lm-sensors_on_Ubuntu_10.04
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
Loading…
Reference in New Issue
Block a user