---
title: SQL Server Metrics
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > OpenTelemetry in Datadog > Integrations > SQL Server Metrics
---

# SQL Server Metrics

## Overview{% #overview %}

The [SQL Server receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlserverreceiver) allows for collection of SQL Server metrics and access to the [SQL Server Overview](https://app.datadoghq.com/dash/integration/236/sql-server---overview) and [SQL Server Metrics](https://app.datadoghq.com/dash/integration/33/sqlserver---metrics) dashboards. Configure the receiver according to the specifications of the latest version of the `sqlserverreceiver`.

For more information, see the OpenTelemetry project documentation for the [SQL Server receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlserverreceiver).

## Setup{% #setup %}

To collect SQL Server metrics with OpenTelemetry for use with Datadog:

1. Configure the [SQL Server receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlserverreceiver) in your OpenTelemetry Collector configuration.
1. Optionally, configure the [host metrics receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/hostmetricsreceiver) if your OpenTelemetry Collector is running on the same server as your SQL Server database.
1. Optionally, configure the [file log receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver) if your OpenTelemetry Collector is running on the same server as your SQL Server database.
1. Configure service pipelines.
1. Ensure the OpenTelemetry Collector is [configured to export to Datadog](https://docs.datadoghq.com/opentelemetry/setup/collector_exporter.md).

### SQL Server receiver{% #sql-server-receiver %}

The SQL Server receiver supports two collection methods: Windows Performance Counters (Windows only) or direct connection. This configuration uses the direct connection method.

```yaml
receivers:
  sqlserver:
    server: "<HOST>"
    port: <PORT>
    username: "<USERNAME>"
    password: "<PASSWORD>"
    collection_interval: 15s
    metrics:
      sqlserver.processes.blocked:
        enabled: true
      sqlserver.cpu.count:
        enabled: true
      sqlserver.computer.uptime:
        enabled: true
      sqlserver.database.io:
        enabled: true
      sqlserver.database.latency:
        enabled: true
      sqlserver.database.operations:
        enabled: true

processors:
  resource:
    attributes:
      - key: host.name
        value: "<HOST>"
        action: upsert
  transform/fix_rate_counters:
    metric_statements:
      - context: metric
        statements:
          - convert_gauge_to_sum("cumulative", true) where metric.name == "sqlserver.batch.request.rate"
          - convert_gauge_to_sum("cumulative", true) where metric.name == "sqlserver.batch.sql_compilation.rate"
          - convert_gauge_to_sum("cumulative", true) where metric.name == "sqlserver.batch.sql_recompilation.rate"
          - convert_gauge_to_sum("cumulative", true) where metric.name == "sqlserver.lock.wait.rate"
  cumulativetodelta:
    include:
      match_type: strict
      metrics:
        - sqlserver.database.io
        - sqlserver.database.latency
        - sqlserver.database.operations
        - sqlserver.batch.request.rate
        - sqlserver.batch.sql_compilation.rate
        - sqlserver.batch.sql_recompilation.rate
        - sqlserver.lock.wait.rate
  deltatorate:
    metrics:
      - sqlserver.batch.request.rate
      - sqlserver.batch.sql_compilation.rate
      - sqlserver.batch.sql_recompilation.rate
      - sqlserver.lock.wait.rate
```

See the [SQL Server receiver documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlserverreceiver) for detailed configuration options and requirements.

### Host metrics receiver{% #host-metrics-receiver %}

```yaml
receivers:
  hostmetrics:
    scrapers:
      load:
      cpu:
        metrics:
         system.cpu.utilization:
           enabled: true
      memory:
      network:
```

### File log receiver{% #file-log-receiver %}

```yaml
receivers:
  filelog:
    include:
      - <PATH_TO_YOUR_SQLSERVER_LOG>
    operators:
      - type: regex_parser
        regex: '^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+) (?P<message>.*)'
        timestamp:
          parse_from: attributes.timestamp
          layout: "%Y-%m-%d %H:%M:%S.%f"

processors:
  transform/logs:
    log_statements:
      - context: resource
        statements:
          - set(attributes["datadog.host.name"], "<HOST>")
          - set(attributes["datadog.log.source"], "sqlserver")
```

### Service pipelines{% #service-pipelines %}

```yaml
service:
  pipelines:
    metrics:
      receivers: [sqlserver]
      processors: [resource, transform/fix_rate_counters, cumulativetodelta, deltatorate]
      exporters: [datadog/exporter]
```

If you configured the host metrics receiver, add it to a separate metrics pipeline:

```yaml
    metrics/host:
      receivers: [hostmetrics]
      exporters: [datadog/exporter]
```

If you configured the file log receiver, add a logs pipeline:

```yaml
    logs:
      receivers: [filelog]
      processors: [transform/logs]
      exporters: [datadog/exporter]
```

## Data collected{% #data-collected %}

| OTEL                                   | DATADOG                               | DESCRIPTION                                                                            | FILTER               | TRANSFORM |
| -------------------------------------- | ------------------------------------- | -------------------------------------------------------------------------------------- | -------------------- | --------- |
| sqlserver.batch.request.rate           | sqlserver.stats.batch_requests        | Number of batch requests received by SQL Server.                                       |
| sqlserver.batch.sql_compilation.rate   | sqlserver.stats.sql_compilations      | Number of SQL compilations needed.                                                     |
| sqlserver.batch.sql_recompilation.rate | sqlserver.stats.sql_recompilations    | Number of SQL recompilations needed.                                                   |
| sqlserver.computer.uptime              | sqlserver.server.uptime               | Computer uptime.                                                                       |
| sqlserver.cpu.count                    | sqlserver.server.cpu_count            | Number of CPUs.                                                                        |
| sqlserver.database.io                  | sqlserver.files.read_bytes            | The number of bytes of I/O on this file.                                               | `direction`: `read`  |
| sqlserver.database.io                  | sqlserver.files.written_bytes         | The number of bytes of I/O on this file.                                               | `direction`: `write` |
| sqlserver.database.latency             | sqlserver.files.read_io_stall         | Total time that the users waited for I/O issued on this file.                          | `direction`: `read`  | × 1000    |
| sqlserver.database.latency             | sqlserver.files.write_io_stall        | Total time that the users waited for I/O issued on this file.                          | `direction`: `write` | × 1000    |
| sqlserver.database.operations          | sqlserver.files.writes                | The number of operations issued on the file.                                           | `direction`: `write` |
| sqlserver.database.operations          | sqlserver.files.reads                 | The number of operations issued on the file.                                           | `direction`: `read`  |
| sqlserver.lock.wait.rate               | sqlserver.stats.lock_waits            | Number of lock requests resulting in a wait.                                           |
| sqlserver.page.buffer_cache.hit_ratio  | sqlserver.buffer.cache_hit_ratio      | Pages found in the buffer pool without having to read from disk.                       | × 0.01               |
| sqlserver.page.life_expectancy         | sqlserver.buffer.page_life_expectancy | Time a page will stay in the buffer pool.                                              |
| sqlserver.page.split.rate              | sqlserver.access.page_splits          | Number of pages split as a result of overflowing index pages.                          |
| sqlserver.processes.blocked            | sqlserver.stats.procs_blocked         | The number of processes that are currently blocked                                     |
| sqlserver.transaction.rate             | sqlserver.database.transactions       | Number of transactions started for the database (not including XTP-only transactions). |
| sqlserver.transaction.write.rate       | sqlserver.database.write_transactions | Number of transactions that wrote to the database and committed.                       |
| sqlserver.user.connection.count        | sqlserver.stats.connections           | Number of users connected to the SQL Server.                                           |

See [OpenTelemetry Metrics Mapping](https://docs.datadoghq.com/opentelemetry/guide/metrics_mapping.md) for more information.

## Further reading{% #further-reading %}

- [Setting Up the OpenTelemetry Collector](https://docs.datadoghq.com/opentelemetry/collector_exporter.md)
