Prometheus Metrics
To monitor MariaDB with Prometheus, you can use mariadb_exporter — a lightweight, modular Prometheus exporter written in Rust with low memory overhead and mariadb_-prefixed metrics.
Create a dedicated monitoring user#
Create a least-privilege user for the exporter. When running on the same host, connecting over the local Unix socket is recommended to avoid sending credentials over the network:
CREATE USER 'exporter'@'localhost' IDENTIFIED VIA unix_socket;
GRANT PROCESS, REPLICATION CLIENT, SLAVE MONITOR ON *.* TO 'exporter'@'localhost';
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
FLUSH PRIVILEGES;
If connecting over TCP instead of a Unix socket, create
'exporter'@'127.0.0.1'(or your monitoring host) with a strong password andWITH MAX_USER_CONNECTIONS 3.
Install & Run#
Install via Cargo (or use the pre-built release binaries / container images from nbari/mariadb_exporter):
cargo install mariadb_exporter
Run using a local Unix socket (recommended):
mariadb_exporter \
--dsn "mysql:///mysql?socket=/var/run/mysqld/mysqld.sock&user=exporter"
Or over TCP:
mariadb_exporter \
--dsn "mysql://exporter:password@tcp(127.0.0.1:3306)/mysql"
By default, mariadb_exporter listens on port 9306 (override with --port).
Modular collectors#
Core availability, InnoDB, and replication metrics are enabled by default while heavier collectors remain off until requested. Enable only what you need to keep scrape latency and cardinality low, for example:
mariadb_exporter \
--dsn "mysql:///mysql?socket=/var/run/mysqld/mysqld.sock&user=exporter" \
--collector.innodb \
--collector.replication \
--collector.locks \
--collector.statements
Run mariadb_exporter --help to see all available collector flags and options.
Prometheus scrape configuration#
Add the target to your prometheus.yml:
scrape_configs:
- job_name: mariadb
static_configs:
- targets:
- db01.example.com:9306Verify metrics#
Confirm the exporter is serving metrics on /metrics:
curl -s http://127.0.0.1:9306/metrics | grep '^mariadb_up'
Even if MariaDB is unreachable,
/metricssafely returnsHTTP 200withmariadb_up 0so Prometheus can alert cleanly without reporting stale metrics.