From 73b511330620ea3bb213624f12bd75da7e74c668 Mon Sep 17 00:00:00 2001 From: Bogdan Popescu <68062990+bopopescu@users.noreply.github.com> Date: Sun, 26 Jul 2020 06:38:08 +0300 Subject: [PATCH] Get away from master/slave vocabulary --- scalarium_ganglia/files/default/mysql.py | 110 +++++++++++------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/scalarium_ganglia/files/default/mysql.py b/scalarium_ganglia/files/default/mysql.py index 8a73be2..c34cfda 100644 --- a/scalarium_ganglia/files/default/mysql.py +++ b/scalarium_ganglia/files/default/mysql.py @@ -42,7 +42,7 @@ REPORT_MASTER = True REPORT_SLAVE = True -def update_stats(get_innodb=True, get_master=True, get_slave=True): +def update_stats(get_innodb=True, get_main=True, get_subordinate=True): logging.warning('updating stats') global last_update global mysql_stats @@ -85,7 +85,7 @@ def update_stats(get_innodb=True, get_master=True, get_slave=True): # try not to fail ? get_innodb = get_innodb and variables['have_innodb'].lower() == 'yes' - get_master = get_master and variables['log_bin'].lower() == 'on' + get_main = get_main and variables['log_bin'].lower() == 'on' if get_innodb: cursor = conn.cursor(MySQLdb.cursors.Cursor) @@ -93,22 +93,22 @@ def update_stats(get_innodb=True, get_master=True, get_slave=True): innodb_status = parse_innodb_status(cursor.fetchone()[2].split('\n')) cursor.close() - if get_master: + if get_main: cursor = conn.cursor(MySQLdb.cursors.Cursor) cursor.execute("SHOW MASTER LOGS") - master_logs = cursor.fetchall() + main_logs = cursor.fetchall() cursor.close() - if get_slave: + if get_subordinate: cursor = conn.cursor(MySQLdb.cursors.DictCursor) cursor.execute("SHOW SLAVE STATUS") - slave_status = {} + subordinate_status = {} res = cursor.fetchone() if res: for (k,v) in res.items(): - slave_status[k.lower()] = v + subordinate_status[k.lower()] = v else: - get_slave = False + get_subordinate = False cursor.close() cursor = conn.cursor(MySQLdb.cursors.DictCursor) @@ -170,8 +170,8 @@ def update_stats(get_innodb=True, get_master=True, get_slave=True): 'select_range', 'select_range_check', 'select_scan', - 'slave_open_temp_tables', - 'slave_retried_transactions', + 'subordinate_open_temp_tables', + 'subordinate_retried_transactions', 'slow_launch_threads', 'slow_queries', 'sort_range', @@ -197,32 +197,32 @@ def update_stats(get_innodb=True, get_master=True, get_slave=True): for istat in innodb_status: mysql_stats['innodb_' + istat] = innodb_status[istat] - # process master logs - if get_master: - mysql_stats['binlog_count'] = len(master_logs) - mysql_stats['binlog_space_current'] = master_logs[-1][1] - #mysql_stats['binlog_space_total'] = sum((long(s[1]) for s in master_logs)) + # process main logs + if get_main: + mysql_stats['binlog_count'] = len(main_logs) + mysql_stats['binlog_space_current'] = main_logs[-1][1] + #mysql_stats['binlog_space_total'] = sum((long(s[1]) for s in main_logs)) mysql_stats['binlog_space_total'] = 0 - for s in master_logs: + for s in main_logs: mysql_stats['binlog_space_total'] += int(s[1]) - mysql_stats['binlog_space_used'] = float(master_logs[-1][1]) / float(variables['max_binlog_size']) * 100 - - # process slave status - if get_slave: - mysql_stats['slave_exec_master_log_pos'] = slave_status['exec_master_log_pos'] - #mysql_stats['slave_io'] = 1 if slave_status['slave_io_running'].lower() == "yes" else 0 - if slave_status['slave_io_running'].lower() == "yes": - mysql_stats['slave_io'] = 1 + mysql_stats['binlog_space_used'] = float(main_logs[-1][1]) / float(variables['max_binlog_size']) * 100 + + # process subordinate status + if get_subordinate: + mysql_stats['subordinate_exec_main_log_pos'] = subordinate_status['exec_main_log_pos'] + #mysql_stats['subordinate_io'] = 1 if subordinate_status['subordinate_io_running'].lower() == "yes" else 0 + if subordinate_status['subordinate_io_running'].lower() == "yes": + mysql_stats['subordinate_io'] = 1 else: - mysql_stats['slave_io'] = 0 - #mysql_stats['slave_sql'] = 1 if slave_status['slave_sql_running'].lower() =="yes" else 0 - if slave_status['slave_sql_running'].lower() == "yes": - mysql_stats['slave_sql'] = 1 + mysql_stats['subordinate_io'] = 0 + #mysql_stats['subordinate_sql'] = 1 if subordinate_status['subordinate_sql_running'].lower() =="yes" else 0 + if subordinate_status['subordinate_sql_running'].lower() == "yes": + mysql_stats['subordinate_sql'] = 1 else: - mysql_stats['slave_sql'] = 0 - mysql_stats['slave_lag'] = slave_status['seconds_behind_master'] - mysql_stats['slave_relay_log_pos'] = slave_status['relay_log_pos'] - mysql_stats['slave_relay_log_space'] = slave_status['relay_log_space'] + mysql_stats['subordinate_sql'] = 0 + mysql_stats['subordinate_lag'] = subordinate_status['seconds_behind_main'] + mysql_stats['subordinate_relay_log_pos'] = subordinate_status['relay_log_pos'] + mysql_stats['subordinate_relay_log_space'] = subordinate_status['relay_log_space'] def get_stat(name): logging.info("getting stat: %s" % name) @@ -260,8 +260,8 @@ def metric_init(params): global REPORT_SLAVE REPORT_INNODB = str(params.get('get_innodb', True)) == "True" - REPORT_MASTER = str(params.get('get_master', True)) == "True" - REPORT_SLAVE = str(params.get('get_slave', True)) == "True" + REPORT_MASTER = str(params.get('get_main', True)) == "True" + REPORT_SLAVE = str(params.get('get_subordinate', True)) == "True" logging.warning("init: " + str(params)) @@ -273,9 +273,9 @@ def metric_init(params): connect_timeout = params.get('timeout', 30), ) - master_stats_descriptions = {} + main_stats_descriptions = {} innodb_stats_descriptions = {} - slave_stats_descriptions = {} + subordinate_stats_descriptions = {} misc_stats_descriptions = dict( aborted_clients = { @@ -498,14 +498,14 @@ def metric_init(params): 'units': 'joins', }, - slave_open_temp_tables = { - 'description': 'The number of temporary tables that the slave SQL thread currently has open', + subordinate_open_temp_tables = { + 'description': 'The number of temporary tables that the subordinate SQL thread currently has open', 'units': 'tables', 'slope': 'both', }, - slave_retried_transactions = { - 'description': 'The total number of times since startup that the replication slave SQL thread has retried transactions', + subordinate_retried_transactions = { + 'description': 'The total number of times since startup that the replication subordinate SQL thread has retried transactions', 'units': 'count', }, @@ -584,7 +584,7 @@ def metric_init(params): ) if REPORT_MASTER: - master_stats_descriptions = dict( + main_stats_descriptions = dict( binlog_count = { 'description': "Number of binary logs", 'units': 'logs', @@ -612,34 +612,34 @@ def metric_init(params): ) if REPORT_SLAVE: - slave_stats_descriptions = dict( - slave_exec_master_log_pos = { - 'description': "The position of the last event executed by the SQL thread from the master's binary log", + subordinate_stats_descriptions = dict( + subordinate_exec_main_log_pos = { + 'description': "The position of the last event executed by the SQL thread from the main's binary log", 'units': 'bytes', 'slope': 'both', }, - slave_io = { - 'description': "Whether the I/O thread is started and has connected successfully to the master", + subordinate_io = { + 'description': "Whether the I/O thread is started and has connected successfully to the main", 'value_type': 'uint8', 'units': 'True/False', 'slope': 'both', }, - slave_lag = { + subordinate_lag = { 'description': "Replication Lag", 'units': 'secs', 'slope': 'both', }, - slave_relay_log_pos = { + subordinate_relay_log_pos = { 'description': "The position up to which the SQL thread has read and executed in the current relay log", 'units': 'bytes', 'slope': 'both', }, - slave_sql = { - 'description': "Slave SQL Running", + subordinate_sql = { + 'description': "Subordinate SQL Running", 'value_type': 'uint8', 'units': 'True/False', 'slope': 'both', @@ -915,7 +915,7 @@ def metric_init(params): update_stats(REPORT_INNODB, REPORT_MASTER, REPORT_SLAVE) - for stats_descriptions in (innodb_stats_descriptions, master_stats_descriptions, misc_stats_descriptions, slave_stats_descriptions): + for stats_descriptions in (innodb_stats_descriptions, main_stats_descriptions, misc_stats_descriptions, subordinate_stats_descriptions): for label in stats_descriptions: if mysql_stats.has_key(label): @@ -956,8 +956,8 @@ def metric_cleanup(): parser.add_option("-p", "--password", dest="passwd", help="password", default="") parser.add_option("-P", "--port", dest="port", help="port", default=3306, type="int") parser.add_option("--no-innodb", dest="get_innodb", action="store_false", default=True) - parser.add_option("--no-master", dest="get_master", action="store_false", default=True) - parser.add_option("--no-slave", dest="get_slave", action="store_false", default=True) + parser.add_option("--no-main", dest="get_main", action="store_false", default=True) + parser.add_option("--no-subordinate", dest="get_subordinate", action="store_false", default=True) parser.add_option("-b", "--gmetric-bin", dest="gmetric_bin", help="path to gmetric binary", default="/usr/bin/gmetric") parser.add_option("-c", "--gmond-conf", dest="gmond_conf", help="path to gmond.conf", default="/etc/ganglia/gmond.conf") parser.add_option("-g", "--gmetric", dest="gmetric", help="submit via gmetric", action="store_true", default=False) @@ -971,8 +971,8 @@ def metric_cleanup(): 'user': options.user, 'port': options.port, 'get_innodb': options.get_innodb, - 'get_master': options.get_master, - 'get_slave': options.get_slave, + 'get_main': options.get_main, + 'get_subordinate': options.get_subordinate, }) for d in descriptors: