Parseable

MySQL

Monitor MySQL metrics and logs with Parseable using OpenTelemetry


Monitor your MySQL databases by collecting metrics and logs using the OpenTelemetry Collector and sending them to Parseable.

Overview

The OpenTelemetry Collector's MySQL receiver collects metrics from MySQL and MariaDB databases including:

  • Server Statistics - Connections, queries, threads
  • InnoDB Metrics - Buffer pool, row operations, locks
  • Query Performance - Statement events, query samples
  • Replication Status - Slave lag and replication metrics

Prerequisites

  • MySQL 8.0+ or MariaDB 10.11+
  • OpenTelemetry Collector with mysql receiver
  • Parseable instance running and accessible

Database User Setup

Create a monitoring user with the required permissions:

-- Create monitoring user
CREATE USER 'otel'@'%' IDENTIFIED BY 'your-secure-password';

-- Grant required permissions
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'otel'@'%';
GRANT SELECT ON performance_schema.* TO 'otel'@'%';

-- Flush privileges
FLUSH PRIVILEGES;

OpenTelemetry Collector Configuration

Basic Configuration

Create an otel-collector-config.yaml file:

receivers:
  mysql:
    endpoint: localhost:3306
    username: otel
    password: ${env:MYSQL_PASSWORD}
    database: mydb
    collection_interval: 10s

exporters:
  otlphttp/parseable:
    endpoint: "http://parseable:8000"
    headers:
      Authorization: "Basic YWRtaW46YWRtaW4="
      X-P-Stream: "mysql-metrics"
      X-P-Log-Source: "otel-metrics"
    tls:
      insecure: true

service:
  pipelines:
    metrics:
      receivers: [mysql]
      exporters: [otlphttp/parseable]

Advanced Configuration with Statement Events

For detailed query performance monitoring:

receivers:
  mysql:
    endpoint: localhost:3306
    username: otel
    password: ${env:MYSQL_PASSWORD}
    database: mydb
    collection_interval: 10s
    initial_delay: 1s
    statement_events:
      digest_text_limit: 120
      time_limit: 24h
      limit: 250
    tls:
      insecure: false
      insecure_skip_verify: false

exporters:
  otlphttp/parseable:
    endpoint: "http://parseable:8000"
    headers:
      Authorization: "Basic YWRtaW46YWRtaW4="
      X-P-Stream: "mysql-metrics"
      X-P-Log-Source: "otel-metrics"
    tls:
      insecure: true

service:
  pipelines:
    metrics:
      receivers: [mysql]
      exporters: [otlphttp/parseable]

Configuration Options

ParameterDefaultDescription
endpointlocalhost:3306MySQL server endpoint
usernamerootDatabase username
password-Database password
database-Database name (empty = all databases)
collection_interval10sMetrics collection interval
allow_native_passwordstrueAllow native password authentication
tls.insecurefalseDisable TLS
statement_events.limit250Max statement events to collect

Collected Metrics

The MySQL receiver collects the following metrics:

MetricDescription
mysql.buffer_pool.pagesBuffer pool page counts
mysql.buffer_pool.data_pagesBuffer pool data pages
mysql.buffer_pool.operationsBuffer pool operations
mysql.commandsCommand execution counts
mysql.handlersHandler operation counts
mysql.locksLock wait counts
mysql.sortsSort operation counts
mysql.threadsThread counts by state
mysql.connectionsConnection counts
mysql.queriesQuery execution counts
mysql.statement_events.countStatement event counts
mysql.statement_events.wait.timeStatement wait times

Running the Collector

Docker

docker run -d \
  --name otel-collector \
  -v $(pwd)/otel-collector-config.yaml:/etc/otelcol/config.yaml \
  -e MYSQL_PASSWORD=your-password \
  otel/opentelemetry-collector-contrib:latest

Docker Compose

version: '3.8'
services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:latest
    volumes:
      - ./otel-collector-config.yaml:/etc/otelcol/config.yaml
    environment:
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    depends_on:
      - mysql
      - parseable

Querying MySQL Metrics in Parseable

Once data is flowing, query your MySQL metrics:

-- Get thread counts over time
SELECT p_timestamp, threads_running, threads_connected 
FROM "mysql-metrics" 
ORDER BY p_timestamp DESC 
LIMIT 100

-- Find slow queries
SELECT digest_text, total_latency, exec_count
FROM "mysql-metrics"
WHERE p_timestamp > NOW() - INTERVAL '1 hour'
ORDER BY total_latency DESC
LIMIT 10

Troubleshooting

Connection Issues

If the collector can't connect to MySQL:

  1. Verify MySQL is accepting connections on the configured port
  2. Check the user has proper permissions
  3. Verify skip-networking is not enabled in MySQL config
  4. Check firewall rules allow the connection

Missing Metrics

If some metrics are not appearing:

  1. Ensure performance_schema is enabled
  2. Verify the monitoring user has SELECT on performance_schema
  3. Check InnoDB is the storage engine for InnoDB-specific metrics

Next Steps

Was this page helpful?

On this page