Monitoring MySQL Performance using OpenTelemetry

OpenTelemetry MySQL

Monitoring MySQL performance is crucial to ensure the optimal operation of your MySQL database and identify any potential bottlenecks or issues.

This tutorial explains how you can use OpenTelemetry and Uptrace to proactively identify and address performance issues, optimize your MySQL database, and ensure its smooth operation.

What is OpenTelemetry Collector?

OpenTelemetry Collectoropen in new window is an agent that pulls telemetry data from systems you want to monitor and export the collected data to an OpenTelemetry backendopen in new window.

Otel Collector provides powerful data processing capabilities, allowing you to perform aggregation, filtering, sampling, and enrichment of telemetry data. You can transform and reshape the data to fit your specific monitoring and analysis requirements before sending it to the backend systems.

OpenTelemetry MySQL receiver

Using OpenTelemetry Collector, you can monitor key performance metrics provided by MySQL itself, such as CPU usage, memory utilization, disk I/O, network traffic, and query throughput.

To start monitoring MySQL, you need to configure MySQL receiveropen in new window in /etc/otel-contrib-collector/config.yaml using Uptrace DSN:

    endpoint: localhost:3306
    username: otel
    password: $MYSQL_PASSWORD
    database: otel
    collection_interval: 10s
      digest_text_limit: 120
      time_limit: 24h
      limit: 250

    headers: { 'uptrace-dsn': '<FIXME>' }

    detectors: [env, system]
    timeout: 10s

      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/uptrace]
      receivers: [otlp, mysql]
      processors: [cumulativetodelta, batch, resourcedetection]
      exporters: [otlp/uptrace]

Don't forget to restart OpenTelemetry Collector:

sudo systemctl restart otelcol-contrib

You can also check OpenTelemetry Collector logs for any errors:

sudo journalctl -u otelcol-contrib -f

OpenTelemetry Backend

Once the metrics are collected and exported, you can visualize them using a compatible backend system. For example, you can use Uptrace to create dashboards that display metrics from the OpenTelemetry Collector.

Uptrace is a OpenTelemetry backendopen in new window that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.

Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.

In just a few minutes, you can try Uptrace by visiting the cloud demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

Available metrics

Uptrace automatically creates the following dashboard when MySQL metrics are available:

MySQL metrics

What's next?

Next, you can learn more about configuring OpenTelemetry Collector. To start using OpenTelemetry and Uptrace, see Getting started with Uptrace.

Last Updated: