diff options
author | nicolargo <nicolas@nicolargo.com> | 2022-07-15 18:25:41 +0200 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2022-07-15 18:25:41 +0200 |
commit | 177eff05a21f655b4b6808807e77323a8b248a79 (patch) | |
tree | f8b12f03fdbc5841c2bd51e5c73bd1bc2594267f | |
parent | 17ff53d3a714704d73293178ca978b0cd9ebd1d0 (diff) |
Improve error message when export error occures
-rw-r--r-- | conf/glances.conf | 1 | ||||
-rw-r--r-- | glances/exports/glances_elasticsearch.py | 18 | ||||
-rw-r--r-- | glances/exports/glances_graphite.py | 2 | ||||
-rw-r--r-- | glances/exports/glances_rabbitmq.py | 4 |
4 files changed, 17 insertions, 8 deletions
diff --git a/conf/glances.conf b/conf/glances.conf index ccbd07b3..09cb5c68 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -524,6 +524,7 @@ port=8125 # Configuration for the --export elasticsearch option # Data are available via the ES RESTful API. ex: URL/<index>/cpu # https://www.elastic.co +scheme=http host=localhost port=9200 index=glances diff --git a/glances/exports/glances_elasticsearch.py b/glances/exports/glances_elasticsearch.py index 91c3bace..1ed0c052 100644 --- a/glances/exports/glances_elasticsearch.py +++ b/glances/exports/glances_elasticsearch.py @@ -31,7 +31,7 @@ class Export(GlancesExport): self.index = None # Load the ES configuration file - self.export_enable = self.load_conf('elasticsearch', mandatories=['host', 'port', 'index'], options=[]) + self.export_enable = self.load_conf('elasticsearch', mandatories=['scheme', 'host', 'port', 'index'], options=[]) if not self.export_enable: sys.exit(2) @@ -44,12 +44,22 @@ class Export(GlancesExport): return None try: - es = Elasticsearch(hosts=['{}:{}'.format(self.host, self.port)]) + es = Elasticsearch(hosts=['{}://{}:{}'.format(self.scheme, self.host, self.port)]) except Exception as e: - logger.critical("Cannot connect to ElasticSearch server %s:%s (%s)" % (self.host, self.port, e)) + logger.critical("Cannot connect to ElasticSearch server %s://%s:%s (%s)" % (self.scheme, + self.host, + self.port, e)) + sys.exit(2) + + if not es.ping(): + logger.critical("Cannot ping the ElasticSearch server %s://%s:%s" % (self.scheme, + self.host, + self.port)) sys.exit(2) else: - logger.info("Connected to the ElasticSearch server %s:%s" % (self.host, self.port)) + logger.info("Connected to the ElasticSearch server %s://%s:%s" % (self.scheme, + self.host, + self.port)) return es diff --git a/glances/exports/glances_graphite.py b/glances/exports/glances_graphite.py index fdcb2e9f..b33d3951 100644 --- a/glances/exports/glances_graphite.py +++ b/glances/exports/glances_graphite.py @@ -12,7 +12,6 @@ import sys from numbers import Number -from glances.compat import range from glances.logger import logger from glances.exports.glances_export import GlancesExport @@ -80,7 +79,6 @@ class Export(GlancesExport): client = None else: logger.info("Stats will be exported to Graphite server: {}:{}".format(self.host, self.port)) - return client def export(self, name, columns, points): diff --git a/glances/exports/glances_rabbitmq.py b/glances/exports/glances_rabbitmq.py index fa2e3724..b322c588 100644 --- a/glances/exports/glances_rabbitmq.py +++ b/glances/exports/glances_rabbitmq.py @@ -72,8 +72,8 @@ class Export(GlancesExport): channel = connection.channel() return channel except Exception as e: - logger.critical("Connection to rabbitMQ failed : %s " % e) - return None + logger.critical("Connection to rabbitMQ server %s:%s failed. %s" % (self.host, self.port, e)) + sys.exit(2) def export(self, name, columns, points): """Write the points in RabbitMQ.""" |