diff --git a/glances/__init__.py b/glances/__init__.py index 1f270d509ea06ae3a76febbad922275e134584a0..40002a77c4e015abd1b836ef83064f91d3a844ef 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -110,7 +110,7 @@ def start(config, args): # Start the main loop logger.debug("Glances started in {} seconds".format(start_duration.get())) - if args.stdout_issue: + if args.stdout_issue or args.stdout_fields: # Serve once for issue/test mode mode.serve_issue() else: diff --git a/glances/main.py b/glances/main.py index 88b27038a8466467123e8f29703c27725db2eec6..d7ba181e89ebb269d534371416e2dde782c61bd5 100644 --- a/glances/main.py +++ b/glances/main.py @@ -230,6 +230,8 @@ Examples of use: dest='stdout_csv', help='display stats to stdout, csv format (comma separated list of plugins/plugins.attribute)') parser.add_argument('--issue', default=None, action='store_true', dest='stdout_issue', help='test all plugins and exit (please copy/paste the output if you open an issue)') + parser.add_argument('--fields', '--api-doc', default=None, action='store_true', + dest='stdout_fields', help='display fields descriptions') if not WINDOWS: parser.add_argument('--hide-kernel-threads', action='store_true', default=False, dest='no_kernel_threads', help='hide kernel threads in process list (not available on Windows)') diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 1e582dc3e142f3a9ac2475ba2f5eb415e8731a66..781f89b31e26008556f4063a142d120526ff5167 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -29,6 +29,47 @@ from glances.plugins.glances_plugin import GlancesPlugin import psutil +# Fields description +# {'total': 19.7, 'user': 3.4, 'nice': 0.0, 'system': 2.6, 'idle': 93.0, 'iowait': 0.1, 'irq': 0.0, 'softirq': 0.8, 'steal': 0.0, 'guest': 0.0, 'guest_nice': 0.0, 'time_since_update': 2.1306779384613037, 'cpucore': 4, 'ctx_switches': 11636, 'interrupts': 4463, 'soft_interrupts': 3227, 'syscalls': 0} +fields_description = { + 'total': {'description': 'Sum of all CPU percentages (except idle).', + 'unit': 'percent'}, + 'system': {'description': 'percent time spent in kernel space. System CPU time is the \ +time spent running code in the Operating System kernel.', + 'unit': 'percent'}, + 'user': {'description': 'CPU percent time spent in user space. \ +User CPU time is the time spent on the processor running your program\'s code (or code in libraries).', + 'unit': 'percent'}, + 'iowait': {'description': '*(Linux)*: percent time spent by the CPU waiting for I/O \ +operations to complete.', + 'unit': 'percent'}, + 'idle': {'description': 'percent of CPU used by any program. Every program or task \ +that runs on a computer system occupies a certain amount of processing \ +time on the CPU. If the CPU has completed all tasks it is idle.', + 'unit': 'percent'}, + 'irq': {'description': '*(Linux and BSD)*: percent time spent servicing/handling \ +hardware/software interrupts. Time servicing interrupts (hardware + \ +software).', + 'unit': 'percent'}, + 'nice': {'description': '*(Unix)*: percent time occupied by user level processes with \ +a positive nice value. The time the CPU has spent running users\' \ +processes that have been *niced*.', + 'unit': 'percent'}, + 'steal': {'description': '*(Linux)*: percentage of time a virtual CPU waits for a real \ +CPU while the hypervisor is servicing another virtual processor.', + 'unit': 'percent'}, + 'ctx_sw': {'description': 'number of context switches (voluntary + involuntary) per \ +second. A context switch is a procedure that a computer\'s CPU (central \ +processing unit) follows to change from one task (or process) to \ +another while ensuring that the tasks do not conflict.', + 'unit': 'percent'}, + 'inter': {'description': 'number of interrupts per second.', + 'unit': 'percent'}, + 'sw_int': {'description': 'number of software interrupts per second. Always set to \ +0 on Windows and SunOS.', + 'unit': 'percent'}, +} + # SNMP OID # percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0 # percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0 @@ -64,7 +105,8 @@ class Plugin(GlancesPlugin): """Init the CPU plugin.""" super(Plugin, self).__init__(args=args, config=config, - items_history_list=items_history_list) + items_history_list=items_history_list, + fields_description=fields_description) # We want to display the stat in the curse interface self.display_curse = True diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 73cc7fd92e713fe09e7bc984e09c58a83b8137be..48bc9375b6beb38855866d778cc06e4cca4335ec 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -44,7 +44,8 @@ class GlancesPlugin(object): args=None, config=None, items_history_list=None, - stats_init_value={}): + stats_init_value={}, + fields_description=None): """Init the plugin of plugins class. All Glances' plugins should inherit from this class. Most of the @@ -107,6 +108,9 @@ class GlancesPlugin(object): # Set the initial refresh time to display stats the first time self.refresh_timer = Timer(0) + # Init stats description + self.fields_description = fields_description + # Init the stats self.stats_init_value = stats_init_value self.stats = None diff --git a/glances/standalone.py b/glances/standalone.py index d6a07f2f35610d7de62e8ae69d48a8cc9b7207da..f95d79ffda1b7a5b7782ac0e03491db958fcf666 100644 --- a/glances/standalone.py +++ b/glances/standalone.py @@ -30,6 +30,7 @@ from glances.outputs.glances_curses import GlancesCursesStandalone from glances.outputs.glances_stdout import GlancesStdout from glances.outputs.glances_stdout_csv import GlancesStdoutCsv from glances.outputs.glances_stdout_issue import GlancesStdoutIssue +from glances.outputs.glances_stdout_fields import GlancesStdoutFieldsDescription from glances.outdated import Outdated from glances.timer import Counter @@ -87,6 +88,10 @@ class GlancesStandalone(object): logger.info("Issue mode is ON") # Init screen self.screen = GlancesStdoutIssue(config=config, args=args) + elif args.stdout_fields: + logger.info("Fields descriptions mode is ON") + # Init screen + self.screen = GlancesStdoutFieldsDescription(config=config, args=args) elif args.stdout: logger.info("Stdout mode is ON, following stats will be displayed: {}".format(args.stdout)) # Init screen