diff --git a/glances/exports/glances_restful.py b/glances/exports/glances_restful.py index 8abe5f6fb627816f513fdfb596186a728b18bb6e..64f8f5e0fb23c0c707540e7a71fb27b2c79bd621 100644 --- a/glances/exports/glances_restful.py +++ b/glances/exports/glances_restful.py @@ -20,9 +20,7 @@ """Restful interface class.""" import sys -from numbers import Number -from glances.compat import range from glances.logger import logger from glances.exports.glances_export import GlancesExport @@ -31,7 +29,8 @@ 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.""" @@ -47,6 +46,10 @@ class Export(GlancesExport): if not self.export_enable: sys.exit(2) + # Init the stats buffer + # It's a dict of stats + self.buffer = {} + # Init the Statsd client self.client = self.init() @@ -65,16 +68,13 @@ class Export(GlancesExport): def export(self, name, columns, points): """Export the stats to the Statsd server.""" - post(self.client, json=dict(zip(columns, points)), allow_redirects=True) - logger.debug("Export {} stats to Restful endpoint".format(name)) - - -def normalize(name): - """Normalize name for the Statsd convention""" - - # Name should not contain some specials chars (issue #1068) - ret = name.replace(':', '') - ret = ret.replace('%', '') - ret = ret.replace(' ', '_') - - return ret + if name in self.buffer: + # One complete loop have been done + # 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))