From: Wido den Hollander Date: Tue, 30 Jan 2018 14:45:40 +0000 (+0100) Subject: mgr/influx: Catch ConnectionError if raised X-Git-Tag: v12.2.6~32^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c5cadd1d47a94256b97dcbe07c59271ee6d41469;p=ceph.git mgr/influx: Catch ConnectionError if raised The InfluxDBClient can also re-raise a ConnectionError from the python requests module if that was caught. The Exception might be: ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer')) Catch and log this error instead of having it raised which might cause problems further down. Signed-off-by: Wido den Hollander (cherry picked from commit a0c2c8b900cd2bab2ef8041722036036efd2cb0f) --- diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index bf4c3942489b..067229ee75bc 100644 --- a/src/pybind/mgr/influx/module.py +++ b/src/pybind/mgr/influx/module.py @@ -9,6 +9,7 @@ from mgr_module import MgrModule try: from influxdb import InfluxDBClient from influxdb.exceptions import InfluxDBClientError + from requests.exceptions import ConnectionError except ImportError: InfluxDBClient = None @@ -170,6 +171,13 @@ class Module(MgrModule): if not self.config['hostname']: self.log.error("No Influx server configured, please set one using: " "ceph influx config-set hostname ") + self.set_health_checks({ + 'MGR_INFLUX_NO_SERVER': { + 'severity': 'warning', + 'summary': 'No InfluxDB server configured', + 'detail': ['Configuration option hostname not set'] + } + }) return # If influx server has authentication turned off then @@ -189,6 +197,19 @@ class Module(MgrModule): try: client.write_points(self.get_df_stats(), 'ms') client.write_points(self.get_daemon_stats(), 'ms') + self.set_health_checks(dict()) + except ConnectionError as e: + self.log.exception("Failed to connect to Influx host %s:%d", + self.config['hostname'], self.config['port']) + self.set_health_checks({ + 'MGR_INFLUX_SEND_FAILED': { + 'severity': 'warning', + 'summary': 'Failed to send data to InfluxDB server at %s:%d' + ' due to an connection error' + % (self.config['hostname'], self.config['port']), + 'detail': [str(e)] + } + }) except InfluxDBClientError as e: if e.code == 404: self.log.info("Database '%s' not found, trying to create " @@ -198,6 +219,13 @@ class Module(MgrModule): self.config['username']) client.create_database(self.config['database']) else: + self.set_health_checks({ + 'MGR_INFLUX_SEND_FAILED': { + 'severity': 'warning', + 'summary': 'Failed to send data to InfluxDB', + 'detail': [str(e)] + } + }) raise def shutdown(self):