-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit index usage and index size metrics from mysql integration (#19383)
* Emit index usage and size metrics * Add logs for debugging * Use query executor to run index usage queries * Set collection interval to 5 min * linter, change log, and config validation * clean up * sort metadata.csv * sync models * magic number replaced with var * linter * make collection interval configurable * fix spec.yaml * sync models * update readme, report size in bytes, don't exclude primary * updated spec description
- Loading branch information
1 parent
f184aa2
commit 778d9c7
Showing
12 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Emit index usage and index metrics from mysql integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# (C) Datadog, Inc. 2025-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
from datadog_checks.base import is_affirmative | ||
|
||
QUERY_INDEX_SIZE = { | ||
'name': 'mysql.innodb_index_stats', | ||
'query': """ | ||
SELECT | ||
database_name, | ||
table_name, | ||
index_name, | ||
stat_value * @@innodb_page_size AS index_size_bytes | ||
FROM | ||
mysql.innodb_index_stats | ||
WHERE | ||
stat_name = 'size' | ||
""".strip(), | ||
'columns': [ | ||
{'name': 'db', 'type': 'tag'}, | ||
{'name': 'table', 'type': 'tag'}, | ||
{'name': 'index', 'type': 'tag'}, | ||
{'name': 'mysql.index.size', 'type': 'gauge'}, | ||
], | ||
} | ||
QUERY_INDEX_USAGE = { | ||
'name': 'performance_schema.table_io_waits_summary_by_index_usage', | ||
'query': """ | ||
SELECT | ||
object_schema, | ||
object_name, | ||
index_name, | ||
count_read, | ||
count_update, | ||
count_delete | ||
FROM | ||
performance_schema.table_io_waits_summary_by_index_usage | ||
WHERE index_name IS NOT NULL | ||
AND object_schema NOT IN ('mysql', 'performance_schema') | ||
""".strip(), | ||
'columns': [ | ||
{'name': 'db', 'type': 'tag'}, | ||
{'name': 'table', 'type': 'tag'}, | ||
{'name': 'index', 'type': 'tag'}, | ||
{'name': 'mysql.index.reads', 'type': 'gauge'}, | ||
{'name': 'mysql.index.updates', 'type': 'gauge'}, | ||
{'name': 'mysql.index.deletes', 'type': 'gauge'}, | ||
], | ||
} | ||
|
||
DEFAULT_INDEX_METRIC_COLLECTION_INTERVAL = 300 # 5 minutes | ||
|
||
|
||
class MySqlIndexMetrics: | ||
def __init__(self, config): | ||
self._config = config | ||
|
||
@property | ||
def include_index_metrics(self) -> bool: | ||
return is_affirmative(self._config.index_config.get('enabled', True)) | ||
|
||
@property | ||
def collection_interval(self) -> int: | ||
return int(self._config.index_config.get('collection_interval', DEFAULT_INDEX_METRIC_COLLECTION_INTERVAL)) | ||
|
||
@property | ||
def queries(self): | ||
# make a copy of the query to avoid modifying the original | ||
# in case different instances have different collection intervals | ||
usage_query = QUERY_INDEX_USAGE.copy() | ||
size_query = QUERY_INDEX_SIZE.copy() | ||
usage_query['collection_interval'] = self.collection_interval | ||
size_query['collection_interval'] = self.collection_interval | ||
return [size_query, usage_query] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters