Skip to content

Commit b810262

Browse files
Add mysql.uptime metric (DataDog#24802)
* Add mysql.uptime metric The Uptime status variable was already returned by the SHOW GLOBAL STATUS query the check runs, but was never mapped to a metric name and so was discarded. Map it so users can alert on and correlate server restarts without resorting to a custom query. Named mysql.uptime to match both Datadog's convention across database integrations (postgresql.uptime, mongodb.uptime, proxysql.uptime) and the OpenTelemetry mysqlreceiver metric of the same name. Co-authored-by: Cursor <cursoragent@cursor.com> * Add changelog entry Co-authored-by: Cursor <cursoragent@cursor.com> * Warn when an additional_status entry is shadowed by a built-in metric --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a2ea619 commit b810262

6 files changed

Lines changed: 8 additions & 2 deletions

File tree

mysql/changelog.d/24802.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the ``mysql.uptime`` metric, reporting the number of seconds the server has been up.

mysql/datadog_checks/mysql/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
# Vars found in "SHOW STATUS;"
1818
STATUS_VARS = {
19+
# Server Metrics
20+
'Uptime': ('mysql.uptime', GAUGE),
1921
# Command Metrics
2022
'Prepared_stmt_count': ('mysql.performance.prepared_stmt_count', GAUGE),
2123
'Slow_queries': ('mysql.performance.slow_queries', RATE),

mysql/datadog_checks/mysql/mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def _collect_metrics(self, db, tags):
697697
status_metric = status_dict["metric_name"]
698698
if status_name in metrics.keys():
699699
collected_metric = metrics.get(status_name)[0]
700-
self.log.debug(
700+
self.warning(
701701
"Skipping status variable %s for metric %s as it is already collected by %s",
702702
status_name,
703703
status_metric,

mysql/metadata.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,4 @@ mysql.replication.seconds_behind_master,gauge,,second,,The lag in seconds betwee
253253
mysql.replication.seconds_behind_source,gauge,,second,,The lag in seconds between the source and the replica.,-1,mysql,replication lag,
254254
mysql.replication.slave_running,gauge,,,,Deprecated. Use service check mysql.replication.replica_running instead. A boolean showing if this server is a replication slave / master that is running.,0,mysql,slave running,
255255
mysql.replication.slaves_connected,gauge,,,,Deprecated. Use `mysql.replication.replicas_connected` instead. Number of slaves connected to a replication master.,0,mysql,slaves connected,
256+
mysql.uptime,gauge,,second,,The number of seconds that the server has been up.,0,mysql,uptime,

mysql/tests/test_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def test_additional_variable_unknown(aggregator, dd_run_check, instance_invalid_
798798
@pytest.mark.usefixtures('dd_environment')
799799
def test_additional_status_already_queried(aggregator, dd_run_check, instance_status_already_queried, caplog):
800800
caplog.clear()
801-
caplog.set_level(logging.DEBUG)
801+
caplog.set_level(logging.WARNING)
802802
mysql_check = MySql(common.CHECK_NAME, {}, [instance_status_already_queried])
803803
dd_run_check(mysql_check)
804804

mysql/tests/variables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
STATUS_VARS = [
5+
# Server Metrics
6+
'mysql.uptime',
57
# Command Metrics
68
'mysql.performance.prepared_stmt_count',
79
'mysql.performance.slow_queries',

0 commit comments

Comments
 (0)