Menu
Grafana Cloud

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:

  1. To run the MySQL exporter using an environment variable, run the following command.

    export DATA_SOURCE_NAME=‘user:password@(hostname:3306)/’
    ./mysqld_exporter

  2. To run the MySQL exporting using Docker, run the following command.

    docker network create my-mysql-network
    docker pull prom/mysqld-exporter

    docker run -d
    -p 9104:9104
    --network my-mysql-network
    -e DATA_SOURCE_NAME=“user:password@(hostname:3306)/”
    prom/mysqld-exporter

  3. To enable flags on the exporter, refer to mysqld_exporter.

  4. 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

MetricKey Performance Indicator (KPI)

Request

mysql_global_status_connections

mysql_global_status_handlers_total

Request Rate

rate(mysql_global_status_connections[5m])

rate(sum without(handler) (mysql_global_status_handlers_total{handler=~“commit”})[5m])

Error

mysql_global_status_connection_errors_total

Error Ratio

rate(mysql_global_status_connection_errors_total[5m])/ rate(mysql_global_status_connections[5m])

Resource metrics

MetricKey Performance Indicator (KPI)

Connections

mysql_global_status_max_used_connections

Connection Usage

mysql_global_status_max_used_connections / mysql_global_variables_max_connections

Temp Tables Created

mysql_global_status_created_tmp_tables

Temp Tables Usage

avg_over_time(mysql_global_status_created_tmp_tables[5m)

Network Bytes Received

mysql_global_status_bytes_received

Network Bytes Transmitted

mysql_global_status_bytes_sent

Data transfer rate

avg_over_time(mysql_global_status_bytes_received[5m)

avg_over_time(mysql_global_status_bytes_received[5m)

Open Files

mysql_global_status_open_files

Open Files Usage

mysql_global_status_open_files / mysql_global_variables_open_files_limit

Alerts

KPIAlert
Request RateRequestRateAnomaly
Error RatioErrorRatioBreach and ErrorBuildup are based on an availability SLO of 99.9
Connection Usage, Open Files UsageSaturation with severity level of warning and critical when utilization exceeds 80% and 90%, respectively
Temp Tables UsageResourceRateAnomaly
Network BytesResourceRateAnomaly

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.

MySQL dashboard

The following dashboard shows additional metric details.

MySQL details

The following dashboard shows InnoDB metrics.

InnoDB metrics