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

# MySQL Metrics

## Overview{% #overview %}

{% image
   source="https://docs.dd-static.net/images/opentelemetry/collector_exporter/mysql_metrics.c85e1516ba5fafcd2a34f7f47a25f728.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/opentelemetry/collector_exporter/mysql_metrics.c85e1516ba5fafcd2a34f7f47a25f728.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="OpenTelemetry MySQL metrics in a MySQL dashboard" /%}

The [MySQL receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mysqlreceiver) allows for collection of MySQL metrics and access to the [MySQL Overview](https://app.datadoghq.com/dash/integration/12/mysql---overview) dashboard. Configure the receiver according to the specifications of the latest version of the `mysqlreceiver`.

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

## Setup{% #setup %}

To collect MySQL metrics with OpenTelemetry for use with Datadog:

1. Configure the [MySQL receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mysqlreceiver) 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 MySQL 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 MySQL 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).

### MySQL receiver{% #mysql-receiver %}

```
receivers:
  mysql/mysql-host-1:
    endpoint: "<HOST>:<PORT>"
    username: "<USERNAME>"
    password: "<PASSWORD>"
    collection_interval: 10s
    metrics:
      mysql.connection.count:
        enabled: true
      mysql.connection.errors:
        enabled: true
      mysql.commands:
        enabled: true
      mysql.query.slow.count:
        enabled: true
      mysql.max_used_connections:
        enabled: true

processors:
  resource/mysql-host-1:
    attributes:
      - action: insert
        key: datadog.host.name
        value: <HOST>
  transform/mysql-host-1:
    metric_statements:
      - convert_sum_to_gauge() where metric.name == "mysql.locks"
  cumulativetodelta: {}
  deltatorate:
    metrics:
      - mysql.connection.count
      - mysql.commands
      - mysql.operations
      - mysql.query.slow.count
      - mysql.connection.errors
      - mysql.log_operations
      - system.network.io
```

See the [MySQL receiver documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mysqlreceiver) 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_MYSQL_ERROR_LOG>
      - <PATH_TO_YOUR_MYSQL_LOG_FILE>
    operators:
      - type: json_parser
        parse_from: body
        timestamp:
          parse_from: attributes.timestamp
          layout: "%Y-%m-%dT%H:%M:%SZ"

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

  batch: {}
```

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

```yaml
service:
  pipelines:
    metrics/mysql-host-1:
      receivers: [mysql/mysql-host-1]
      exporters: [datadog/exporter]
      processors: [resource/mysql-host-1,cumulativetodelta,deltatorate,transform/mysql-host-1]
```

Add `hostmetrics` and `filelog` receiver if you configured them, for example:

```yaml
      receivers: [mysql/mysql-host-1,hostmetrics,filelog]
```

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

| OTEL                             | DESCRIPTION                                                                 | FILTER                            |
| -------------------------------- | --------------------------------------------------------------------------- | --------------------------------- |
| mysql.buffer_pool.data_pages     | The number of data pages in the InnoDB buffer pool.                         | `status`: `dirty`                 |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `read_ahead`         |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `read_ahead_evicted` |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `read_ahead_rnd`     |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `read_requests`      |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `reads`              |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `wait_free`          |
| mysql.buffer_pool.operations     | The number of operations on the InnoDB buffer pool.                         | `operation`: `write_requests`     |
| mysql.buffer_pool.page_flushes   | The number of requests to flush pages from the InnoDB buffer pool.          |
| mysql.buffer_pool.pages          | The number of pages in the InnoDB buffer pool.                              | `kind`: `data`                    |
| mysql.buffer_pool.pages          | The number of pages in the InnoDB buffer pool.                              | `kind`: `free`                    |
| mysql.buffer_pool.usage          | The number of bytes in the InnoDB buffer pool.                              |
| mysql.buffer_pool.usage          | The number of bytes in the InnoDB buffer pool.                              | `status`: `dirty`                 |
| mysql.client.network.io          | The number of transmitted bytes between server and clients.                 | `kind`: `received`                |
| mysql.client.network.io          | The number of transmitted bytes between server and clients.                 | `kind`: `sent`                    |
| mysql.commands                   | The number of times each type of command has been executed.                 | `command`: `select`               |
| mysql.commands                   | The number of times each type of command has been executed.                 | `command`: `update`               |
| mysql.commands                   | The number of times each type of command has been executed.                 | `command`: `delete`               |
| mysql.commands                   | The number of times each type of command has been executed.                 | `command`: `insert`               |
| mysql.connection.count           | The number of connection attempts (successful or not) to the MySQL server.  |
| mysql.connection.errors          | Errors that occur during the client connection process.                     | `error`: `aborted`                |
| mysql.double_writes              | The number of writes to the InnoDB doublewrite buffer.                      | `kind`: `pages_written`           |
| mysql.double_writes              | The number of writes to the InnoDB doublewrite buffer.                      | `kind`: `writes`                  |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `write`                   |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `update`                  |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `rollback`                |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `read_rnd_next`           |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `read_rnd`                |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `read_prev`               |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `read_first`              |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `read_key`                |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `prepare`                 |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `delete`                  |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `commit`                  |
| mysql.handlers                   | The number of requests to various MySQL handlers.                           | `kind`: `read_next`               |
| mysql.joins                      | The number of joins that perform table scans.                               | `kind`: `scan`                    |
| mysql.joins                      | The number of joins that perform table scans.                               | `kind`: `range_check`             |
| mysql.joins                      | The number of joins that perform table scans.                               | `kind`: `full_range`              |
| mysql.joins                      | The number of joins that perform table scans.                               | `kind`: `range`                   |
| mysql.joins                      | The number of joins that perform table scans.                               | `kind`: `full`                    |
| mysql.locks                      | The number of MySQL locks.                                                  | `kind`: `immediate`               |
| mysql.locks                      | The number of MySQL locks.                                                  | `kind`: `waited`                  |
| mysql.log_operations             | The number of InnoDB log operations.                                        | `operation`: `waits`              |
| mysql.log_operations             | The number of InnoDB log operations.                                        | `operation`: `write_requests`     |
| mysql.log_operations             | The number of InnoDB log operations.                                        | `operation`: `writes`             |
| mysql.log_operations             | The number of InnoDB log operations.                                        | `operation`: `fsyncs`             |
| mysql.max_used_connections       | Maximum number of connections used simultaneously since the server started. |
| mysql.operations                 | The number of InnoDB operations.                                            | `operation`: `fsyncs`             |
| mysql.operations                 | The number of InnoDB operations.                                            | `operation`: `writes`             |
| mysql.operations                 | The number of InnoDB operations.                                            | `operation`: `reads`              |
| mysql.page_operations            | The number of InnoDB page operations.                                       | `operation`: `created`            |
| mysql.page_operations            | The number of InnoDB page operations.                                       | `operation`: `read`               |
| mysql.page_operations            | The number of InnoDB page operations.                                       | `operation`: `written`            |
| mysql.query.slow.count           | The number of slow queries.                                                 |
| mysql.replica.time_behind_source | This field is an indication of how "late" the replica is.                   |
| mysql.row_locks                  | The number of InnoDB row locks.                                             | `kind`: `waits`                   |
| mysql.row_locks                  | The number of InnoDB row locks.                                             |
| mysql.row_operations             | The number of InnoDB row operations.                                        | `operation`: `deleted`            |
| mysql.row_operations             | The number of InnoDB row operations.                                        | `operation`: `inserted`           |
| mysql.row_operations             | The number of InnoDB row operations.                                        | `operation`: `read`               |
| mysql.row_operations             | The number of InnoDB row operations.                                        | `operation`: `updated`            |
| mysql.sorts                      | The number of MySQL sorts.                                                  | `kind`: `merge_passes`            |
| mysql.sorts                      | The number of MySQL sorts.                                                  | `kind`: `range`                   |
| mysql.sorts                      | The number of MySQL sorts.                                                  | `kind`: `rows`                    |
| mysql.sorts                      | The number of MySQL sorts.                                                  | `kind`: `scan`                    |
| mysql.table_open_cache           | The number of hits, misses or overflows for open tables cache lookups.      | `status`: `hit`                   |
| mysql.table_open_cache           | The number of hits, misses or overflows for open tables cache lookups.      | `status`: `miss`                  |
| mysql.threads                    | The state of MySQL threads.                                                 | `kind`: `cached`                  |
| mysql.threads                    | The state of MySQL threads.                                                 | `kind`: `connected`               |
| mysql.threads                    | The state of MySQL threads.                                                 | `kind`: `created`                 |
| mysql.threads                    | The state of MySQL threads.                                                 | `kind`: `running`                 |
| mysql.tmp_resources              | The number of created temporary resources.                                  | `resource`: `files`               |
| mysql.tmp_resources              | The number of created temporary resources.                                  | `resource`: `disk_tables`         |
| mysql.tmp_resources              | The number of created temporary resources.                                  | `resource`: `tables`              |

For the full mapping between OpenTelemetry and Datadog metric names, see [OpenTelemetry Metrics Mapping](https://docs.datadoghq.com/opentelemetry/guide/metrics_mapping.md).

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

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