@cryptotaxi247 / netdata-1 / commits / 697d5608e

add slave stats to mysql chart

lgz committed Dec 29, 2016 at 22:02 UTC 697d5608ef4f1171abf3a5503db9640386775556
1 file changed +31 -3
python.d/mysql.chart.py
+31 -3
@@ -40,6 +40,7 @@ retries = 60
40
41 # query executed on MySQL server
42 QUERY = "SHOW GLOBAL STATUS;"
43 +QUERY_SLAVE = "SHOW SLAVE STATUS;"
44
45 ORDER = ['net',
46 'queries',
@@ -55,7 +56,7 @@ ORDER = ['net',
56 'innodb_buffer_pool_read_ahead', 'innodb_buffer_pool_reqs', 'innodb_buffer_pool_ops',
57 'qcache_ops', 'qcache', 'qcache_freemem', 'qcache_memblocks',
58 'key_blocks', 'key_requests', 'key_disk_ops',
58 - 'files', 'files_rate']
59 + 'files', 'files_rate', 'slave_behind', 'slave_status']
60
61 CHARTS = {
62 'net': {
@@ -298,8 +299,18 @@ CHARTS = {
299 ["Connection_errors_peer_address", "peer_addr", "incremental"],
300 ["Connection_errors_select", "select", "incremental"],
301 ["Connection_errors_tcpwrap", "tcpwrap", "incremental"]
302 + ]},
303 + 'slave_behind': {
304 + 'options': [None, 'Slave Behind Seconds', 'seconds', 'slave', 'mysql.slave_behind', 'line'],
305 + 'lines': [
306 + ["slave_behind", "seconds", "absolute"]
307 + ]},
308 + 'slave_status': {
309 + 'options': [None, 'Slave Status', 'status', 'slave', 'mysql.slave_status', 'line'],
310 + 'lines': [
311 + ["slave_sql", "sql_running", "absolute"],
312 + ["slave_io", "io_running", "absolute"]
313 ]}
302 -
314 }
315
316
@@ -362,12 +373,28 @@ class Service(SimpleService):
373 cursor = self.connection.cursor()
374 cursor.execute(QUERY)
375 raw_data = cursor.fetchall()
376 + slave_data = {}
377 + if cursor.execute(QUERY_SLAVE):
378 + slave_data = {'slave_behind': 0, 'slave_sql': 0, 'slave_io': 0 }
379 + slave_raw_data = dict(list(zip([elem[0] for elem in cursor.description], cursor.fetchone())))
380 + slave_data['slave_behind'] = int(slave_raw_data.setdefault('Seconds_Behind_Master', -1))
381 + slave_data['slave_sql'] = 1 if slave_raw_data.get('Slave_SQL_Running') == 'Yes' else -1
382 + slave_data['slave_io'] = 1 if slave_raw_data.get('Slave_IO_Running') == 'Yes' else -1
383 +
384 except MySQLdb.OperationalError as e:
385 self.debug("Reconnecting due to", str(e))
386 self._connect()
387 cursor = self.connection.cursor()
388 cursor.execute(QUERY)
389 raw_data = cursor.fetchall()
390 + slave_data = {}
391 + if cursor.execute(QUERY_SLAVE):
392 + slave_data = {'slave_behind': 0, 'slave_sql': 0, 'slave_io': 0 }
393 + slave_raw_data = dict(list(zip([elem[0] for elem in cursor.description], cursor.fetchone())))
394 + slave_data['slave_behind'] = int(slave_raw_data.setdefault('Seconds_Behind_Master', -1))
395 + slave_data['slave_sql'] = 1 if slave_raw_data.get('Slave_SQL_Running') == 'Yes' else -1
396 + slave_data['slave_io'] = 1 if slave_raw_data.get('Slave_IO_Running') == 'Yes' else -1
397 +
398 except Exception as e:
399 self.error("cannot execute query.", e)
400 self.connection.close()
@@ -379,7 +406,8 @@ class Service(SimpleService):
406 data["Thread_cache_misses"] = int(data["Threads_created"] * 10000 / float(data["Connections"]))
407 except:
408 data["Thread_cache_misses"] = 0
382 -
409 +
410 + data.update(slave_data)
411 return data
412
413 def check(self):