-
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.
Use query executor to run index usage queries
- Loading branch information
1 parent
4ada445
commit 581ed03
Showing
9 changed files
with
198 additions
and
125 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,74 @@ | ||
# (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, | ||
ROUND(stat_value * @@innodb_page_size/1024/1024, 2) AS index_size_mb | ||
FROM | ||
mysql.innodb_index_stats | ||
WHERE | ||
stat_name = 'size' AND | ||
index_name != 'PRIMARY' | ||
""".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 | ||
index_name != 'PRIMARY' 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'}, | ||
], | ||
} | ||
|
||
class MySqlIndexMetrics(): | ||
def __init__(self, config): | ||
self._config = config | ||
|
||
@property | ||
def include_index_metrics(self) -> bool: | ||
return is_affirmative(self._config.options.get('index_metrics', True)) | ||
@property | ||
def collection_interval(self) -> int: | ||
# TODO ALLEN: change this to 300 | ||
return 60 | ||
|
||
@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
Oops, something went wrong.