Skip to content

Commit

Permalink
Mysql additional vars (#10573)
Browse files Browse the repository at this point in the history
* added additional mysql status and variables

* modified sample conf yaml file

* rollback to original yaml file due to sync error

* add additional status and variable example on yaml

* add additional status and variable to spec and remove to duplicated context

* fixed wrong depth in sepc file

* fixed wrong text itmes to items on spec file

* modified description metric to metric_name on mysql spec

* check example file sync

* check model sync
  • Loading branch information
notemusic110 authored Nov 11, 2021
1 parent 8111683 commit 0186dbd
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mysql/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,41 @@ files:
type: gauge
tags:
- test:mysql
- name: additional_status
description: |
Set this parameter to collect mysql status exclude STATUS_VARS and OPTIONAL_STATUS_VARS of const
The following fields are supported:
name : mysql status name on "SHOW GLOBAL STATUS"
metric_name : datadog metric name
type : gauge | rate | count | ...
value:
type: array
items:
type: object
example:
- name: innodb_rows_read
metric_name: mysql.innodb.rows_read
type: rate

- name: additional_variable
description: |
Set this parameter to collect mysql variable exclude VARIABLES_VARS and another VARS of const
The following fields are supported:
name : mysql variable name on "SHOW GLOBAL VARIABLES"
metric_name : datadog metric name
type : gauge | rate | count | ...
value:
type: array
items:
type: object
example:
- name: long_query_time
metric_name: mysql.performance.long_query_time
type: gauge

- name: max_custom_queries
description: |
Expand Down
2 changes: 2 additions & 0 deletions mysql/datadog_checks/mysql/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, instance):
self.tags.append("channel:{0}".format(replication_channel))
self.queries = instance.get('queries', [])
self.ssl = instance.get('ssl', {})
self.additional_status = instance.get('additional_status', {})
self.additional_variable = instance.get('additional_variable', {})
self.connect_timeout = instance.get('connect_timeout', 10)
self.max_custom_queries = instance.get('max_custom_queries', DEFAULT_MAX_CUSTOM_QUERIES)
self.charset = instance.get('charset')
Expand Down
8 changes: 8 additions & 0 deletions mysql/datadog_checks/mysql/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def shared_service(field, value):
return get_default_field_value(field, value)


def instance_additional_status(field, value):
return get_default_field_value(field, value)


def instance_additional_variable(field, value):
return get_default_field_value(field, value)


def instance_charset(field, value):
return get_default_field_value(field, value)

Expand Down
2 changes: 2 additions & 0 deletions mysql/datadog_checks/mysql/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

additional_status: Optional[Sequence[Mapping[str, Any]]]
additional_variable: Optional[Sequence[Mapping[str, Any]]]
charset: Optional[str]
connect_timeout: Optional[float]
custom_queries: Optional[Sequence[CustomQuery]]
Expand Down
28 changes: 28 additions & 0 deletions mysql/datadog_checks/mysql/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ instances:
# tags:
# - test:mysql

## @param additional_status - list of mappings - optional
## Set this parameter to collect mysql status exclude STATUS_VARS and OPTIONAL_STATUS_VARS of const
##
## The following fields are supported:
##
## name : mysql status name on "SHOW GLOBAL STATUS"
## metric_name : datadog metric name
## type : gauge | rate | count | ...
#
# additional_status:
# - name: innodb_rows_read
# metric_name: mysql.innodb.rows_read
# type: rate

## @param additional_variable - list of mappings - optional
## Set this parameter to collect mysql variable exclude VARIABLES_VARS and another VARS of const
##
## The following fields are supported:
##
## name : mysql variable name on "SHOW GLOBAL VARIABLES"
## metric_name : datadog metric name
## type : gauge | rate | count | ...
#
# additional_variable:
# - name: long_query_time
# metric_name: mysql.performance.long_query_time
# type: gauge

## @param max_custom_queries - integer - optional - default: 20
## Set the maximum number of custom queries to execute with this integration.
##
Expand Down
12 changes: 12 additions & 0 deletions mysql/datadog_checks/mysql/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ def _collect_metrics(self, db, tags):
metrics.update(replication_metrics)
self._check_replication_status(results)

if len(self._config.additional_status) > 0:
additional_status_dict = {}
for status_dict in self._config.additional_status:
additional_status_dict[status_dict["name"]] = (status_dict["metric_name"], status_dict["type"])
metrics.update(additional_status_dict)

if len(self._config.additional_variable) > 0:
additional_variable_dict = {}
for variable_dict in self._config.additional_variable:
additional_variable_dict[variable_dict["name"]] = (variable_dict["metric_name"], variable_dict["type"])
metrics.update(additional_variable_dict)

# "synthetic" metrics
metrics.update(SYNTHETIC_VARS)
self._compute_synthetic_results(results)
Expand Down
48 changes: 48 additions & 0 deletions mysql/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,54 @@ def instance_complex():
}


@pytest.fixture
def instance_additional_status():
return {
'host': common.HOST,
'user': common.USER,
'pass': common.PASS,
'port': common.PORT,
'tags': tags.METRIC_TAGS,
'disable_generic_tags': 'true',
'additional_status': [
{
'name': "innodb_rows_read",
'metric_name': "mysql.innodb.rows_read",
'type': "rate",
},
{
'name': "row_lock_time",
'metric_name': "mysql.innodb.row_lock_time",
'type': "rate",
},
],
}


@pytest.fixture
def instance_additional_variable():
return {
'host': common.HOST,
'user': common.USER,
'pass': common.PASS,
'port': common.PORT,
'tags': tags.METRIC_TAGS,
'disable_generic_tags': 'true',
'additional_status': [
{
'name': "long_query_time",
'metric_name': "mysql.performance.long_query_time",
'type': "gauge",
},
{
'name': "innodb_flush_log_at_trx_commit",
'metric_name': "mysql.performance.innodb_flush_log_at_trx_commit",
'type': "gauge",
},
],
}


@pytest.fixture
def instance_custom_queries():
return {
Expand Down
20 changes: 20 additions & 0 deletions mysql/tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,23 @@ def test_custom_queries(aggregator, instance_custom_queries, dd_run_check):

aggregator.assert_metric('alice.age', value=25, tags=tags.METRIC_TAGS)
aggregator.assert_metric('bob.age', value=20, tags=tags.METRIC_TAGS)


@pytest.mark.integration
@pytest.mark.usefixtures('dd_environment')
def test_additional_status(aggregator, dd_run_check, instance_additional_status):
mysql_check = MySql(common.CHECK_NAME, {}, [instance_additional_status])
dd_run_check(mysql_check)

aggregator.assert_metric('mysql.innodb.rows_read', metric_type=1, tags=tags.METRIC_TAGS)
aggregator.assert_metric('mysql.innodb.row_lock_time', metric_type=1, tags=tags.METRIC_TAGS)


@pytest.mark.integration
@pytest.mark.usefixtures('dd_environment')
def test_additional_variable(aggregator, dd_run_check, instance_additional_variable):
mysql_check = MySql(common.CHECK_NAME, {}, [instance_additional_variable])
dd_run_check(mysql_check)

aggregator.assert_metric('mysql.performance.long_query_time', metric_type=0, tags=tags.METRIC_TAGS)
aggregator.assert_metric('mysql.performance.innodb_flush_log_at_trx_commit', metric_type=0, tags=tags.METRIC_TAGS)

0 comments on commit 0186dbd

Please sign in to comment.