summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2021-05-10 09:12:23 +0200
committernicolargo <nicolas@nicolargo.com>2021-05-10 09:12:23 +0200
commit560b989f17023756da9523f0f3f18d1a81bf4b84 (patch)
treea7e9b01e273f938ffbe22d6ad62c76acddffb5fe
parent6bceeef43f2988e6485e047068d0bd38021ae6f8 (diff)
Connection to Graphite Server should be done before releasing the feature
-rw-r--r--conf/glances.conf2
-rw-r--r--docs/gw/graphite.rst6
-rw-r--r--glances/exports/glances_graphite.py36
3 files changed, 36 insertions, 8 deletions
diff --git a/conf/glances.conf b/conf/glances.conf
index f1bd101d..93e9c15a 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -590,7 +590,7 @@ path=/
# Configuration for the --export graphite option
# https://graphiteapp.org/
host=localhost
-port=2003
+port=20039
protocol=tcp
batch_size=1000
# Prefix will be added for all measurement name
diff --git a/docs/gw/graphite.rst b/docs/gw/graphite.rst
index 33e765fe..87889bb5 100644
--- a/docs/gw/graphite.rst
+++ b/docs/gw/graphite.rst
@@ -29,5 +29,9 @@ and run Glances with:
$ glances --export graphite
+Note 1: the port defines the TCP or UDP port where the Graphite listen plain-text requests
-Note: 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/)
+ \ No newline at end of file
diff --git a/glances/exports/glances_graphite.py b/glances/exports/glances_graphite.py
index 7d2c0d6e..ba25a08a 100644
--- a/glances/exports/glances_graphite.py
+++ b/glances/exports/glances_graphite.py
@@ -76,16 +76,38 @@ class Export(GlancesExport):
"""Init the connection to the Graphite server."""
if not self.export_enable:
return None
+
+ client = graphyte.Sender(self.host,
+ port=self.port,
+ prefix=self.prefix,
+ protocol=self.protocol,
+ batch_size=self.batch_size)
+
+ # !!! Except is never reached...
+ # !!! Have to find away to test the connection with the Graphite server
+ # !!! Waiting that, have to set the logger to debug in the export function
+ # try:
+ # client.send("check", 1)
+ # except Exception as e:
+ # logger.error("Can not write data to Graphite server: {}:{}/{} ({})".format(self.host,
+ # self.port,
+ # self.protocol,
+ # e))
+ # return None
+ # else:
+ # logger.info(
+ # "Stats will be exported to Graphite server: {}:{}/{}".format(self.host,
+ # self.port,
+ # self.protocol))
+
+ # return client
+
logger.info(
"Stats will be exported to Graphite server: {}:{}/{}".format(self.host,
self.port,
self.protocol))
- return graphyte.Sender(self.host,
- port=self.port,
- prefix=self.prefix,
- protocol=self.protocol,
- batch_size=self.batch_size)
+ return client
def export(self, name, columns, points):
"""Export the stats to the Graphite server."""
@@ -99,7 +121,9 @@ class Export(GlancesExport):
self.client.send(normalize(stat_name),
stat_value)
except Exception as e:
- logger.error("Can not export stats to Graphite (%s)" % e)
+ # !! Set to error when the connection test is ok
+ # logger.error("Can not export stats to Graphite (%s)" % e)
+ logger.debug("Can not export stats to Graphite (%s)" % e)
logger.debug("Export {} stats to Graphite".format(name))