Web server status check endpoint #1988

This commit is contained in:
nicolargo 2022-01-15 11:33:14 +01:00
parent 0659e59e3a
commit 8d4a20a6a8
4 changed files with 446 additions and 447 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "Nov 28, 2021" "3.2.5_beta01" "Glances"
.TH "GLANCES" "1" "Jan 15, 2022" "3.2.5_beta01" "Glances"
.SH NAME
glances \- An eye on your system
.
@ -879,6 +879,6 @@ $ glances browser
.sp
Nicolas Hennion aka Nicolargo <\fI\%contact@nicolargo.com\fP>
.SH COPYRIGHT
2021, Nicolas Hennion
2022, Nicolas Hennion
.\" Generated by docutils manpage writer.
.

View File

@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# Copyright (C) 2019 Nicolargo <nicolas@nicolargo.com>
# Copyright (C) 2022 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
@ -12,7 +12,7 @@
# 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.
# GNU Lesser General Public License 1for 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/>.
@ -145,6 +145,7 @@ class GlancesBottle(object):
def _route(self):
"""Define route."""
# REST API
self._app.route('/api/%s/status' % self.API_VERSION, method="GET", callback=self._api_status)
self._app.route('/api/%s/config' % self.API_VERSION, method="GET", callback=self._api_config)
self._app.route('/api/%s/config/<item>' % self.API_VERSION, method="GET", callback=self._api_config_item)
self._app.route('/api/%s/args' % self.API_VERSION, method="GET", callback=self._api_args)
@ -226,6 +227,19 @@ class GlancesBottle(object):
# Return the static file
return static_file(filepath, root=self.STATIC_PATH)
@compress
def _api_status(self):
"""Glances API RESTful implementation.
Return a 200 status code.
This entry point should be used to check the API health.
See related issue: Web server health check endpoint #1988
"""
response.status = 200
return None
@compress
def _api_help(self):
"""Glances API RESTful implementation.

View File

@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# Copyright (C) 2021 Nicolargo <nicolas@nicolargo.com>
# Copyright (C) 2022 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
@ -53,12 +53,28 @@ def indent_stat(stat, indent=' '):
return indent + pformat(stat).replace('\n', '\n' + indent)
def print_api_status():
sub_title = 'GET API status'
print(sub_title)
print('-' * len(sub_title))
print('')
print('This entry point should be used to check the API status.')
print('It will return nothing but a 200 return code if everythin is OK.')
print('')
print('Get the Rest API status:')
print('')
print(' # curl -I {}/status'.format(API_URL))
print(indent_stat('HTTP/1.0 200 OK'))
print('')
def print_plugins_list(stat):
sub_title = 'GET plugins list'
print(sub_title)
print('-' * len(sub_title))
print('')
print('Get the plugins list::')
print('Get the plugins list:')
print('')
print(' # curl {}/pluginslist'.format(API_URL))
print(indent_stat(stat))
@ -71,7 +87,7 @@ def print_plugin_export(plugin, stat_export):
print('-' * len(sub_title))
print('')
print('Get plugin stats::')
print('Get plugin stats:')
print('')
print(' # curl {}/{}'.format(API_URL, plugin))
print(indent_stat(stat_export))
@ -115,7 +131,7 @@ def print_plugin_item_value(plugin, stat, stat_export):
value = stat_item[item][0]
else:
value = stat_item[item]
print('Get a specific field::')
print('Get a specific field:')
print('')
print(' # curl {}/{}/{}'.format(API_URL, plugin, item))
print(indent_stat(stat_item))
@ -133,7 +149,7 @@ def print_all():
print(sub_title)
print('-' * len(sub_title))
print('')
print('Get all Glances stats::')
print('Get all Glances stats:')
print('')
print(' # curl {}/all'.format(API_URL))
print(' Return a very big dictionnary (avoid using this request, performances will be poor)...')
@ -149,17 +165,17 @@ def print_history(stats):
print(sub_title)
print('-' * len(sub_title))
print('')
print('History of a plugin::')
print('History of a plugin:')
print('')
print(' # curl {}/cpu/history'.format(API_URL))
print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history(nb=3))))
print('')
print('Limit history to last 2 values::')
print('Limit history to last 2 values:')
print('')
print(' # curl {}/cpu/history/2'.format(API_URL))
print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history(nb=2))))
print('')
print('History for a specific field::')
print('History for a specific field:')
print('')
print(' # curl {}/cpu/system/history'.format(API_URL))
print(indent_stat(json.loads(stats.get_plugin('cpu').get_stats_history('system'))))
@ -176,12 +192,12 @@ def print_limits(stats):
print(sub_title)
print('-' * len(sub_title))
print('')
print('All limits/thresholds::')
print('All limits/thresholds:')
print('')
print(' # curl {}/all/limits'.format(API_URL))
print(indent_stat(stats.getAllLimitsAsDict()))
print('')
print('Limits/thresholds for the cpu plugin::')
print('Limits/thresholds for the cpu plugin:')
print('')
print(' # curl {}/cpu/limits'.format(API_URL))
print(indent_stat(stats.get_plugin('cpu').limits))
@ -206,6 +222,9 @@ class GlancesStdoutApiDoc(object):
# Display header
print(APIDOC_HEADER)
# Display API status
print_api_status()
# Display plugins list
print_plugins_list(sorted(stats._plugins))