From: Costa Tsaousis Date: Thu, 29 Dec 2016 20:09:22 +0000 (+0200) Subject: Merge pull request #1471 from ktsaou/master X-Git-Tag: v1.5.0~75 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=c59a9ed846a1669d801892feee4af79046b2618b;hp=28c58b610b5775f137d59843f5ea76023151a866;p=netdata.git Merge pull request #1471 from ktsaou/master mysql alarms --- diff --git a/plugins.d/python.d.plugin b/plugins.d/python.d.plugin index 05d23b9a..b4e6473a 100755 --- a/plugins.d/python.d.plugin +++ b/plugins.d/python.d.plugin @@ -9,6 +9,7 @@ import os import sys import time import threading +from re import sub # ----------------------------------------------------------------------------- # globals & environment setup @@ -340,7 +341,7 @@ class PythonCharts(object): i += 1 try: if job.override_name is not None: - new_name = job.__module__ + '_' + job.override_name + new_name = job.__module__ + '_' + sub(r'\s+', '_', job.override_name) if new_name in overridden: msg.info("DROPPED:", job.name, ", job '" + job.override_name + "' is already served by another job.") self._stop(job) diff --git a/python.d/mysql.chart.py b/python.d/mysql.chart.py index dab6fad3..daff0255 100644 --- a/python.d/mysql.chart.py +++ b/python.d/mysql.chart.py @@ -40,6 +40,7 @@ retries = 60 # query executed on MySQL server QUERY = "SHOW GLOBAL STATUS;" +QUERY_SLAVE = "SHOW SLAVE STATUS;" ORDER = ['net', 'queries', @@ -55,7 +56,7 @@ ORDER = ['net', 'innodb_buffer_pool_read_ahead', 'innodb_buffer_pool_reqs', 'innodb_buffer_pool_ops', 'qcache_ops', 'qcache', 'qcache_freemem', 'qcache_memblocks', 'key_blocks', 'key_requests', 'key_disk_ops', - 'files', 'files_rate'] + 'files', 'files_rate', 'slave_behind', 'slave_status'] CHARTS = { 'net': { @@ -298,8 +299,18 @@ CHARTS = { ["Connection_errors_peer_address", "peer_addr", "incremental"], ["Connection_errors_select", "select", "incremental"], ["Connection_errors_tcpwrap", "tcpwrap", "incremental"] + ]}, + 'slave_behind': { + 'options': [None, 'Slave Behind Seconds', 'seconds', 'slave', 'mysql.slave_behind', 'line'], + 'lines': [ + ["slave_behind", "seconds", "absolute"] + ]}, + 'slave_status': { + 'options': [None, 'Slave Status', 'status', 'slave', 'mysql.slave_status', 'line'], + 'lines': [ + ["slave_sql", "sql_running", "absolute"], + ["slave_io", "io_running", "absolute"] ]} - } @@ -362,12 +373,28 @@ class Service(SimpleService): cursor = self.connection.cursor() cursor.execute(QUERY) raw_data = cursor.fetchall() + slave_data = {} + if cursor.execute(QUERY_SLAVE): + slave_data = {'slave_behind': 0, 'slave_sql': 0, 'slave_io': 0 } + slave_raw_data = dict(list(zip([elem[0] for elem in cursor.description], cursor.fetchone()))) + slave_data['slave_behind'] = int(slave_raw_data.setdefault('Seconds_Behind_Master', -1)) + slave_data['slave_sql'] = 1 if slave_raw_data.get('Slave_SQL_Running') == 'Yes' else -1 + slave_data['slave_io'] = 1 if slave_raw_data.get('Slave_IO_Running') == 'Yes' else -1 + except MySQLdb.OperationalError as e: self.debug("Reconnecting due to", str(e)) self._connect() cursor = self.connection.cursor() cursor.execute(QUERY) raw_data = cursor.fetchall() + slave_data = {} + if cursor.execute(QUERY_SLAVE): + slave_data = {'slave_behind': 0, 'slave_sql': 0, 'slave_io': 0 } + slave_raw_data = dict(list(zip([elem[0] for elem in cursor.description], cursor.fetchone()))) + slave_data['slave_behind'] = int(slave_raw_data.setdefault('Seconds_Behind_Master', -1)) + slave_data['slave_sql'] = 1 if slave_raw_data.get('Slave_SQL_Running') == 'Yes' else -1 + slave_data['slave_io'] = 1 if slave_raw_data.get('Slave_IO_Running') == 'Yes' else -1 + except Exception as e: self.error("cannot execute query.", e) self.connection.close() @@ -379,7 +406,8 @@ class Service(SimpleService): data["Thread_cache_misses"] = int(data["Threads_created"] * 10000 / float(data["Connections"])) except: data["Thread_cache_misses"] = 0 - + + data.update(slave_data) return data def check(self):