Configure the MySQL exporter to generate Prometheus metrics
To enable the Prometheus metric for MySQL, use the mysqld_exporter. You can either run MySQL exporter using an environment variable or using the docker.
To configure MySQL exporter to generate Prometheus metrics, perform the following steps:
To run the MySQL exporter using an environment variable, run the following command.
export DATA_SOURCE_NAME=‘user:password@(hostname:3306)/’
./mysqld_exporterTo run the MySQL exporting using Docker, run the following command.
docker network create my-mysql-network
docker pull prom/mysqld-exporterdocker run -d
-p 9104:9104
--network my-mysql-network
-e DATA_SOURCE_NAME=“user:password@(hostname:3306)/”
prom/mysqld-exporterTo enable flags on the exporter, refer to mysqld_exporter.
To confirm that the exporter is attached to the MySQL server, ensure the following metrics are available in Prometheus.
mysql_version_info
mysql_global_status_connections
Request and error metrics
Metric | Key Performance Indicator (KPI) |
---|---|
Request
| Request Rate
|
Error
| Error Ratio
|
Resource metrics
Metric | Key Performance Indicator (KPI) |
---|---|
Connections
| Connection Usage
|
Temp Tables Created
| Temp Tables Usage
|
Network Bytes Received
Network Bytes Transmitted
| Data transfer rate
|
Open Files
| Open Files Usage
|
Alerts
KPI | Alert |
---|---|
Request Rate | RequestRateAnomaly |
Error Ratio | ErrorRatioBreach and ErrorBuildup are based on an availability SLO of 99.9 |
Connection Usage, Open Files Usage | Saturation with severity level of warning and critical when utilization exceeds 80% and 90%, respectively |
Temp Tables Usage | ResourceRateAnomaly |
Network Bytes | ResourceRateAnomaly |
Failure alerts
MySQLDown: MySQL is not running
mysql_up != 1
MySqlRestarted: MySQL server restarted
mysql_global_status_uptime < 60
MySqlSlowQueries: MySQL queries are running slow
rate(mysql_global_status_sloq_queries[1m]) * 60 > 0
MysqlSlaveSqlThreadNotRunning: MySQL slave is not running even though it is enabled
mysql_slave_status_master_server_id > 0 and on (instance, asserts_env, asserts_site) mysql_slave_status_slave_sql_running == 0
Dashboards
The following MySQL dashboard shows summary level metrics.
The following dashboard shows additional metric details.
The following dashboard shows InnoDB metrics.