Skip to content
34 changes: 21 additions & 13 deletions agent360/plugins/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,37 @@ def run(self, config):
pass

cursor = db.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SHOW SLAVE STATUS')
query_result_slave = cursor.fetchone()
# Try MySQL 8.4+ syntax first, fall back to older syntax for backward compatibility
try:
cursor.execute('SHOW REPLICA STATUS')
query_result_slave = cursor.fetchone()
except MySQLdb.OperationalError:
cursor.execute('SHOW SLAVE STATUS')
query_result_slave = cursor.fetchone()

# Support both old and new column names
non_delta_slave = (
'slave_io_state',
'master_host',
'seconds_behind_master',
'read_master_log_pos',
'slave_io_state', 'replica_io_state',
'master_host', 'source_host',
'seconds_behind_master', 'seconds_behind_source',
'read_master_log_pos', 'read_source_log_pos',
'relay_log_pos',
'slave_io_running',
'slave_sql_running',
'slave_io_running', 'replica_io_running',
'slave_sql_running', 'replica_sql_running',
'last_error',
'exec_master_log_pos',
'exec_master_log_pos', 'exec_source_log_pos',
'relay_log_space',
'slave_sql_running_state',
'master_retry_count'
'slave_sql_running_state', 'replica_sql_running_state',
'master_retry_count', 'source_retry_count'
)
if query_result_slave is None:
query_result_slave = dict()
for key, value in query_result_slave.items():
key = key.lower().strip()
if key == 'slave_sql_running':
# Handle both old and new column names
if key in ('slave_sql_running', 'replica_sql_running'):
value = 1 if value == 'Yes' else 0
if key == 'slave_io_running':
if key in ('slave_io_running', 'replica_io_running'):
value = 1 if value == 'Yes' else 0

for c in constructors:
Expand Down