提交 8d094d5a 编写于 作者: N nicolargo

Implemented but test is KO: only a part of the stats are exported... Same...

Implemented but test is KO: only a part of the stats are exported... Same behavor with both client Graphyte and GraphiteSender. Perhaps the issue came from the server (docker-graphite-grafana)
上级 af6f0245
...@@ -75,7 +75,7 @@ Optional dependencies: ...@@ -75,7 +75,7 @@ Optional dependencies:
- ``couchdb`` (for the CouchDB export module) - ``couchdb`` (for the CouchDB export module)
- ``docker`` (for the Docker monitoring support) [Linux/macOS-only] - ``docker`` (for the Docker monitoring support) [Linux/macOS-only]
- ``elasticsearch`` (for the Elastic Search export module) - ``elasticsearch`` (for the Elastic Search export module)
- ``graphyte`` (For the Graphite export module) - ``graphitesender`` (For the Graphite export module)
- ``hddtemp`` (for HDD temperature monitoring support) [Linux-only] - ``hddtemp`` (for HDD temperature monitoring support) [Linux-only]
- ``influxdb`` (for the InfluxDB version 1 export module) - ``influxdb`` (for the InfluxDB version 1 export module)
- ``influxdb-client`` (for the InfluxDB version 2 export module) [Only for Python >= 3.6] - ``influxdb-client`` (for the InfluxDB version 2 export module) [Only for Python >= 3.6]
......
...@@ -591,15 +591,11 @@ path=/ ...@@ -591,15 +591,11 @@ path=/
# https://graphiteapp.org/ # https://graphiteapp.org/
host=localhost host=localhost
port=2003 port=2003
protocol=tcp
batch_size=1000
# Prefix will be added for all measurement name # Prefix will be added for all measurement name
# Ex: prefix=foo
# => foo.cpu
# => foo.mem
# You can also use dynamic values
#prefix=`hostname`
prefix=glances prefix=glances
# System name added between the prefix and the stats
# By default, system_name = FQDN
#system_name=mycomputer
############################################################################## ##############################################################################
# AMPS # AMPS
......
...@@ -13,8 +13,6 @@ following: ...@@ -13,8 +13,6 @@ following:
[graphite] [graphite]
host=localhost host=localhost
port=2003 port=2003
protocol=udp
batch_size=1000
# Prefix will be added for all measurement name # Prefix will be added for all measurement name
# Ex: prefix=foo # Ex: prefix=foo
# => foo.cpu # => foo.cpu
...@@ -29,9 +27,8 @@ and run Glances with: ...@@ -29,9 +27,8 @@ and run Glances with:
$ glances --export graphite $ glances --export graphite
Note 1: the port defines the TCP or UDP port where the Graphite listen plain-text requests Note 1: the port defines the TCP port where the Graphite listen plain-text requests.
Note 2: As many time-series database, only integer and float are supported in the Graphite datamodel. Note 2: As many time-series database, only integer and float are supported in the Graphite datamodel.
Note 3: Under the wood, Glances uses Graphyte Python lib (https://pypi.org/project/graphyte/) Note 3: Under the wood, Glances uses GraphiteSender Python lib (https://github.com/NicoAdrian/graphitesender).
\ No newline at end of file
...@@ -26,7 +26,7 @@ from glances.compat import range ...@@ -26,7 +26,7 @@ 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
import graphyte from graphitesend import GraphiteClient
class Export(GlancesExport): class Export(GlancesExport):
...@@ -41,17 +41,16 @@ class Export(GlancesExport): ...@@ -41,17 +41,16 @@ class Export(GlancesExport):
# N/A # N/A
# Optionals configuration keys # Optionals configuration keys
self.debug = False
self.prefix = None self.prefix = None
self.protocol = None self.system_name = None
self.batch_size = None
# Load the configuration file # Load the configuration file
self.export_enable = self.load_conf('graphite', self.export_enable = self.load_conf('graphite',
mandatories=['host', mandatories=['host',
'port'], 'port'],
options=['prefix', options=['prefix',
'protocol', 'system_name'])
'batch_size'])
if not self.export_enable: if not self.export_enable:
sys.exit(2) sys.exit(2)
...@@ -59,72 +58,63 @@ class Export(GlancesExport): ...@@ -59,72 +58,63 @@ class Export(GlancesExport):
if self.prefix is None: if self.prefix is None:
self.prefix = 'glances' self.prefix = 'glances'
if self.protocol is None:
self.protocol = 'tcp'
if self.batch_size is None:
self.batch_size = 1000
# Convert config option type # Convert config option type
self.port = int(self.port) self.port = int(self.port)
self.batch_size = int(self.batch_size)
# Init the Graphite client # Init the Graphite client
self.client = self.init() self.client = self.init()
def init(self): def init(self):
"""Init the connection to the Graphite server.""" """Init the connection to the Graphite server."""
client = None
if not self.export_enable: if not self.export_enable:
return None return client
client = graphyte.Sender(self.host, try:
port=self.port, if self.system_name is None:
prefix=self.prefix, client = GraphiteClient(graphite_server=self.host,
protocol=self.protocol, graphite_port=self.port,
batch_size=self.batch_size) prefix=self.prefix,
lowercase_metric_names=True,
# !!! Except is never reached... debug=self.debug)
# !!! Have to find away to test the connection with the Graphite server else:
# !!! Waiting that, have to set the logger to debug in the export function client = GraphiteClient(graphite_server=self.host,
# try: graphite_port=self.port,
# client.send("check", 1) prefix=self.prefix,
# except Exception as e: system_name=self.system_name,
# logger.error("Can not write data to Graphite server: {}:{}/{} ({})".format(self.host, lowercase_metric_names=True,
# self.port, debug=self.debug)
# self.protocol, except Exception as e:
# e)) logger.error("Can not write data to Graphite server: {}:{} ({})".format(self.host,
# return None self.port,
# else: e))
# logger.info( client = None
# "Stats will be exported to Graphite server: {}:{}/{}".format(self.host, else:
# self.port, logger.info(
# self.protocol)) "Stats will be exported to Graphite server: {}:{}".format(self.host,
self.port))
# return client
logger.info(
"Stats will be exported to Graphite server: {}:{}/{}".format(self.host,
self.port,
self.protocol))
return client return client
def export(self, name, columns, points): def export(self, name, columns, points):
"""Export the stats to the Graphite server.""" """Export the stats to the Graphite server."""
for i in range(len(columns)): if self.client is None:
if not isinstance(points[i], Number): return False
# Only Int and Float are supported in the Graphite datamodel before_filtering_dict = dict(zip(
continue [normalize('{}.{}'.format(name, i)) for i in columns],
stat_name = '{}.{}'.format(name, columns[i]) points))
stat_value = points[i] after_filtering_dict = dict(
try: filter(lambda i: isinstance(i[1], Number),
self.client.send(normalize(stat_name), before_filtering_dict.items()))
stat_value) try:
except Exception as e: self.client.send_dict(after_filtering_dict)
# !! Set to error when the connection test is ok except Exception as e:
# logger.error("Can not export stats to Graphite (%s)" % e) logger.error("Can not export stats to Graphite (%s)" % e)
logger.debug("Can not export stats to Graphite (%s)" % e) return False
logger.debug("Export {} stats to Graphite".format(name)) else:
logger.debug("Export {} stats to Graphite".format(name))
return True
def normalize(name): def normalize(name):
......
...@@ -8,7 +8,7 @@ chevron ...@@ -8,7 +8,7 @@ chevron
couchdb couchdb
docker>=2.0.0 docker>=2.0.0
elasticsearch elasticsearch
graphyte graphitesender
hddtemp hddtemp
influxdb influxdb
influxdb-client; python_version >= "3.6" influxdb-client; python_version >= "3.6"
......
...@@ -57,7 +57,7 @@ def get_install_extras_require(): ...@@ -57,7 +57,7 @@ def get_install_extras_require():
'cpuinfo': ['py-cpuinfo<=4.0.0'], 'cpuinfo': ['py-cpuinfo<=4.0.0'],
'docker': ['docker>=2.0.0'], 'docker': ['docker>=2.0.0'],
'export': ['bernhard', 'cassandra-driver', 'couchdb', 'elasticsearch', 'export': ['bernhard', 'cassandra-driver', 'couchdb', 'elasticsearch',
'graphyte', 'influxdb>=1.0.0', 'kafka-python', 'pika', 'graphitesender', 'influxdb>=1.0.0', 'kafka-python', 'pika',
'paho-mqtt', 'potsdb', 'prometheus_client', 'pyzmq', 'paho-mqtt', 'potsdb', 'prometheus_client', 'pyzmq',
'statsd'], 'statsd'],
'folders': ['scandir'], # python_version<"3.5" 'folders': ['scandir'], # python_version<"3.5"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册