Datadog SQL Server Integration

Quote

“Monitoring tells you whether a system is working, observability lets you ask why it isn’t working.”

Baron Schwartz

Integration Config File

Written to /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml:

Minimal config (integration only, no custom queries)

init_config:
 
instances:
  - host: localhost,1433
    username: dd_agent
    password: 'Dd@g3nt!Monitor'
    connector: odbc
    driver: '{ODBC Driver 18 for SQL Server}'
    connection_string: 'TrustServerCertificate=yes'
    tags:
      - env:prod
      - service:data-pipeline-sql

Full config with custom queries — see datadog-custom-queries for the complete file including both custom query blocks.


SQL Server Integration Connection Parameters

ParameterValueNotes
hostlocalhost,1433Comma-separated host and port (not colon) — SQL Server ODBC convention
connectorodbcUses the system ODBC driver manager
driver{ODBC Driver 18 for SQL Server}Must be installed via msodbcsql18 package
connection_stringTrustServerCertificate=yesRequired for self-signed dev certificate on SQL Server 2022 Developer edition
username / passworddd_agentRead-only login with VIEW SERVER STATE — see datadog-agent-sql-vm

TrustServerCertificate

SQL Server 2022 uses a self-signed certificate by default. Without TrustServerCertificate=yes, the ODBC driver will refuse to connect. Do not use this in production environments with real certificates — instead, configure a proper certificate and remove this setting. See server-configuration for the full SQL Server instance setup including certificate and network configuration.

Production Certificate Setup

Provision a CA-signed certificate for SQL Server, configure it in SQL Server Configuration Manager, then remove TrustServerCertificate=yes from connection_string. This ensures the ODBC driver validates the certificate and the connection is genuinely encrypted.


Built-in SQL Server Metrics Collected by Datadog

The integration automatically collects these metric groups from SQL Server DMVs:

MetricDescription
sqlserver.stats.connectionsTotal active connections
sqlserver.stats.batch_requestsBatch requests per second (overall throughput)
sqlserver.stats.lock_waitsLock waits per second — correlates with wait types like LCK_M_*
sqlserver.buffer.cache_hit_ratioBuffer cache hit ratio (%) — target > 99%
sqlserver.buffer.page_life_expectancySeconds a page stays in buffer pool — target > 300
sqlserver.buffer.checkpoint_pagesCheckpoint pages flushed per second
sqlserver.buffer.pool_sizeBuffer pool size in pages

Buffer Cache Hit Ratio

Should stay above 99%. Drops below 95% indicate memory pressure — SQL Server is reading from disk instead of RAM. See essential-dba-queries for DMV queries to diagnose memory pressure.

Page Life Expectancy

Higher is better. Drops below 300 seconds indicate memory pressure and frequent page evictions from the buffer pool.


Missing VIEW SERVER STATE permission

If the dd_agent SQL login lacks VIEW SERVER STATE permission, the Datadog agent connects successfully but returns zero values for most metrics (connections, buffer pool, waits). The agent logs no error — it simply reports 0 for every DMV-backed metric. Always verify with SELECT HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE') from the dd_agent session.

Fix: Grant VIEW SERVER STATE

Connect as sa and run: GRANT VIEW SERVER STATE TO dd_agent;. Restart the Datadog agent, then verify with sudo datadog-agent check sqlserver — metric values should now be non-zero.

Verifying the SQL Server Integration

# Check SQL Server integration status
sudo datadog-agent check sqlserver
 
# Check integration status in the full status output
sudo datadog-agent status | grep -A 10 "Integrations" | grep -A 5 "sqlserver"

Expected: Status: OK with metric counts listed.


Restarting After SQL Server Config Changes

# Restart the agent to pick up config changes
sudo systemctl restart datadog-agent
 
# Wait a few seconds, then verify
sudo datadog-agent check sqlserver 2>&1 | grep -i "error|ok|instance"

YAML Tabs

YAML does not allow tab characters. If the config file was edited in an editor that inserted tabs, the agent will silently fail to load it. Check with:

sudo cat -A /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml | head -40

Tabs appear as ^I. Replace all with spaces.

Fix: Replace Tabs with Spaces

Run sudo sed -i 's/\t/ /g' /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml to replace all tab characters with two spaces. Re-verify with cat -A, then restart the agent with sudo systemctl restart datadog-agent.