mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-02 22:54:49 +03:00
One post only
This commit is contained in:
parent
e372fa2b07
commit
23676e1d76
@ -20,9 +20,7 @@
|
|||||||
"""Restful interface class."""
|
"""Restful interface class."""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from numbers import Number
|
|
||||||
|
|
||||||
from glances.compat import range
|
|
||||||
from glances.logger import logger
|
from glances.logger import logger
|
||||||
from glances.exports.glances_export import GlancesExport
|
from glances.exports.glances_export import GlancesExport
|
||||||
|
|
||||||
@ -31,7 +29,8 @@ from requests import post
|
|||||||
|
|
||||||
class Export(GlancesExport):
|
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):
|
def __init__(self, config=None, args=None):
|
||||||
"""Init the Restful export IF."""
|
"""Init the Restful export IF."""
|
||||||
@ -47,6 +46,10 @@ class Export(GlancesExport):
|
|||||||
if not self.export_enable:
|
if not self.export_enable:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
# Init the stats buffer
|
||||||
|
# It's a dict of stats
|
||||||
|
self.buffer = {}
|
||||||
|
|
||||||
# Init the Statsd client
|
# Init the Statsd client
|
||||||
self.client = self.init()
|
self.client = self.init()
|
||||||
|
|
||||||
@ -65,16 +68,13 @@ class Export(GlancesExport):
|
|||||||
|
|
||||||
def export(self, name, columns, points):
|
def export(self, name, columns, points):
|
||||||
"""Export the stats to the Statsd server."""
|
"""Export the stats to the Statsd server."""
|
||||||
post(self.client, json=dict(zip(columns, points)), allow_redirects=True)
|
if name in self.buffer:
|
||||||
logger.debug("Export {} stats to Restful endpoint".format(name))
|
# 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
|
||||||
def normalize(name):
|
self.buffer[name] = dict(zip(columns, points))
|
||||||
"""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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user