Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion agent360/plugins/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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':
Expand Down
Loading