Get specific item

pull/1906/head
nicolargo 2021-07-16 15:39:24 +02:00
parent a0aa5b479d
commit 04bad352e6
7 changed files with 12 additions and 96 deletions

View File

@ -48,6 +48,9 @@ run-debug: venv
run-webserver: venv
./venv/bin/python -m glances -C ./conf/glances.conf -w
run-restapiserver: venv
./venv/bin/python -m glances -C ./conf/glances.conf -w --disable-webui
run-server: venv
./venv/bin/python -m glances -C ./conf/glances.conf -s

View File

@ -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 or args.stdout_fields:
if args.stdout_issue or args.stdout_apidoc:
# Serve once for issue/test mode
mode.serve_issue()
else:

View File

@ -230,8 +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')
parser.add_argument('--api-doc', default=None, action='store_true',
dest='stdout_apidoc', 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)')

View File

@ -1,84 +0,0 @@
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2021 Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Fields description interface class."""
from pprint import pformat
from glances.logger import logger
from glances.compat import iteritems
class GlancesStdoutFieldsDescription(object):
"""
This class manages the fields description display.
"""
def __init__(self, config=None, args=None):
# Init
self.config = config
self.args = args
def end(self):
pass
def update(self,
stats,
duration=3):
"""Display issue
"""
print('.. _apidoc:')
print('')
print('Restfull/API plugins documentation')
print('==================================')
print('')
print('The Glances Restfull/API server could be ran using the following command line:')
print('')
print('.. code-block:: bash')
print('')
print(' # glances -w --disable-webui')
print('')
for plugin in sorted(stats._plugins):
if stats._plugins[plugin].fields_description:
print('{}'.format(plugin))
print('-' * len(plugin))
print('')
for field, description in iteritems(stats._plugins[plugin].fields_description):
print('* **{}**: {} (unit is *{}*)'.format(field,
description['description'][:-1] if description['description'].endswith('.') else description['description'],
description['unit']))
print('')
print('GET {} plugin stats:'.format(plugin))
print('')
print('.. code-block:: json')
print('')
print(' # curl http://localhost:61208/api/3/{}'.format(plugin))
stat = stats._plugins[plugin].get_export()
if isinstance(stat, list) and len(stat) > 1:
# Only display two first items
print(' ' + pformat(stat[0:2]).replace('\n', '\n '))
else:
print(' ' + pformat(stat).replace('\n', '\n '))
print('')
else:
logger.error('No fields_description variable defined for plugin {}'.format(plugin))
# Return True to exit directly (no refresh)
return True

View File

@ -26,12 +26,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# Fields description
# total: total swap memory in bytes
# used: used swap memory in bytes
# free: free swap memory in bytes
# percent: the percentage usage
# sin: the number of bytes the system has swapped in from disk (cumulative)
# sout: the number of bytes the system has swapped out from disk (cumulative)
fields_description = {
'total': {'description': 'Total swap memory.',
'unit': 'bytes'},

View File

@ -363,6 +363,9 @@ class GlancesProcesses(object):
first = False
# /End of extended stats
# PID is the key
proc['key'] = 'pid'
# Time since last update (for disk_io rate computation)
proc['time_since_update'] = time_since_update

View File

@ -30,7 +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.outputs.glances_stdout_apidoc import GlancesStdoutApiDoc
from glances.outdated import Outdated
from glances.timer import Counter
@ -88,10 +88,10 @@ class GlancesStandalone(object):
logger.info("Issue mode is ON")
# Init screen
self.screen = GlancesStdoutIssue(config=config, args=args)
elif args.stdout_fields:
elif args.stdout_apidoc:
logger.info("Fields descriptions mode is ON")
# Init screen
self.screen = GlancesStdoutFieldsDescription(config=config, args=args)
self.screen = GlancesStdoutApiDoc(config=config, args=args)
elif args.stdout:
logger.info("Stdout mode is ON, following stats will be displayed: {}".format(args.stdout))
# Init screen