MakeStack
Back to Feed

MySQL observability with Grafana, Mimir, Loki, Tempo, and Alloy

A Docker Compose observability stack with Grafana, Loki, Mimir, Tempo, Alloy, and a standalone MySQL instance, with MySQL metrics available in Grafana through Mimir.

Service versions and responsibilities
ServiceImageRole
grafanagrafana/grafana:13.1.0web UI and data source provisioning
mysqlmysql:9.7.1standalone database, query logs, and metrics target
lokigrafana/loki:3.7.3log storage
mimirgrafana/mimir:3.1.2metrics storage
alloygrafana/alloy:v1.17.1collector, embedded exporter, and OTLP receiver
tempografana/tempo:3.0.2application trace storage

The main metrics path is MySQL -> Alloy -> Mimir -> Grafana.

This stack runs one authenticated MySQL container with the stackdb database and generated slow and general query logging. Grafana reads MySQL and node metrics from Mimir, so traffic, transactions, InnoDB pressure, query performance, locks, and host resources can be investigated from the same UI as database logs and application traces.

MySQL metrics flow#

Alloy runs one embedded MySQL exporter component, connects it to mysql:3306 with the configured application credentials, enables the binlog-size and performance-schema statement collectors, labels the target as mysql, and remote-writes the samples to Mimir. In the same process, Alloy collects node metrics, forwards MySQL logs to Loki, accepts OTLP telemetry, and sends application traces to Tempo.

Examplepromql
count by(__name__) ({__name__=~"mysql_.+"})

MySQL dashboard coverage#

The MySQL dashboard is organized around operational questions: whether the server is reachable, how much query and transaction traffic it handles, whether connections are saturated, how InnoDB behaves, which statements are expensive, where locks appear, what the slow and general query logs report, and whether the host has enough resources.

Server Health and Availability

Covers server status, uptime, writable role, running threads, restart detection, exporter availability, and MySQL version and build information.

Traffic, Transactions, and Connections

Covers queries and transactions per second, commits and rollbacks, DML command mix, connection saturation and churn, aborted connections, network throughput, temporary tables, and filesorts.

Replication Monitoring

Shows an explicit standalone-topology note. Replica threads, lag, GTID state, relay logs, and replication-error panels are omitted because replication is not configured.

InnoDB and Storage Engine Health

Covers buffer-pool usage and hit ratio, dirty pages, redo activity, log waits, InnoDB row operations, row-lock pressure, table-cache efficiency, and storage-engine warnings.

Query Performance

Covers average and tail statement latency, rows examined versus sent, full table scans and joins, statements without indexes, handler statistics, and top queries by total execution time.

Slow Query Analytics

Covers slow-query rate, slow-query log volume, query time, rows examined, lock time, missing indexes, and live slow-query log entries.

General Query Log Analytics

Covers connection and login spikes, DDL and privilege changes, administrative commands, suspicious activity, and the live general query log.

Connection and Lock Troubleshooting

Covers active sessions, table and row-lock waits, aborted clients and connects, and log-backed deadlock or lock-wait events.

MySQL Log Analytics

Covers all MySQL logs plus error and warning rates, startup, shutdown, recovery, storage problems, and binary-log errors.

System and Container Resource Usage

Covers host CPU, memory, network throughput, disk I/O, filesystem capacity, and file-descriptor usage.

The dashboard uses stat, table, gauge, bar chart, heatmap, logs, and time-series visualizations instead of forcing every metric into one chart type. Its standalone rendering replaces replica-only panels with a clear topology note rather than empty or fabricated replication data.

Logs and traces#

Alloy collects MySQL container output and tails the generated slow and general query log files. It labels the streams with the real service, container, and log_type values before forwarding them to Loki, which lets the dashboard separate lifecycle and error logs from slow and general query activity.

For OTLP traffic, Alloy exposes gRPC on 4317 and HTTP on 4318. OTLP logs are converted for Loki, OTLP metrics are converted to Prometheus remote write for Mimir, and OTLP traces are batched and sent to Tempo. Tempo is reserved for application traces; the MySQL dashboard does not depend on traces.

Alloy telemetry routing
SourceDestination
Docker container logsLoki
MySQL slow and general query logsLoki
OTLP logs on 4317/4318Loki
OTLP metrics on 4317/4318Mimir
OTLP traces on 4317/4318Tempo
Node exporter metricsMimir
MySQL exporter metricsMimir