NOTE: Not all collection methods are supported on MySQL/MariaDB < 5.6
Building and running
Required Grants
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
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:
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
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)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:
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