提交 4ffad89e 编写于 作者: N nicolargo

New export plugin: standard and configurable Restfull exporter #1129

上级 23676e1d
......@@ -8,6 +8,7 @@ Version NEXT RELEASE
Enhancements and new features:
* [WIP] Refactoring of the WebUI
* New export plugin: standard and configurable Restfull exporter (issue #1129)
Bugs corrected:
......
......@@ -73,7 +73,7 @@ Optional dependencies:
- ``pysnmp`` (for SNMP support)
- ``pystache`` (for the action script feature)
- ``pyzmq`` (for the ZeroMQ export module)
- ``requests`` (for the Ports and Cloud plugins)
- ``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]
......@@ -353,7 +353,7 @@ Gateway to other services
Glances can export stats to: ``CSV`` file, ``InfluxDB``, ``Cassandra``, ``CouchDB``,
``OpenTSDB``, ``Prometheus``, ``StatsD``, ``ElasticSearch``, ``RabbitMQ/ActiveMQ``,
``ZeroMQ``, ``Kafka`` and ``Riemann`` server.
``ZeroMQ``, ``Kafka``, ``Riemann`` and ``Restful`` server.
How to contribute ?
===================
......
......@@ -18,6 +18,7 @@ to providing stats to multiple services (see list below).
opentsdb
prometheus
rabbitmq
restful
riemann
statsd
zeromq
.. _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.
The Restful endpoint should be defined in the Glances configuration file as
following:
.. code-block:: ini
[restful]
# Configuration for the --export-restful option
# Example, export to http://localhost:6789/
host=localhost
port=6789
protocol=http
path=/
URL Syntax:
.. code-block:: ini
http://localhost:6789/
| | | |
| | | path
| | port
| hostname
host
and run Glances with:
.. code-block:: console
$ glances --export-restful
Glances will generate stats as a big JSON dictionary (see example `here`_).
.. _here: https://pastebin.com/7U3vXqvF
.\" Man page generated from reStructuredText.
.
.TH "GLANCES" "1" "Jun 27, 2017" "2.10.1_DEVELOP" "Glances"
.TH "GLANCES" "1" "Jul 30, 2017" "2.10.1_DEVELOP" "Glances"
.SH NAME
glances \- An eye on your system
.
......
......@@ -23,6 +23,8 @@ I am your father...
...for all Glances exports IF.
"""
import json
from glances.compat import NoOptionError, NoSectionError, iteritems, iterkeys
from glances.logger import logger
......@@ -182,6 +184,8 @@ class GlancesExport(object):
pre_key = ''
# Walk through the dict
for key, value in iteritems(stats):
if isinstance(value, bool):
value = json.dumps(value)
if isinstance(value, list):
try:
value = value[0]
......
......@@ -21,6 +21,7 @@
import sys
from glances.compat import listkeys
from glances.logger import logger
from glances.exports.glances_export import GlancesExport
......@@ -63,18 +64,19 @@ class Export(GlancesExport):
self.port,
self.path)
logger.info(
"Stats will be exported to the restful URL: {}".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 in self.buffer:
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),
self.client))
# Export stats
post(self.client, json=self.buffer, allow_redirects=True)
# Reset buffer
self.buffer = {}
logger.debug("Export stats to Restful endpoint ({})".format(self.client))
# Add current stat to the buffer
self.buffer[name] = dict(zip(columns, points))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册