pull/1238/head
Alessio Sergi 2018-02-15 19:45:45 +01:00
parent 7364b6d4d0
commit 780812d943
9 changed files with 41 additions and 41 deletions

8
NEWS
View File

@ -51,7 +51,7 @@ Backward-incompatible changes:
News command line options:
--disable-webui Disable the WebUI (only Restful API will respond)
--disable-webui Disable the WebUI (only RESTful API will respond)
--enable-light Enable the light mode for the UI interface
--modules-list Display plugins and exporters list
--disable-plugin plugin1,plugin2
@ -106,7 +106,7 @@ Version 2.11
Enhancements and new features:
* New export plugin: standard and configurable Restfull exporter (issue #1129)
* New export plugin: standard and configurable RESTful exporter (issue #1129)
* Add a JSON export module (issue #1130)
* [WIP] Refactoring of the WebUI
@ -631,8 +631,8 @@ Version 2.1
Users can configure alias from the Glances configuration file.
* Add Glances log message (in the /tmp/glances.log file)
The default log level is INFO, you can switch to the DEBUG mode using the -d option on the command line.
* Add RESTFul API to the Web server mode
RestFul API doc: https://github.com/nicolargo/glances/wiki/The-Glances-RESTFULL-JSON-API
* Add RESTful API to the Web server mode
RESTful API doc: https://github.com/nicolargo/glances/wiki/The-Glances-RESTFULL-JSON-API
* Improve SNMP fallback mode for Cisco IOS, VMware ESXi
* Add --theme-white feature to optimize display for white background
* Experimental history feature (--enable-history option on the command line)

View File

@ -75,7 +75,7 @@ Optional dependencies:
- ``pysnmp`` (for SNMP support)
- ``pystache`` (for the action script feature)
- ``pyzmq`` (for the ZeroMQ export module)
- ``requests`` (for the Ports, Cloud plugins and Restful export module)
- ``requests`` (for the Ports, Cloud plugins and RESTful export module)
- ``scandir`` (for the Folders plugin) [Only for Python < 3.5]
- ``statsd`` (for the StatsD export module)
- ``wifi`` (for the wifi plugin) [Linux-only]
@ -355,7 +355,7 @@ Gateway to other services
Glances can export stats to: ``CSV`` file, ``JSON`` file, ``InfluxDB``, ``Cassandra``, ``CouchDB``,
``OpenTSDB``, ``Prometheus``, ``StatsD``, ``ElasticSearch``, ``RabbitMQ/ActiveMQ``,
``ZeroMQ``, ``Kafka``, ``Riemann`` and ``Restful`` server.
``ZeroMQ``, ``Kafka``, ``Riemann`` and ``RESTful`` server.
How to contribute ?
===================

View File

@ -364,7 +364,7 @@ port=8125
[elasticsearch]
# Configuration for the --export elasticsearch option
# Data are available via the ES Restful API. ex: URL/<index>/cpu/system
# Data are available via the ES RESTful API. ex: URL/<index>/cpu/system
# https://www.elastic.co
host=localhost
port=9200
@ -431,7 +431,7 @@ port=9091
prefix=glances
[restful]
# Configuration for the --export restful option
# Configuration for the --export RESTful option
# Example, export to http://localhost:6789/
host=localhost
port=6789

View File

@ -52,7 +52,7 @@ Command-Line Options
.. option:: --disable-webui
disable the Web UI (only the Restful API will respond)
disable the Web UI (only the RESTful API will respond)
.. option:: --light, --enable-light

View File

@ -1,12 +1,12 @@
.. _restful:
Restful
RESTful
=======
You can export statistics to a ``Restful`` JSON server. All the available stats
will be exported in one big (~15 KB) POST request to the Restful endpoint.
You can export statistics to a ``RESTful`` JSON server. All the available stats
will be exported in one big (~15 KB) POST request to the RESTful endpoint.
The Restful endpoint should be defined in the Glances configuration file as
The RESTful endpoint should be defined in the Glances configuration file as
following:
.. code-block:: ini

View File

@ -104,7 +104,7 @@ disable process module (reduce Glances CPU consumption)
.INDENT 0.0
.TP
.B \-\-disable\-webui
disable the Web UI (only the Restful API will respond)
disable the Web UI (only the RESTful API will respond)
.UNINDENT
.INDENT 0.0
.TP

View File

@ -17,7 +17,7 @@
# 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/>.
"""Restful interface class."""
"""RESTful interface class."""
import sys
@ -30,18 +30,18 @@ from requests import post
class Export(GlancesExport):
"""This class manages the Restful export module.
"""This class manages the RESTful export module.
Be aware that stats will be exported in one big POST request"""
def __init__(self, config=None, args=None):
"""Init the Restful export IF."""
"""Init the RESTful export IF."""
super(Export, self).__init__(config=config, args=args)
# Mandatories configuration keys (additional to host and port)
self.protocol = None
self.path = None
# Load the Restful section in the configuration file
# Load the RESTful section in the configuration file
self.export_enable = self.load_conf('restful',
mandatories=['host', 'port', 'protocol', 'path'])
if not self.export_enable:
@ -55,23 +55,23 @@ class Export(GlancesExport):
self.client = self.init()
def init(self):
"""Init the connection to the restful server."""
"""Init the connection to the RESTful server."""
if not self.export_enable:
return None
# Build the Restful URL where the stats will be posted
# Build the RESTful URL where the stats will be posted
url = '{}://{}:{}{}'.format(self.protocol,
self.host,
self.port,
self.path)
logger.info(
"Stats will be exported to the restful endpoint {}".format(url))
"Stats will be exported to the RESTful endpoint {}".format(url))
return url
def export(self, name, columns, points):
"""Export the stats to the Statsd server."""
if name == self.plugins_to_export()[0] and self.buffer != {}:
# One complete loop have been done
logger.debug("Export stats ({}) to Restful endpoint ({})".format(listkeys(self.buffer),
logger.debug("Export stats ({}) to RESTful endpoint ({})".format(listkeys(self.buffer),
self.client))
# Export stats
post(self.client, json=self.buffer, allow_redirects=True)

View File

@ -65,11 +65,11 @@ Examples of use:
Display all Glances modules (plugins and exporters) and exit:
$ glances --module-list
Monitor local machine with the Web interface and start Restful server:
Monitor local machine with the Web interface and start RESTful server:
$ glances -w
Glances web server started on http://0.0.0.0:61208/
Only start Restful API (without the WebUI):
Only start RESTful API (without the WebUI):
$ glances -w --disable-webui
Glances API available on http://0.0.0.0:61208/api/

View File

@ -54,7 +54,7 @@ class GlancesBottle(object):
self.stats = None
# cached_time is the minimum time interval between stats updates
# i.e. HTTP/Restful calls will not retrieve updated info until the time
# i.e. HTTP/RESTful calls will not retrieve updated info until the time
# since last update is passed (will retrieve old cached info instead)
self.timer = Timer(0)
@ -146,7 +146,7 @@ class GlancesBottle(object):
callback=self._api_item_history)
self._app.route('/api/%s/<plugin>/<item>/<value>' % self.API_VERSION, method="GET",
callback=self._api_value)
bindmsg = 'Glances Restful API Server started on {}api/{}/'.format(self.bind_url,
bindmsg = 'Glances RESTful API Server started on {}api/{}/'.format(self.bind_url,
self.API_VERSION)
logger.info(bindmsg)
@ -206,7 +206,7 @@ class GlancesBottle(object):
return static_file(filepath, root=self.STATIC_PATH)
def _api_help(self):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the help data or 404 error.
"""
@ -257,7 +257,7 @@ class GlancesBottle(object):
return plist
def _api_all(self):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of all the plugins
HTTP/200 if OK
@ -285,7 +285,7 @@ class GlancesBottle(object):
return statval
def _api_all_limits(self):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of all the plugins limits
HTTP/200 if OK
@ -302,7 +302,7 @@ class GlancesBottle(object):
return limits
def _api_all_views(self):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of all the plugins views
HTTP/200 if OK
@ -319,7 +319,7 @@ class GlancesBottle(object):
return limits
def _api(self, plugin):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of a given plugin
HTTP/200 if OK
@ -342,7 +342,7 @@ class GlancesBottle(object):
return statval
def _api_history(self, plugin, nb=0):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of a given plugin history
Limit to the last nb items (all if nb=0)
@ -366,7 +366,7 @@ class GlancesBottle(object):
return statval
def _api_limits(self, plugin):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON limits of a given plugin
HTTP/200 if OK
@ -389,7 +389,7 @@ class GlancesBottle(object):
return ret
def _api_views(self, plugin):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON views of a given plugin
HTTP/200 if OK
@ -442,7 +442,7 @@ class GlancesBottle(object):
return ret
def _api_item(self, plugin, item):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of the couple plugin/item
HTTP/200 if OK
@ -453,7 +453,7 @@ class GlancesBottle(object):
return self._api_itemvalue(plugin, item)
def _api_item_history(self, plugin, item, nb=0):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of the couple plugin/history of item
HTTP/200 if OK
@ -464,7 +464,7 @@ class GlancesBottle(object):
return self._api_itemvalue(plugin, item, history=True, nb=int(nb))
def _api_value(self, plugin, item, value):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the process stats (dict) for the given item=value
HTTP/200 if OK
@ -474,7 +474,7 @@ class GlancesBottle(object):
return self._api_itemvalue(plugin, item, value)
def _api_config(self):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of the Glances configuration file
HTTP/200 if OK
@ -490,7 +490,7 @@ class GlancesBottle(object):
return args_json
def _api_config_item(self, item):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of the Glances configuration item
HTTP/200 if OK
@ -511,7 +511,7 @@ class GlancesBottle(object):
return args_json
def _api_args(self):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of the Glances command line arguments
HTTP/200 if OK
@ -529,7 +529,7 @@ class GlancesBottle(object):
return args_json
def _api_args_item(self, item):
"""Glances API RESTFul implementation.
"""Glances API RESTful implementation.
Return the JSON representation of the Glances command line arguments item
HTTP/200 if OK