![]() |
VOOZH | about |
Database Monitoring provides deep visibility into your Microsoft SQL Server databases by exposing query metrics, query samples, explain plans, database states, failovers, and events.
Do the following steps to enable Database Monitoring with your database:
The Datadog Agent requires read-only access to the database server in order to collect statistics and queries.
Create a read-only login to connect to your server and grant the required permissions:
CREATELOGINdatadogWITHPASSWORD='<PASSWORD>';CREATEUSERdatadogFORLOGINdatadog;GRANTCONNECTANYDATABASEtodatadog;GRANTVIEWSERVERSTATEtodatadog;GRANTVIEWANYDEFINITIONtodatadog;-- If not using either of Log Shipping Monitoring (available in Agent v7.50+) or
-- SQL Server Agent Monitoring (available in Agent v7.57+), comment out the next three lines:
USEmsdb;CREATEUSERdatadogFORLOGINdatadog;GRANTSELECTtodatadog;CREATELOGINdatadogWITHPASSWORD='<PASSWORD>';CREATEUSERdatadogFORLOGINdatadog;GRANTVIEWSERVERSTATEtodatadog;GRANTVIEWANYDEFINITIONtodatadog;-- If not using either of Log Shipping Monitoring (available in Agent v7.50+) or
-- SQL Server Agent Monitoring (available in Agent v7.57+), comment out the next three lines:
USEmsdb;CREATEUSERdatadogFORLOGINdatadog;GRANTSELECTtodatadog;Create the datadog user in each additional application database:
USE[database_name];CREATEUSERdatadogFORLOGINdatadog;Store your password using secret management software such as Vault. You can then reference this password as ENC[<SECRET_NAME>] in your Agent configuration files: for example, ENC[datadog_user_database_password]. See Secrets Management for more information.
The examples on this page use datadog_user_database_password to refer to the name of the secret where your password is stored. It is possible to reference your password in plain text, but this is not recommended.
It’s recommended to install the agent directly on the SQL Server host as that enables the agent to collect a variety of system telemetry (CPU, memory, disk, network) in addition to SQL Server specific telemetry.
Note: For AlwaysOn users, the recommended approach is to install the Agent on each individual replica, which will help provide related infrastructure metrics (CPU, memory, networking) for each replica. Telemetry for the relevant availability groups will be collected from each replica the agent is connected to. As a fallback method, the Agent can be installed on a separate server and connected to the cluster through the listener endpoint, but this will make it impossible to relate infrastructure metrics for the underlying host. To start collecting SQL Server telemetry, first install the Datadog Agent.
Create the SQL Server Agent conf file C:\ProgramData\Datadog\conf.d\sqlserver.d\conf.yaml. See the sample conf file for all available configuration options.
init_config:instances:- dbm:truehost:'<HOSTNAME>,<PORT>'username:datadogpassword:'ENC[datadog_user_database_password]'connector:adodbapiadoprovider:MSOLEDBSQL# Optional: For additional tagstags:- 'service:<CUSTOM_SERVICE>'- 'env:<CUSTOM_ENV>'To use Windows Authentication, set connection_string: "Trusted_Connection=yes" and omit the username and password fields.
The agent supports SQL Server Browser Service in versions 7.41+. To enable SSBS, provide a port of 0 in the host string: <HOSTNAME>,0.
Use the service and env tags to link your database telemetry to other telemetry through a common tagging scheme. See Unified Service Tagging on how these tags are used throughout Datadog.
The recommended ADO provider is Microsoft OLE DB Driver. Ensure the driver is installed on the host where the agent is running.
connector:adodbapiadoprovider:MSOLEDBSQL19 # Replace with MSOLEDBSQL for versions 18 and lowerThe other two providers, SQLOLEDB and SQLNCLI, are considered deprecated by Microsoft and should no longer be used.
The recommended ODBC driver is Microsoft ODBC Driver. Ensure the driver is installed on the host where the Agent is running.
connector:odbcdriver:'ODBC Driver 18 for SQL Server'Once all Agent configuration is complete, restart the Datadog Agent.
Run the Agent’s status subcommand and look for sqlserver under the Checks section. Navigate to the Databases page in Datadog to get started.
Note: For AlwaysOn users, the recommended approach is to install the Agent on each individual replica, which will help provide related infrastructure metrics (CPU, memory, networking) for each replica. Telemetry for the relevant availability groups will be collected from each replica the agent is connected to. As a fallback method, the Agent can be installed on a separate server and connected to the cluster through the listener endpoint, but this will make it impossible to relate infrastructure metrics for the underlying host. To start collecting SQL Server telemetry, first install the Datadog Agent.
On Linux, the Datadog Agent additionally requires an ODBC SQL Server driver to be installed—for example, the Microsoft ODBC driver. Once an ODBC SQL Server is installed, copy the odbc.ini and odbcinst.ini files into the /opt/datadog-agent/embedded/etc folder.
Use the odbc connector and specify the proper driver as indicated in the odbcinst.ini file.
Create the SQL Server Agent conf file /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml. See the sample conf file for all available configuration options.
init_config:instances:- dbm:truehost:'<HOSTNAME>,<PORT>'username:datadogpassword:'ENC[datadog_user_database_password]'connector:odbcdriver:'<Driver from the `odbcinst.ini` file>'# Optional: For additional tagstags:- 'service:<CUSTOM_SERVICE>'- 'env:<CUSTOM_ENV>'Use the service and env tags to link your database telemetry to other telemetry through a common tagging scheme. See Unified Service Tagging on how these tags are used throughout Datadog.
Once all Agent configuration is complete, restart the Datadog Agent.
Run the Agent’s status subcommand and look for sqlserver under the Checks section. Navigate to the Databases page in Datadog to get started.
Locate the odbc.ini and odbcinst.ini files. By default, these are placed in the /etc directory when installing ODBC.
Copy the odbc.ini and odbcinst.ini files into the /opt/datadog-agent/embedded/etc folder.
Configure your DSN settings as follows:
odbcinst.ini must provide at least one section header and ODBC driver location.
Example:
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
UsageCount=1
odbc.ini must provide a section header and a Driver path that matches odbcinst.ini.
Example:
[datadog]
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
Update the /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml file with your DSN information.
Example:
instances:- dbm:truehost:'localhost,1433'username:datadogpassword:'ENC[datadog_user_database_password]'connector:'odbc'driver:'ODBC Driver 18 for SQL Server'# This is the section header of odbcinst.inidsn:'datadog'# This is the section header of odbc.iniRestart the Agent.
For AlwaysOn users, the Agent should be installed on each replica server and connected directly to each replica. The full set of AlwaysOn telemetry is collected from each individual replica, in addition to host-based telemetry (CPU, disk, memory, and so on) for each server.
instances:- dbm:truehost:'shopist-prod,1433'username:datadogpassword:'ENC[datadog_user_database_password]'connector:adodbapiadoprovider:MSOLEDBSQLdatabase_metrics:# If Availability Groups is enabledao_metrics:enabled:true# If Failover Clustering is enabledfci_metrics:enabled:trueMonitoring of SQL Server Agent jobs is supported on SQL Server versions 2016 and newer. Starting from Agent v7.57, the Datadog Agent can collect SQL Server Agent job metrics and histories. To enable this feature, set enabled to true in the agent_jobs section of the SQL Server integration configuration file. The collection_interval and history_row_limit fields are optional.
instances:- dbm:truehost:'shopist-prod,1433'username:datadogpassword:'<PASSWORD>'connector:adodbapiadoprovider:MSOLEDBSQLagent_jobs:enabled:truecollection_interval:15history_row_limit:10000To enable this feature, use the collect_schemas option. Schemas are collected on databases for which the Agent has CONNECT access.
datadog user explicit CONNECT access to each database on the instance. For more information, see Grant the Agent access.Use the database_autodiscovery option to avoid specifying each logical database. See the sample sqlserver.d/conf.yaml for more details.
init_config:instances:# This instance detects every logical database automatically- dbm:truehost:'shopist-prod,1433'username:datadogpassword:'ENC[datadog_user_database_password]'connector:adodbapiadoprovider:MSOLEDBSQLdatabase_autodiscovery:truecollect_schemas:enabled:truedatabase_metrics:# Optional: enable metric collection for indexesindex_usage_metrics:enabled:true# This instance only collects schemas and index metrics from the `users` database- dbm:truehost:'shopist-prod,1433'username:datadogpassword:'ENC[datadog_user_database_password]'connector:adodbapiadoprovider:MSOLEDBSQLdatabase:userscollect_schemas:enabled:truedatabase_metrics:# Optional: enable metric collection for indexesindex_usage_metrics:enabled:trueNote: For Agent v7.68 and below, use schemas_collection instead of collect_schemas.
It is common to configure a single Agent host to connect to multiple remote database instances (see Agent installation architectures for DBM). To connect to multiple hosts, create an entry for each host in the SQL Server integration config.
init_config:instances:- dbm:truehost:'example-service-primary.example-host.com,1433'username:datadogconnector:adodbapiadoprovider:MSOLEDBSQLpassword:'ENC[datadog_user_database_password]'tags:- 'env:prod'- 'team:team-discovery'- 'service:example-service'- dbm:truehost:'example-service–replica-1.example-host.com,1433'connector:adodbapiadoprovider:MSOLEDBSQLusername:datadogpassword:'ENC[datadog_user_database_password]'tags:- 'env:prod'- 'team:team-discovery'- 'service:example-service'- dbm:truehost:'example-service–replica-2.example-host.com,1433'connector:adodbapiadoprovider:MSOLEDBSQLusername:datadogpassword:'ENC[datadog_user_database_password]'tags:- 'env:prod'- 'team:team-discovery'- 'service:example-service'[...]To collect custom metrics, use the custom_queries option. See the sample sqlserver.d/conf.yaml for more details.
init_config:instances:- dbm:truehost:'localhost,1433'connector:adodbapiadoprovider:MSOLEDBSQLusername:datadogpassword:'ENC[datadog_user_database_password]'custom_queries:- query:SELECT age, salary, hours_worked, name FROM hr.employees;columns:- name:custom.employee_agetype:gauge- name:custom.employee_salarytype:gauge- name:custom.employee_hourstype:count- name:nametype:tagtags:- 'table:employees'If the Agent must connect to a database host through a remote proxy, all telemetry is tagged with the hostname of the proxy rather than the database instance. Use the reported_hostname option to set a custom override of the hostname detected by the Agent.
init_config:instances:- dbm:truehost:'localhost,1433'connector:adodbapiadoprovider:MSOLEDBSQLusername:datadogpassword:'ENC[datadog_user_database_password]'reported_hostname:products-primary- dbm:truehost:'localhost,1433'connector:adodbapiadoprovider:MSOLEDBSQLusername:datadogpassword:'ENC[datadog_user_database_password]'reported_hostname:products-replica-1SQL Server Browser Service, Named Instances, and other services can automatically detect port numbers. You can use this instead of hardcoding port numbers in connection strings. To use the Agent with one of these services, set the port field to 0.
For example, a Named Instance config:
init_config:instances:- host:<hostname\instance name>port:0Additional helpful documentation, links, and articles:
| |