RousselTMLEARNING

Observability

Database Observability: tracking MySQL and PostgreSQL queries and plans with Alloy

Alloy's database_observability.mysql and .postgres components: collectors, execution plans, locks, sending to Loki and Mimir, required grants.

1. Beyond server metrics #

What Database Observability sees.

The principle #

A Prometheus exporter says the database is slow; Database Observability says which query, with which execution plan and which locks. The database_observability.mysql and database_observability.postgres components collect these details and send them to Loki; the Grafana Cloud Database Observability app presents them.

From performance_schema to Loki and Mimir

MySQL collectors #

CollectorDefaultRole
query_detailsyes, 1 minNormalized queries (250 max)
query_samplesyes, 10 sSamples of real executions
schema_detailsyes, 1 minTables and columns
explain_plansyes, 1 minExecution plans (EXPLAIN)
locksno, 30 sLock waits over 1 s
table_stats, index_statsnoTable and index statistics
What the exporter measures and what Database Observability adds

2. The configuration #

MySQL to Loki and Mimir.

config.alloy #

local.file "mysql_dsn" {
  filename  = "/etc/alloy/secrets/mysql-dsn"
  is_secret = true
}

prometheus.exporter.mysql "orders" {
  data_source_name = local.file.mysql_dsn.content
}

database_observability.mysql "orders" {
  data_source_name  = local.file.mysql_dsn.content
  forward_to        = [loki.write.default.receiver]
  targets           = prometheus.exporter.mysql.orders.targets
  enable_collectors = ["locks", "table_stats"]
}

prometheus.scrape "orders" {
  targets    = database_observability.mysql.orders.targets
  forward_to = [prometheus.remote_write.mimir.receiver]
}

loki.write "default" {
  endpoint {
    url = "http://loki:3100/loki/api/v1/push"
  }
}

prometheus.remote_write "mimir" {
  endpoint {
    url = "http://mimir:9009/api/v1/push"
  }
}

Configuration validated with alloy validate (Alloy v1.21.3, November 2026).

  • The DSN is a secret: read by local.file with is_secret = true, it does not appear in the Alloy UI or logs.
  • targets: reuses those of prometheus.exporter.mysql to link details and metrics of the same instance.
  • allow_update_performance_schema_settings (false by default): needed for query_samples and setup_actors to adjust performance_schema themselves.

Database side #

Create a dedicated read-only user with access to performance_schema (MySQL) or pg_stat_statements and pg_monitor (PostgreSQL). Exact grants depend on the version: follow Grafana's setup guide for your engine.

Not run here: without a MySQL server in our environment, the configuration was validated, not run.

Sources #

Related articles

Alloy and the Grafana Labs ecosystem: which component for which tool?

The map of Alloy integrations with Faro, Beyla, k6, Loki, Mimir, Tempo, Pyroscope, Database Observability, Fl…

Faro and Alloy: receiving front-end RUM with faro.receiver

Configure faro.receiver: CORS, API key, rate limiting, source maps, then send browser errors, Web Vitals and …

Beyla and Alloy: zero-code RED metrics and traces with beyla.ebpf

Enable Beyla eBPF instrumentation in Alloy: service discovery, RED metrics to Mimir, traces to Tempo, require…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!