mirror of https://github.com/nicolargo/glances.git
Done fore Core plugin
This commit is contained in:
parent
e7d79a1dd6
commit
1cca754759
|
|
@ -21,6 +21,8 @@ class GlancesDataUnit:
|
|||
BYTE = 'B'
|
||||
CORE = 'C'
|
||||
TEMPERATURE = '°'
|
||||
INTEGER = ''
|
||||
FLOAT = ''
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
|||
|
|
@ -10,16 +10,31 @@
|
|||
"""CPU core plugin."""
|
||||
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.data.item import GlancesDataUnit
|
||||
from glances.data.plugin import GlancesDataPlugin
|
||||
|
||||
import psutil
|
||||
|
||||
# =============================================================================
|
||||
# Fields description
|
||||
# =============================================================================
|
||||
# key: stat identifier
|
||||
# description: human readable description
|
||||
# short_name: shortname to use in user interfaces
|
||||
# unit: unit type
|
||||
# min_symbol: Auto unit should be used if value > than 1 'X' (K, M, G)...
|
||||
# rate: if True, the value is a rate (per second, compute automaticaly)
|
||||
# =============================================================================
|
||||
|
||||
fields_description = {
|
||||
'phys': {'description': 'Number of physical cores (hyper thread CPUs are excluded).', 'unit': 'number'},
|
||||
'phys': {
|
||||
'description': 'Number of physical cores (hyper thread CPUs are excluded).',
|
||||
'unit': GlancesDataUnit.INTEGER
|
||||
},
|
||||
'log': {
|
||||
'description': 'Number of logical CPUs. A logical CPU is the number of \
|
||||
physical cores multiplied by the number of threads that can run on each core.',
|
||||
'unit': 'number',
|
||||
'unit': GlancesDataUnit.INTEGER
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -34,12 +49,24 @@ class PluginModel(GlancesPluginModel):
|
|||
|
||||
def __init__(self, args=None, config=None):
|
||||
"""Init the plugin."""
|
||||
super(PluginModel, self).__init__(args=args, config=config, fields_description=fields_description)
|
||||
super(PluginModel, self).__init__(args=args,
|
||||
config=config,
|
||||
fields_description=fields_description)
|
||||
|
||||
# We dot not want to display the stat in the curse interface
|
||||
# The core number is displayed by the load plugin
|
||||
self.display_curse = False
|
||||
|
||||
# Init the data
|
||||
# TODO: to be done in the top level plugin class
|
||||
self.stats = GlancesDataPlugin(name=self.plugin_name,
|
||||
description='Glances {} plugin'.format(self.plugin_name.upper()),
|
||||
fields_description=fields_description)
|
||||
|
||||
# TODO: To be done in the top level plugin class
|
||||
def get_raw(self):
|
||||
return self.stats.export()
|
||||
|
||||
# Do *NOT* uncomment the following line
|
||||
# @GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
|
|
@ -63,7 +90,7 @@ class PluginModel(GlancesPluginModel):
|
|||
stats["phys"] = psutil.cpu_count(logical=False)
|
||||
stats["log"] = psutil.cpu_count()
|
||||
except NameError:
|
||||
self.reset()
|
||||
stats = self.get_init_value()
|
||||
|
||||
elif self.input_method == 'snmp':
|
||||
# Update stats using SNMP
|
||||
|
|
@ -71,6 +98,4 @@ class PluginModel(GlancesPluginModel):
|
|||
pass
|
||||
|
||||
# Update the stats
|
||||
self.stats = stats
|
||||
|
||||
return self.stats
|
||||
self.stats.update_data(stats)
|
||||
|
|
|
|||
|
|
@ -76,7 +76,9 @@ class PluginModel(GlancesPluginModel):
|
|||
|
||||
# Call CorePluginModel in order to display the core number
|
||||
try:
|
||||
self.nb_log_core = CorePluginModel(args=self.args).update()["log"]
|
||||
core_plugin = CorePluginModel(args=self.args)
|
||||
core_plugin.update()
|
||||
self.nb_log_core = core_plugin.get_raw()['log']
|
||||
except Exception as e:
|
||||
logger.warning('Error: Can not retrieve the CPU core number (set it to 1) ({})'.format(e))
|
||||
self.nb_log_core = 1
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ class GlancesPluginModel(object):
|
|||
|
||||
Stats should be a list of dict (processlist, network...)
|
||||
"""
|
||||
return json_dumps_dictlist(self.stats, item)
|
||||
return json_dumps_dictlist(self.get_raw(), item)
|
||||
|
||||
def get_stats_value(self, item, value):
|
||||
"""Return the stats object for a specific item=value in JSON format.
|
||||
|
|
|
|||
|
|
@ -108,11 +108,11 @@ class TestGlances(unittest.TestCase):
|
|||
print("HTTP RESTful request: %s/%s" % (URL, p))
|
||||
req = self.http_get("%s/%s" % (URL, p))
|
||||
self.assertTrue(req.ok)
|
||||
if p in ('uptime', 'now'):
|
||||
if p in ('now'):
|
||||
self.assertIsInstance(req.json(), text_type)
|
||||
elif p in ('fs', 'percpu', 'sensors', 'alert', 'processlist', 'diskio',
|
||||
'hddtemp', 'batpercent', 'network', 'folders', 'amps', 'ports',
|
||||
'irq', 'wifi', 'gpu'):
|
||||
'irq', 'wifi', 'gpu', 'containers'):
|
||||
self.assertIsInstance(req.json(), list)
|
||||
elif p in ('psutilversion', 'help'):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in New Issue