Skip to content

Commit

Permalink
Fix bug where mysql table row stats were not being collected (#12472)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeunier28 authored Jul 8, 2022
1 parent c6e0fe2 commit 0469419
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mysql/datadog_checks/mysql/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion mysql/datadog_checks/mysql/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions mysql/datadog_checks/mysql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mysql/metadata.csv
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 0469419

Please sign in to comment.