Monitoring MySQL Performance using OpenTelemetry

This tutorial explains how you can use OpenTelemetry and Uptrace to monitor MySQL performance. Besides using Otel Collector to monitor your MySQL servers, you can also use OpenTelemetry to instrument your applications with traces, metrics, and logs.

What is OpenTelemetry?

OpenTelemetry defines APIs and protocols for collecting telemetry data such as metrics, traces, and logs, and provides a variety of libraries, agents, and integrations for popular programming languages and technologies.

OpenTelemetry is an open and vendor-neutral solution that provides a unified approach to observability, making it easier for organizations to manage the complexity of their cloud-native infrastructure. This allows organizations to collect and transmit telemetry data from their applications to a variety of distributed tracing toolsopen in new window.

What is OpenTelemetry Collector?

OpenTelemetry Collectoropen in new window is an agent that pulls telemetry data from systems you want to monitor and sends it to tracing toolsopen in new window using the OpenTelemetry protocol (OTLP).

You can use OpenTelemetry Collector to monitor system metricsopen in new window, PostgreSQLopen in new window, MySQLopen in new window, Redisopen in new window, and more.

Uptrace

Uptrace is a source-available APMopen in new window powered by OpenTelemetry and ClickHouse. It allows you to identify and fix bugs in production faster knowing what conditions lead to which errors.

You can get startedopen in new window with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.

OpenTelemetry MySQL receiver

To start monitoring MySQL with Otel Collector, you need to configure MySQL receiver in /etc/otel-contrib-collector/config.yaml using Uptrace DSNopen in new window:

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:
    endpoint: otlp.uptrace.dev:4317
    headers: { 'uptrace-dsn': '<FIXME>' }

processors:
  resourcedetection:
    detectors: [system]
  batch:
    timeout: 10s

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

Don't forget to restart the service:

sudo systemctl restart otelcol-contrib

You can also check OpenTelemetry Collector logs for any errors:

sudo journalctl -u otelcol-contrib -f

Available metrics

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

MySQL metrics

Prometheus

You can also send OpenTelemetry metrics to Prometheus using OpenTelemetry Prometheus exporter.

What's next?

Next, you can learn more about configuring OpenTelemetry Collector and check available receivers.

To start using OpenTelemetry and Uptrace, see Getting started with Uptraceopen in new window.

Last Updated: