diff --git a/agent360/plugins/mysql.py b/agent360/plugins/mysql.py index 468e86c..19e9887 100644 --- a/agent360/plugins/mysql.py +++ b/agent360/plugins/mysql.py @@ -129,8 +129,27 @@ def run(self, config): pass cursor = db.cursor(MySQLdb.cursors.DictCursor) - cursor.execute('SHOW SLAVE STATUS') + # SHOW REPLICA STATUS: MySQL 8.0.22+ / MariaDB 10.5.1+. Older servers + # reject it with a syntax error (ProgrammingError), so fall back. + try: + cursor.execute('SHOW REPLICA STATUS') + except MySQLdb.Error: + cursor.execute('SHOW SLAVE STATUS') query_result_slave = cursor.fetchone() + + # Newer servers renamed columns; map them back to the legacy names + # so metric keys stay the same across server versions. + replica_key_map = { + 'replica_io_state': 'slave_io_state', + 'source_host': 'master_host', + 'seconds_behind_source': 'seconds_behind_master', + 'read_source_log_pos': 'read_master_log_pos', + 'replica_io_running': 'slave_io_running', + 'replica_sql_running': 'slave_sql_running', + 'exec_source_log_pos': 'exec_master_log_pos', + 'replica_sql_running_state': 'slave_sql_running_state', + 'source_retry_count': 'master_retry_count', + } non_delta_slave = ( 'slave_io_state', 'master_host', @@ -149,6 +168,7 @@ def run(self, config): query_result_slave = dict() for key, value in query_result_slave.items(): key = key.lower().strip() + key = replica_key_map.get(key, key) if key == 'slave_sql_running': value = 1 if value == 'Yes' else 0 if key == 'slave_io_running':