提交 e798fb4f 编写于 作者: N nicolargo

Add API doc for CPU (not completed)

上级 d650913c
......@@ -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:
......
......@@ -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)')
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册