OpenTelemetry MySQL Monitoring [step by step]

Vladimir Mihailenco
September 15, 2024
2 min read

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 Collector is an agent that pulls telemetry data from systems you want to monitor and export the collected data to an OpenTelemetry backend.

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 receiver in /etc/otel-contrib-collector/config.yaml using Uptrace DSN:

yaml
receivers:
  otlp:
    protocols:
      grpc:
      http:
  mysql:
    endpoint: localhost:3306
    username: otel
    password: $MYSQL_PASSWORD
    database: otel
    collection_interval: 10s
    perf_events_statements:
      digest_text_limit: 120
      time_limit: 24h
      limit: 250

exporters:
  otlp/uptrace:
    endpoint: api.uptrace.dev:4317
    headers: { 'uptrace-dsn': '<FIXME>' }

processors:
  resourcedetection:
    detectors: [env, system]
  cumulativetodelta:
  batch:
    timeout: 10s

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/uptrace]
    metrics:
      receivers: [otlp, mysql]
      processors: [cumulativetodelta, batch, resourcedetection]
      exporters: [otlp/uptrace]

Don't forget to restart OpenTelemetry Collector:

shell
sudo systemctl restart otelcol-contrib

You can also check OpenTelemetry Collector logs for any errors:

shell
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 backend that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

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 demo (no login required) or running it locally with Docker. The source code is available on GitHub.

Available metrics

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

What's next?

Next, you can learn more about configuring OpenTelemetry Collector to export data to a backend.