summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2023-12-16 15:00:04 +0100
committernicolargo <nicolas@nicolargo.com>2023-12-16 15:00:04 +0100
commitb3828f549750405b316a38d4796087ee3a815882 (patch)
tree8d97684b0c3ab402a062e59471c03cb8cc7bfd9f
parent32b33b588380df490d0399aaf653200b26d83386 (diff)
Replace Bottle by FastAPI #2181
-rw-r--r--Makefile2
-rw-r--r--glances/events.py6
-rw-r--r--glances/exports/couchdb/__init__.py7
-rw-r--r--glances/exports/export.py2
-rw-r--r--glances/folder_list.py12
-rw-r--r--glances/globals.py2
-rw-r--r--glances/main.py2
-rw-r--r--glances/outputs/glances_curses.py25
-rw-r--r--glances/outputs/glances_restful_api.py297
-rw-r--r--glances/outputs/glances_stdout_apidoc.py4
-rw-r--r--glances/plugins/alert/__init__.py8
-rw-r--r--glances/plugins/folders/__init__.py3
-rw-r--r--glances/plugins/gpu/__init__.py7
-rw-r--r--glances/plugins/help/__init__.py30
-rw-r--r--glances/plugins/mem/__init__.py5
-rw-r--r--glances/plugins/processlist/__init__.py8
-rw-r--r--glances/processes.py5
-rw-r--r--glances/programs.py6
-rw-r--r--glances/stats.py7
19 files changed, 208 insertions, 230 deletions
diff --git a/Makefile b/Makefile
index 1963c931..c8f84a07 100644
--- a/Makefile
+++ b/Makefile
@@ -102,7 +102,7 @@ codespell: ## Run codespell to fix common misspellings in text files
./venv-dev/bin/codespell -S .git,./docs/_build,./Glances.egg-info,./venv*,./glances/outputs,*.svg -L hart,bu,te,statics
semgrep: ## Run semgrep to find bugs and enforce code standards
- ./venv-dev/bin/semgrep --config=auto --lang python --use-git-ignore ./glances
+ ./venv-dev/bin/semgrep scan --config=auto
profiling: ## How to start the profiling of the Glances software
@echo "Please complete and run: sudo ./venv-dev/bin/py-spy record -o ./docs/_static/glances-flame.svg -d 60 -s --pid <GLANCES PID>"
diff --git a/glances/events.py b/glances/events.py
index 956364f3..2dbc5100 100644
--- a/glances/events.py
+++ b/glances/events.py
@@ -13,7 +13,6 @@ import time
from datetime import datetime
from glances.processes import glances_processes, sort_stats
-from glances.logger import logger
class GlancesEvents(object):
@@ -109,8 +108,7 @@ class GlancesEvents(object):
self._create_event(event_state, event_type, event_value, proc_desc)
else:
# Event exist, update it
- self._update_event(event_index,
- event_state, event_type, event_value, proc_list, proc_desc, peak_time)
+ self._update_event(event_index, event_state, event_type, event_value, proc_list, proc_desc, peak_time)
return self.len()
@@ -130,7 +128,7 @@ class GlancesEvents(object):
time.mktime(datetime.now().timetuple()), # START DATE
-1, # END DATE
event_state, # STATE: WARNING|CRITICAL
- event_type, # TYPE: CPU, LOAD, MEM...
+ event_type, # TYPE: CPU, LOAD, MEM...
event_value, # MAX
event_value, # AVG
event_value, # MIN
diff --git a/glances/exports/couchdb/__init__.py b/glances/exports/couchdb/__init__.py
index 7f3a216a..5cc65529 100644
--- a/glances/exports/couchdb/__init__.py
+++ b/glances/exports/couchdb/__init__.py
@@ -36,9 +36,7 @@ class Export(GlancesExport):
# Load the CouchDB configuration file section
# User and Password are mandatory with CouchDB 3.0 and higher
- self.export_enable = self.load_conf('couchdb',
- mandatories=['host', 'port', 'db',
- 'user', 'password'])
+ self.export_enable = self.load_conf('couchdb', mandatories=['host', 'port', 'db', 'user', 'password'])
if not self.export_enable:
sys.exit(2)
@@ -51,8 +49,7 @@ class Export(GlancesExport):
return None
# @TODO: https
- server_uri = 'http://{}:{}@{}:{}/'.format(self.user, self.password,
- self.host, self.port)
+ server_uri = 'http://{}:{}@{}:{}/'.format(self.user, self.password, self.host, self.port)
try:
s = pycouchdb.Server(server_uri)
diff --git a/glances/exports/export.py b/glances/exports/export.py
index 914db71c..45a08c77 100644
--- a/glances/exports/export.py
+++ b/glances/exports/export.py
@@ -36,7 +36,7 @@ class GlancesExport(object):
'processlist',
'psutilversion',
'quicklook',
- 'version'
+ 'version',
]
def __init__(self, config=None, args=None):
diff --git a/glances/folder_list.py b/glances/folder_list.py
index 2dccab93..595c536f 100644
--- a/glances/folder_list.py
+++ b/glances/folder_list.py
@@ -10,7 +10,6 @@
"""Manage the folder list."""
from __future__ import unicode_literals
-import os
from glances.timer import Timer
from glances.globals import nativestr, folder_size
@@ -132,11 +131,12 @@ class FolderList(object):
# Get folder size
self.__folder_list[i]['size'], self.__folder_list[i]['errno'] = folder_size(self.path(i))
if self.__folder_list[i]['errno'] != 0:
- logger.debug('Folder size ({} ~ {}) may not be correct. Error: {}'.format(
- self.path(i),
- self.__folder_list[i]['size'],
- self.__folder_list[i]['errno']))
- # Reset the timer
+ logger.debug(
+ 'Folder size ({} ~ {}) may not be correct. Error: {}'.format(
+ self.path(i), self.__folder_list[i]['size'], self.__folder_list[i]['errno']
+ )
+ )
+ # Reset the timer
self.timer_folders[i].reset()
# It is no more the first time...
diff --git a/glances/globals.py b/glances/globals.py
index 46f47f7b..315d0d57 100644
--- a/glances/globals.py
+++ b/glances/globals.py
@@ -413,8 +413,8 @@ def folder_size(path, errno=0):
def weak_lru_cache(maxsize=128, typed=False):
"""LRU Cache decorator that keeps a weak reference to self
Source: https://stackoverflow.com/a/55990799"""
- def wrapper(func):
+ def wrapper(func):
@functools.lru_cache(maxsize, typed)
def _func(_self, *args, **kwargs):
return func(_self(), *args, **kwargs)
diff --git a/glances/main.py b/glances/main.py
index 6a449aa5..5fe92471 100644
--- a/glances/main.py
+++ b/glances/main.py
@@ -134,7 +134,7 @@ Examples of use:
'--enable-plugins',
'--enable',
dest='enable_plugin',
- help='enable plugin (comma-separated list)'
+ help='enable plugin (comma-separated list)',
)
parser.add_argument(
'--disable-process',
diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py
index f5ba10ad..f4e70c81 100644
--- a/glances/outputs/glances_curses.py
+++ b/glances/outputs/glances_curses.py
@@ -101,15 +101,7 @@ class _GlancesCurses(object):
_sort_loop = sort_processes_key_list
# Define top menu
- _top = [
- 'quicklook',
- 'cpu',
- 'percpu',
- 'gpu',
- 'mem',
- 'memswap',
- 'load'
- ]
+ _top = ['quicklook', 'cpu', 'percpu', 'gpu', 'mem', 'memswap', 'load']
_quicklook_max_width = 68
# Define left sidebar
@@ -131,13 +123,7 @@ class _GlancesCurses(object):
_left_sidebar_max_width = 34
# Define right sidebar
- _right_sidebar = [
- 'containers',
- 'processcount',
- 'amps',
- 'processlist',
- 'alert'
- ]
+ _right_sidebar = ['containers', 'processcount', 'amps', 'processlist', 'alert']
def __init__(self, config=None, args=None):
# Init
@@ -301,8 +287,7 @@ class _GlancesCurses(object):
if curses.COLORS > 8:
# ex: export TERM=xterm-256color
- colors_list = [curses.COLOR_CYAN,
- curses.COLOR_YELLOW]
+ colors_list = [curses.COLOR_CYAN, curses.COLOR_YELLOW]
for i in range(0, 3):
try:
curses.init_pair(i + 9, colors_list[i], -1)
@@ -462,9 +447,7 @@ class _GlancesCurses(object):
)
def _handle_sort_key(self, hotkey):
- glances_processes.set_sort_key(
- self._hotkeys[hotkey]['sort_key'], self._hotkeys[hotkey]['sort_key'] == 'auto'
- )
+ glances_processes.set_sort_key(self._hotkeys[hotkey]['sort_key'], self._hotkeys[hotkey]['sort_key'] == 'auto')
def _handle_enter(self):
self.edit_filter = not self.edit_filter
diff --git a/glances/outputs/glances_restful_api.py b/glances/outputs/glances_restful_api.py
index 02a86cf8..f4dfde6d 100644
--- a/glances/outputs/glances_restful_api.py
+++ b/glances/outputs/glances_restful_api.py
@@ -16,6 +16,7 @@ from io import open
import webbrowser
import socket
from urllib.parse import urljoin
+
# Replace typing_extensions by typing when Python 3.8 support will be dropped
# from typing import Annotated
from typing_extensions import Annotated
@@ -72,15 +73,12 @@ class GlancesRestfulApi(object):
self.load_config(config)
# Set the bind URL
- self.bind_url = urljoin('http://{}:{}/'.format(self.args.bind_address,
- self.args.port),
- self.url_prefix)
+ self.bind_url = urljoin('http://{}:{}/'.format(self.args.bind_address, self.args.port), self.url_prefix)
# FastAPI Init
if self.args.password:
self._app = FastAPI(dependencies=[Depends(self.authentication)])
- self._password = GlancesPassword(username=args.username,
- config=config)
+ self._password = GlancesPassword(username=args.username, config=config)
else:
self._app = FastAPI()
@@ -100,9 +98,7 @@ class GlancesRestfulApi(object):
self._app.add_middleware(
CORSMiddleware,
# allow_origins=["*"],
- allow_origins=[
- self.bind_url
- ],
+ allow_origins=[self.bind_url],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
@@ -110,8 +106,7 @@ class GlancesRestfulApi(object):
# FastAPI Enable GZIP compression
# https://fastapi.tiangolo.com/advanced/middleware/
- self._app.add_middleware(GZipMiddleware,
- minimum_size=1000)
+ self._app.add_middleware(GZipMiddleware, minimum_size=1000)
# FastAPI Define routes
self._app.include_router(self._router())
@@ -139,8 +134,7 @@ class GlancesRestfulApi(object):
"""Check if a username/password combination is valid."""
if creds.username == self.args.username:
# check_password and get_hash are (lru) cached to optimize the requests
- if self._password.check_password(self.args.password,
- self._password.get_hash(creds.password)):
+ if self._password.check_password(self.args.password, self._password.get_hash(creds.password)):
return creds.username
# If the username/password combination is invalid, return an HTTP 401
@@ -155,74 +149,80 @@ class GlancesRestfulApi(object):
router = APIRouter()
# REST API
- router.add_api_route('/api/%s/status' % self.API_VERSION,
- status_code=status.HTTP_200_OK,
- response_class=ORJSONResponse,
- endpoint=self._api_status)
-
- router.add_api_route('/api/%s/config' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_config)
- router.add_api_route('/api/%s/config/{section}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_config_section)
- router.add_api_route('/api/%s/config/{section}/{item}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_config_section_item)
-
- router.add_api_route('/api/%s/args' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_args)
- router.add_api_route('/api/%s/args/{item}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_args_item)
-
- router.add_api_route('/api/%s/pluginslist' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_plugins)
- router.add_api_route('/api/%s/all' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_all)
- router.add_api_route('/api/%s/all/limits' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_all_limits)
- router.add_api_route('/api/%s/all/views' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_all_views)
-
- router.add_api_route('/api/%s/help' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_help)
- router.add_api_route('/api/%s/{plugin}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api)
- router.add_api_route('/api/%s/{plugin}/history' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_history)
- router.add_api_route('/api/%s/{plugin}/history/{nb}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_history)
- router.add_api_route('/api/%s/{plugin}/top/{nb}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_top)
- router.add_api_route('/api/%s/{plugin}/limits' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_limits)
- router.add_api_route('/api/%s/{plugin}/views' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_views)
- router.add_api_route('/api/%s/{plugin}/{item}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_item)
- router.add_api_route('/api/%s/{plugin}/{item}/history' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_item_history)
- router.add_api_route('/api/%s/{plugin}/{item}/history/{nb}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_item_history)
- router.add_api_route('/api/%s/{plugin}/{item}/{value}' % self.API_VERSION,
- response_class=ORJSONResponse,
- endpoint=self._api_value)
+ router.add_api_route(
+ '/api/%s/status' % self.API_VERSION,
+ status_code=status.HTTP_200_OK,
+ response_class=ORJSONResponse,
+ endpoint=self._api_status,
+ )
+
+ router.add_api_route(
+ '/api/%s/config' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_config
+ )
+ router.add_api_route(
+ '/api/%s/config/{section}' % self.API_VERSION,
+ response_class=ORJSONResponse,
+ endpoint=self._api_config_section,
+ )
+ router.add_api_route(
+ '/api/%s/config/{section}/{item}' % self.API_VERSION,
+ response_class=ORJSONResponse,
+ endpoint=self._api_config_section_item,
+ )
+
+ router.add_api_route('/api/%s/args' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_args)
+ router.add_api_route(
+ '/api/%s/args/{item}' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_args_item
+ )
+
+ router.add_api_route(
+ '/api/%s/pluginslist' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_plugins
+ )
+ router.add_api_route('/api/%s/all' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_all)
+ router.add_api_route(
+ '/api/%s/all/limits' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_all_limits
+ )
+ router.add_api_route(
+ '/api/%s/all/views' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_all_views
+ )
+
+ router.add_api_route('/api/%s/help' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_help)
+ router.add_api_route('/api/%s/{plugin}' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api)
+ router.add_api_route(
+ '/api/%s/{plugin}/history' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_history
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/history/{nb}' % self.API_VERSION,
+ response_class=ORJSONResponse,
+ endpoint=self._api_history,
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/top/{nb}' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_top
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/limits' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_limits
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/views' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_views
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/{item}' % self.API_VERSION, response_class=ORJSONResponse, endpoint=self._api_item
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/{item}/history' % self.API_VERSION,
+ response_class=ORJSONResponse,
+ endpoint=self._api_item_history,
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/{item}/history/{nb}' % self.API_VERSION,
+ response_class=ORJSONResponse,
+ endpoint=self._api_item_history,
+ )
+ router.add_api_route(
+ '/api/%s/{plugin}/{item}/{value}' % self.API_VERSION,
+ response_class=ORJSONResponse,
+ endpoint=self._api_value,
+ )
# Restful API
bindmsg = 'Glances RESTful API Server started on {}api/{}'.format(self.bind_url, self.API_VERSION)
@@ -231,14 +231,10 @@ class GlancesRestfulApi(object):
# WEB UI
if not self.args.disable_webui:
# Template for the root index.html file
- router.add_api_route('/',
- response_class=HTMLResponse,
- endpoint=self._index)
+ router.add_api_route('/', response_class=HTMLResponse, endpoint=self._index)
# Statics files
- self._app.mount("/static",
- StaticFiles(directory=self.STATIC_PATH),
- name="static")
+ self._app.mount("/static", StaticFiles(directory=self.STATIC_PATH), name="static")
bindmsg = 'Glances Web User Interface started on {}'.format(self.bind_url)
else:
@@ -267,10 +263,7 @@ class GlancesRestfulApi(object):
# Run the Web application
try:
- uvicorn.run(self._app,
- host=self.args.bind_address,
- port=self.args.port,
- access_log=self.args.debug)
+ uvicorn.run(self._app, host=self.args.bind_address, port=self.args.port, access_log=self.args.debug)
except socket.error as e:
logger.critical('Error: Can not ran Glances Web server ({})'.format(e))
@@ -286,18 +279,19 @@ class GlancesRestfulApi(object):
Note: This function is only called the first time the page is loaded.
"""
- refresh_time = request.query_params.get('refresh',
- default=max(1, int(self.args.time)))
+ refresh_time = request.query_params.get('refresh', default=max(1, int(self.args.time)))
# Update the stat
self.__update__()
# Display
- return self._templates.TemplateResponse("index.html",
- {
- "request": request,
- "refresh_time": refresh_time,
- })
+ return self._templates.TemplateResponse(
+ "index.html",
+ {
+ "request": request,
+ "refresh_time": refresh_time,
+ },
+ )
def _api_status(self):
"""Glances API RESTful implementation.
@@ -318,9 +312,7 @@ class GlancesRestfulApi(object):
try:
plist = self.stats.get_plugin("help").get_view_data()
except Exception as e:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get help view data (%s)" % str(e))
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get help view data (%s)" % str(e))
return ORJSONResponse(plist)
@@ -356,9 +348,7 @@ class GlancesRestfulApi(object):
try:
plist = self.plugins_list
except Exception as e:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get plugin list (%s)" % str(e))
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get plugin list (%s)" % str(e))
return ORJSONResponse(plist)
@@ -385,9 +375,7 @@ class GlancesRestfulApi(object):
# Get the RAW value of the stat ID
statval = self.stats.getAllAsDict()
except Exception as e:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get stats (%s)" % str(e))
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get stats (%s)" % str(e))
return ORJSONResponse(statval)
@@ -403,9 +391,7 @@ class GlancesRestfulApi(object):
# Get the RAW value of the stat limits
limits = self.stats.getAllLimitsAsDict()
except Exception as e:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get limits (%s)" % str(e))
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get limits (%s)" % str(e))
return ORJSONResponse(limits)
@@ -421,9 +407,7 @@ class GlancesRestfulApi(object):
# Get the RAW value of the stat view
limits = self.stats.getAllViewsAsDict()
except Exception as e:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get views (%s)" % str(e))
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get views (%s)" % str(e))
return ORJSONResponse(limits)
@@ -438,7 +422,8 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
# Update the stat
self.__update__()
@@ -448,8 +433,8 @@ class GlancesRestfulApi(object):
statval = self.stats.get_plugin(plugin).get_raw()
except Exception as e:
raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get plugin %s (%s)" % (plugin, str(e)))
+ status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get plugin %s (%s)" % (plugin, str(e))
+ )
return ORJSONResponse(statval)
@@ -466,7 +451,8 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
# Update the stat
self.__update__()
@@ -476,8 +462,8 @@ class GlancesRestfulApi(object):
statval = self.stats.get_plugin(plugin).get_export()
except Exception as e:
raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get plugin %s (%s)" % (plugin, str(e)))
+ status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get plugin %s (%s)" % (plugin, str(e))
+ )
if isinstance(statval, list):
statval = statval[:nb]
@@ -496,7 +482,8 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
# Update the stat
self.__update__()
@@ -506,8 +493,8 @@ class GlancesRestfulApi(object):
statval = self.stats.get_plugin(plugin).get_raw_history(nb=int(nb))
except Exception as e:
raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get plugin history %s (%s)" % (plugin, str(e)))
+ status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get plugin history %s (%s)" % (plugin, str(e))
+ )
return statval
@@ -522,15 +509,16 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
try:
# Get the RAW value of the stat limits
ret = self.stats.get_plugin(plugin).limits
except Exception as e:
raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get limits for plugin %s (%s)" % (plugin, str(e)))
+ status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get limits for plugin %s (%s)" % (plugin, str(e))
+ )
return ORJSONResponse(ret)
@@ -545,15 +533,16 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
try:
# Get the RAW value of the stat views
ret = self.stats.get_plugin(plugin).get_views()
except Exception as e:
raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get views for plugin %s (%s)" % (plugin, str(e)))
+ status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get views for plugin %s (%s)" % (plugin, str(e))
+ )
return ORJSONResponse(ret)
@@ -568,7 +557,8 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
# Update the stat
self.__update__()
@@ -579,7 +569,8 @@ class GlancesRestfulApi(object):
except Exception as e:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get item %s in plugin %s (%s)" % (item, plugin, str(e)))
+ detail="Cannot get item %s in plugin %s (%s)" % (item, plugin, str(e)),
+ )
return ORJSONResponse(ret)
@@ -595,7 +586,8 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
# Update the stat
self.__update__()
@@ -605,8 +597,8 @@ class GlancesRestfulApi(object):
ret = self.stats.get_plugin(plugin).get_raw_history(item, nb=nb)
except Exception as e:
raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get history for plugin %s (%s)" % (plugin, str(e)))
+ status_code=status.HTTP_404_NOT_FOUND, detail="Cannot get history for plugin %s (%s)" % (plugin, str(e))
+ )
return ORJSONResponse(ret)
@@ -621,7 +613,8 @@ class GlancesRestfulApi(object):
if plugin not in self.plugins_list:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
- detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
+ detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
+ )
# Update the stat
self.__update__()
@@ -632,7 +625,8 @@ class GlancesRestfulApi(object):
except Exception as e:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
- detail="Cannot get %s = %s for plugin %s (%s)" % (item, value, plugin, str(e)))
+ detail="Cannot get %s = %s for plugin %s (%s)" % (item, value, plugin, str(e)),
+ )