NOTE: Not all collection methods are supported on MySQL/MariaDB < 5.6
Building and running
Required Grants
The default --mysqld.address=localhost:3306 uses TCP. Because localhost
may resolve to either 127.0.0.1 or ::1, use an explicit address when
creating a host-specific MySQL account. For a local IPv4 connection:
CREATE USER 'exporter'@'127.0.0.1' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'127.0.0.1';
Run the exporter with --mysqld.address=127.0.0.1:3306. For remote or
containerized deployments, replace 127.0.0.1 with the client host or address
that the MySQL server observes.
For a Unix socket connection, such as
--mysqld.address=unix:///run/mysqld/mysqld.sock or a socket= entry in the
configuration file, use a localhost account:
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
NOTE: It is recommended to set a max connection limit for the user to avoid overloading the server with monitoring scrapes under heavy load. This is not supported on all MySQL/MariaDB versions; for example, MariaDB 10.1 (provided with Ubuntu 18.04) does not support this feature.
Build
make build
Running
Single exporter mode
Running using .my.cnf from the current directory:
./mysqld_exporter <flags>
Multi-target support
This exporter supports the multi-target pattern. This allows running a single instance of this exporter for multiple MySQL targets.
To use the multi-target functionality, send an http request to the endpoint /probe?target=foo:3306 where target is set to the DSN of the MySQL instance to scrape metrics from.
To avoid putting sensitive information like username and password in the URL, you can have multiple configurations in config.my-cnf file and match it by adding &auth_module=<section> to the request.
Sample config file for multiple configurations
[client]
user = foo
password = foo123
[client.servers]
user = bar
password = bar123
On the prometheus side you can set a scrape config as follows
- job_name: mysql # To get metrics about the mysql exporter’s targets
metrics_path: /probe
params:
# Not required. Will match value to child in config file. Default value is `client`.
auth_module: [client.servers]
static_configs:
- targets:
# All mysql hostnames or unix sockets to monitor.
- server1:3306
- server2:3306
- unix:///run/mysqld/mysqld.sock
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
# The mysqld_exporter host:port
replacement: localhost:9104
Collect metrics from performance_schema.replication_applier_status_by_worker.
collect.slave_status
5.1
Collect from SHOW SLAVE STATUS (Enabled by default)
collect.slave_hosts
5.1
Collect from SHOW SLAVE HOSTS
collect.sys.user_summary
5.7
Collect metrics from sys.x$user_summary (disabled by default).
General Flags
Name
Description
mysqld.address
Hostname and port used for connecting to MySQL server, format: host:port. (default: localhost:3306)
mysqld.username
Username to be used for connecting to MySQL Server
config.my-cnf
Path to .my.cnf file to read MySQL credentials from. (default: ~/.my.cnf)
log.level
Logging verbosity (default: info)
exporter.lock_wait_timeout
Set a lock_wait_timeout (in seconds) on the connection to avoid long metadata locking. (default: 2)
exporter.enable_lock_wait_timeout
Enable the lock_wait_timeout connection parameter. Makes the exporter compatible with older versions of MySQL. (default: true)
exporter.log_slow_filter
Add a log_slow_filter to avoid slow query logging of scrapes. NOTE: Not supported by Oracle MySQL.
exporter.query_timeout
Per-scraper query timeout (in seconds). 0 disables the timeout. (default: 0, disabled)
exporter.max_open_connections
Maximum number of open connections to the database per scrape. Must be >= 1. The pool is per scrape request, so in multi-target mode total connections scale with concurrent targets; keep the value within the exporter user’s MAX_USER_CONNECTIONS grant. (default: 2)
Address to listen on for web interface and telemetry.
web.telemetry-path
Path under which to expose metrics.
version
Print the version information.
Environment Variables
Name
Description
MYSQLD_EXPORTER_PASSWORD
Password to be used for connecting to MySQL Server
Configuration precedence
If you have configured cli with both mysqld flags and a valid configuration file, the options in the configuration file will override the flags for client section.
TLS and basic authentication
The MySQLd Exporter supports TLS and basic authentication.
To use TLS and/or basic authentication, you need to pass a configuration file
using the --web.config.file parameter. The format of the file is described
in the exporter-toolkit repository.
Customizing Configuration for a SSL Connection
If The MySQL server supports SSL, you may need to specify a CA truststore to verify the server’s chain-of-trust. You may also need to specify a SSL keypair for the client side of the SSL connection. To configure the mysqld exporter to use a custom CA certificate, add the following to the mysql cnf file:
ssl-ca=/path/to/ca/file
To specify the client SSL keypair, add the following to the cnf.
It’s possible to also restrict the TLS versions that can be used between the MySQL server and mysqld exporter by specifying versions in the mysql cnf file like this:
tls-min-version=TLSv1.2
tls-max-version=TLSv1.3
In some environments the MySQL server’s TLS certificate SN or SAN may not include the host that mysqld exporter uses to connect to it. This could happen in cases when the certificate includes only DNS names, while mysqld exporter uses an IP address to connect. To allow secure connections in these cases, tls-server-name can be used to specify the server’s name to use during verification. The parameter works the same as server_name in Prometheus’s scrape config configuration.
With collect.heartbeat enabled, mysqld_exporter will scrape replication delay
measured by heartbeat mechanisms. Pt-heartbeat is the
reference heartbeat implementation supported.
Filtering enabled collectors
The mysqld_exporter will expose all metrics from enabled collectors by default. This is the recommended way to collect metrics to avoid errors when comparing metrics of different families.
For advanced use the mysqld_exporter can be passed an optional list of collectors to filter metrics. The collect[] parameter may be used multiple times. In Prometheus configuration you can use this syntax under the scrape config.
params:
collect[]:
- foo
- bar
This can be useful for having different Prometheus servers collect specific metrics from targets.
Example Rules
There is a set of sample rules, alerts and dashboards available in the mysqld-mixin
MySQL Server Exporter
Prometheus exporter for MySQL server metrics.
Supported versions:
NOTE: Not all collection methods are supported on MySQL/MariaDB < 5.6
Building and running
Required Grants
The default
--mysqld.address=localhost:3306uses TCP. Becauselocalhostmay resolve to either127.0.0.1or::1, use an explicit address when creating a host-specific MySQL account. For a local IPv4 connection:Run the exporter with
--mysqld.address=127.0.0.1:3306. For remote or containerized deployments, replace127.0.0.1with the client host or address that the MySQL server observes.For a Unix socket connection, such as
--mysqld.address=unix:///run/mysqld/mysqld.sockor asocket=entry in the configuration file, use alocalhostaccount:NOTE: It is recommended to set a max connection limit for the user to avoid overloading the server with monitoring scrapes under heavy load. This is not supported on all MySQL/MariaDB versions; for example, MariaDB 10.1 (provided with Ubuntu 18.04) does not support this feature.
Build
Running
Single exporter mode
Running using
.my.cnffrom the current directory:Multi-target support
This exporter supports the multi-target pattern. This allows running a single instance of this exporter for multiple MySQL targets.
To use the multi-target functionality, send an http request to the endpoint
/probe?target=foo:3306where target is set to the DSN of the MySQL instance to scrape metrics from.To avoid putting sensitive information like username and password in the URL, you can have multiple configurations in
config.my-cnffile and match it by adding&auth_module=<section>to the request.Sample config file for multiple configurations
On the prometheus side you can set a scrape config as follows
Flag format
Example format for flags for version > 0.10.0:
Example format for flags for version <= 0.10.0:
Collector Flags
pt-heartbeatis called with--utc). (default: false)*‘ for all.General Flags
host:port. (default:localhost:3306)~/.my.cnf)MAX_USER_CONNECTIONSgrant. (default: 2)Environment Variables
Configuration precedence
If you have configured cli with both
mysqldflags and a valid configuration file, the options in the configuration file will override the flags forclientsection.TLS and basic authentication
The MySQLd Exporter supports TLS and basic authentication.
To use TLS and/or basic authentication, you need to pass a configuration file using the
--web.config.fileparameter. The format of the file is described in the exporter-toolkit repository.Customizing Configuration for a SSL Connection
If The MySQL server supports SSL, you may need to specify a CA truststore to verify the server’s chain-of-trust. You may also need to specify a SSL keypair for the client side of the SSL connection. To configure the mysqld exporter to use a custom CA certificate, add the following to the mysql cnf file:
To specify the client SSL keypair, add the following to the cnf.
It’s possible to also restrict the TLS versions that can be used between the MySQL server and mysqld exporter by specifying versions in the mysql cnf file like this:
In some environments the MySQL server’s TLS certificate SN or SAN may not include the host that mysqld exporter uses to connect to it. This could happen in cases when the certificate includes only DNS names, while mysqld exporter uses an IP address to connect. To allow secure connections in these cases, tls-server-name can be used to specify the server’s name to use during verification. The parameter works the same as server_name in Prometheus’s scrape config configuration.
Using Docker
You can deploy this exporter using the prom/mysqld-exporter Docker image.
For example:
heartbeat
With
collect.heartbeatenabled, mysqld_exporter will scrape replication delay measured by heartbeat mechanisms. Pt-heartbeat is the reference heartbeat implementation supported.Filtering enabled collectors
The
mysqld_exporterwill expose all metrics from enabled collectors by default. This is the recommended way to collect metrics to avoid errors when comparing metrics of different families.For advanced use the
mysqld_exportercan be passed an optional list of collectors to filter metrics. Thecollect[]parameter may be used multiple times. In Prometheus configuration you can use this syntax under the scrape config.This can be useful for having different Prometheus servers collect specific metrics from targets.
Example Rules
There is a set of sample rules, alerts and dashboards available in the mysqld-mixin