From 0469419235dd35cca64b547a3252a4de46834ba8 Mon Sep 17 00:00:00 2001 From: JoJo Date: Thu, 7 Jul 2022 19:14:03 -0700 Subject: [PATCH] Fix bug where mysql table row stats were not being collected (#12472) --- mysql/datadog_checks/mysql/config.py | 2 +- mysql/datadog_checks/mysql/mysql.py | 2 +- mysql/datadog_checks/mysql/queries.py | 28 +++++++++++++-------------- mysql/metadata.csv | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/mysql/datadog_checks/mysql/config.py b/mysql/datadog_checks/mysql/config.py index bafe80ecfdded..515954168b4b7 100644 --- a/mysql/datadog_checks/mysql/config.py +++ b/mysql/datadog_checks/mysql/config.py @@ -32,7 +32,7 @@ def __init__(self, instance): self.max_custom_queries = instance.get('max_custom_queries', DEFAULT_MAX_CUSTOM_QUERIES) self.charset = instance.get('charset') self.dbm_enabled = is_affirmative(instance.get('dbm', instance.get('deep_database_monitoring', False))) - self.table_rows_stats_enabled = is_affirmative(instance.get('table_rows_stats_metrics', False)) + self.table_rows_stats_enabled = is_affirmative(self.options.get('table_rows_stats_metrics', False)) self.statement_metrics_limits = instance.get('statement_metrics_limits', None) self.full_statement_text_cache_max_size = instance.get('full_statement_text_cache_max_size', 10000) self.full_statement_text_samples_per_hour_per_query = instance.get( diff --git a/mysql/datadog_checks/mysql/mysql.py b/mysql/datadog_checks/mysql/mysql.py index dbc1de437e6e6..658ca6ccdde87 100644 --- a/mysql/datadog_checks/mysql/mysql.py +++ b/mysql/datadog_checks/mysql/mysql.py @@ -401,6 +401,7 @@ def _collect_metrics(self, db, tags): if is_affirmative(self._config.options.get('table_rows_stats_metrics', False)) and self.userstat_enabled: # report size of tables in MiB to Datadog + self.log.debug("Collecting Table Row Stats Metrics.") (rows_read_total, rows_changed_total) = self._query_rows_stats_per_table(db) results['information_table_rows_read_total'] = rows_read_total results['information_table_rows_changed_total'] = rows_changed_total @@ -1085,7 +1086,6 @@ def _query_rows_stats_per_table(self, db): # set the tag as the dictionary key table_rows_read_total["schema:{},table:{}".format(table_schema, table_name)] = rows_read_total table_rows_changed_total["schema:{},table:{}".format(table_schema, table_name)] = rows_changed_total - return table_rows_read_total, table_rows_changed_total except (pymysql.err.InternalError, pymysql.err.OperationalError) as e: self.warning("Tables rows stats metrics unavailable at this time: %s", e) diff --git a/mysql/datadog_checks/mysql/queries.py b/mysql/datadog_checks/mysql/queries.py index 3439413a9a7e0..d7f6656b468a2 100644 --- a/mysql/datadog_checks/mysql/queries.py +++ b/mysql/datadog_checks/mysql/queries.py @@ -13,27 +13,27 @@ LIMIT 1""" SQL_QUERY_TABLE_ROWS_STATS = """\ -SELECT table_schema, table_name, rows_read, rows_changed -FROM information_schema.table_statistics""" +SELECT table_schema, table_name, rows_read, rows_changed +FROM information_schema.table_statistics""" SQL_QUERY_SCHEMA_SIZE = """\ -SELECT table_schema, IFNULL(SUM(data_length+index_length)/1024/1024,0) AS total_mb -FROM information_schema.tables +SELECT table_schema, IFNULL(SUM(data_length+index_length)/1024/1024,0) AS total_mb +FROM information_schema.tables GROUP BY table_schema""" SQL_QUERY_TABLE_SIZE = """\ -SELECT table_schema, table_name, - IFNULL(index_length/1024/1024,0) AS index_size_mb, - IFNULL(data_length/1024/1024,0) AS data_size_mb -FROM information_schema.tables -WHERE table_schema not in ('mysql', 'performance_schema', 'information_schema')""" +SELECT table_schema, table_name, + IFNULL(index_length/1024/1024,0) AS index_size_mb, + IFNULL(data_length/1024/1024,0) AS data_size_mb +FROM information_schema.tables +WHERE table_schema not in ('mysql', 'performance_schema', 'information_schema')""" SQL_QUERY_SYSTEM_TABLE_SIZE = """\ -SELECT table_schema, table_name, - IFNULL(index_length/1024/1024,0) AS index_size_mb, - IFNULL(data_length/1024/1024,0) AS data_size_mb -FROM information_schema.tables -WHERE table_schema in ('mysql', 'performance_schema', 'information_schema')""" +SELECT table_schema, table_name, + IFNULL(index_length/1024/1024,0) AS index_size_mb, + IFNULL(data_length/1024/1024,0) AS data_size_mb +FROM information_schema.tables +WHERE table_schema in ('mysql', 'performance_schema', 'information_schema')""" SQL_AVG_QUERY_RUN_TIME = """\ SELECT schema_name, ROUND((SUM(sum_timer_wait) / SUM(count_star)) / 1000000) AS avg_us diff --git a/mysql/metadata.csv b/mysql/metadata.csv index 228a1c5a356a6..48e8158af91d9 100644 --- a/mysql/metadata.csv +++ b/mysql/metadata.csv @@ -1,7 +1,7 @@ metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric mysql.info.schema.size,gauge,,mebibyte,,"Size of schemas in MiB",0,mysql,mysql schema size, mysql.info.table.rows.read,count,,row,,"Total number of rows read per table (Percona userstat only)",0,mysql,mysql table rows read, -mysql.info.table.rows.update,count,,row,,"Total number of rows changed per table (Percona userstat only)",0,mysql,mysql table rows changed, +mysql.info.table.rows.changed,count,,row,,"Total number of rows changed per table (Percona userstat only)",0,mysql,mysql table rows changed, mysql.info.table.index_size,gauge,,mebibyte,,"Size of tables index in MiB",0,mysql,mysql index table size, mysql.info.table.data_size,gauge,,mebibyte,,"Size of tables data in MiB",0,mysql,mysql data table size,memory mysql.galera.wsrep_cluster_size,gauge,,node,,The current number of nodes in the Galera cluster.,0,mysql,galera cluster size,