try to reconnect to MySQL on OperationalError
paulfantom committed
Aug 7, 2016 at 15:46 UTC
0c3629cf19de74465dbcf85240fc874892e97108
1 file changed
+9
python.d/mysql.chart.py
+9
@@ -369,11 +369,20 @@ class Service(SimpleService):
369
cursor = self.connection.cursor()
370
cursor.execute(QUERY)
371
raw_data = cursor.fetchall()
372
+ except MySQLdb.OperationalError as e:
373
+ self.debug("Reconnecting due to", str(e))
374
+ self._connect()
375
+ cursor = self.connection.cursor()
376
+ cursor.execute(QUERY)
377
+ raw_data = cursor.fetchall()
378
+
379
+
380
except Exception as e:
381
self.error("cannot execute query.", e)
382
self.connection.close()
383
self.connection = None
384
return None
385
+
386
data = dict(raw_data)
387
try:
388
data["Thread_cache_misses"] = int(data["Threads_created"] * 10000 / float(data["Connections"]))