Add custom_queries to your postgres.d/conf.yaml file.
If the query reads from a table the datadog user cannot already access, grant the permission first:
GRANT SELECT ON <TABLE_NAME> TO datadog;
Example: The following company table contains employee records:
id | name | age | address | salary
---------------------------------------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 30000
3 | Teddy | 23 | Norway | 45000
To collect age and salary as metrics with name and address as tags:
custom_queries:
- metric_prefix: postgresql.employee
query: SELECT age, salary, name, address FROM company
columns:
- name: employee_age
type: gauge
- name: employee_salary
type: gauge
- name: name
type: tag
- name: address
type: tag
tags:
- source:hr_db
After you update the file, restart the Agent.
For the full configuration reference, see Postgres Custom Metric Collection.
Add custom_queries to your mysql.d/conf.yaml file.
Important: All table references must include the database name (database_name.table_name). If you omit the database name, the Agent fails with the error: No database selected.
Example: The following company table in the testdb database contains employee records:
id | name | age | address | salary
---------------------------------------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 30000
3 | Teddy | 23 | Norway | 45000
To collect age and salary as metrics with name and address as tags:
custom_queries:
- metric_prefix: mysql.employee
query: SELECT age, salary, name, address FROM testdb.company
columns:
- name: employee_age
type: gauge
- name: employee_salary
type: gauge
- name: name
type: tag
- name: address
type: tag
tags:
- source:hr_db
After you update the file, restart the Agent.
For the full configuration reference, see MySQL Custom Queries.
SQL Server supports two approaches for collecting custom metrics: custom queries or performance counters.
Custom queries
Add custom_queries to your sqlserver.d/conf.yaml file to collect metrics from any table.
Example: The following company table in testdb contains employee records:
id | name | age | address | salary
---------------------------------------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 30000
3 | Teddy | 23 | Norway | 45000
To collect age and salary as metrics with name and address as tags:
custom_queries:
- metric_prefix: sqlserver.employee
query: SELECT age, salary, name, address FROM testdb.dbo.company
columns:
- name: employee_age
type: gauge
- name: employee_salary
type: gauge
- name: name
type: tag
- name: address
type: tag
tags:
- source:hr_db
Use custom_metrics to collect metrics from sys.dm_os_performance_counters and other system DMVs.
custom_metrics:
- name: sqlserver.clr.execution
counter_name: CLR Execution
| Option | Required | Description |
|---|
name | Yes | The metric name in Datadog. |
counter_name | Yes | The counter name from sys.dm_os_performance_counters. |
instance_name | No | A specific counter instance. Use ALL to collect all instances (requires tag_by). |
tag_by | No | Tag name used to differentiate instances when instance_name: ALL. |
After you update the file, restart the Agent.
For the full configuration reference, including performance counter details and the legacy stored procedure method, see Collect SQL Server Custom Metrics.