Menu

Caution

Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.
Open source

prometheus.exporter.mysql

The prometheus.exporter.mysql component embeds mysqld_exporter for collecting stats from a MySQL server.

Usage

river
prometheus.exporter.mysql "LABEL" {
    data_source_name = DATA_SOURCE_NAME
}

Arguments

The following arguments can be used to configure the exporter’s behavior. All arguments are optional. Omitted fields take their default values.

NameTypeDescriptionDefaultRequired
data_source_namesecretData Source Name for the MySQL server to connect to.yes
enable_collectorslist(string)A list of collectors to enable on top of the default set.no
disable_collectorslist(string)A list of collectors to disable from the default set.no
set_collectorslist(string)A list of collectors to run. Fully overrides the default set.no
lock_wait_timeoutintTimeout, in seconds, to acquire a metadata lock.2no
log_slow_filterboolUsed to avoid queries from scrapes being logged in the slow query log.falseno

Set a lock_wait_timeout on the connection to avoid potentially long wait times for metadata locks. View more detailed documentation on lock_wait_timeout in the MySQL documentation.

NOTE: log_slow_filter is not supported by Oracle MySQL.

Blocks

The following blocks are supported inside the definition of prometheus.exporter.mysql to configure collector-specific options:

HierarchyNameDescriptionRequired
info_schema.processlistinfo_schema.processlistConfigures the info_schema.processlist collector.no
info_schema.tablesinfo_schema.tablesConfigures the info_schema.tables collector.no
perf_schema.eventsstatementsperf_schema.eventsstatementsConfigures the perf_schema.eventsstatements collector.no
perf_schema.file_instancesperf_schema.file_instancesConfigures the perf_schema.file_instances collector.no
perf_schema.memory_eventsperf_schema.memory_eventsConfigures the perf_schema.memory_events collector.no
heartbeatheartbeatConfigures the heartbeat collector.no
mysql.usermysql.userConfigures the mysql.user collector.no

info_schema.processlist block

NameTypeDescriptionDefaultRequired
min_timeintMinimum time a thread must be in each state to be counted.0no
processes_by_userboolEnable collecting the number of processes by user.trueno
processes_by_hostboolEnable collecting the number of processes by host.trueno

info_schema.tables block

NameTypeDescriptionDefaultRequired
info_schema_tables_databasesstringRegular expression to match databases to collect table stats for."*"no

perf_schema.eventsstatements block

NameTypeDescriptionDefaultRequired
limitintLimit the number of events statements digests, in descending order by last_seen.250no
time_limitintLimit how old, in seconds, the last_seen events statements can be.86400no
text_limitintMaximum length of the normalized statement text.120no

perf_schema.file_instances block

NameTypeDescriptionDefaultRequired
filterstringRegular expression to select rows in performance_schema.file_summary_by_instance.".*"no
remove_prefixstringPrefix to trim away from file_name."/var/lib/mysql"no

View more detailed documentation on the tables used in perf_schema_file_instances_filter and perf_schema_file_instances_remove_prefix in the MySQL documentation.

perf_schema.memory_events block

NameTypeDescriptionDefaultRequired
remove_prefixstringPrefix to trim away from performance_schema.memory_summary_global_by_event_name."memory/"no

heartbeat block

NameTypeDescriptionDefaultRequired
databasestringDatabase to collect heartbeat data from."heartbeat"no
tablestringTable to collect heartbeat data from."heartbeat"no
utcboolUse UTC for timestamps of the current server (pt-heartbeat is called with --utc).falseno

mysql.user block

NameTypeDescriptionDefaultRequired
privilegesboolEnable collecting user privileges from mysql.user.falseno

Supported Collectors

The full list of supported collectors is:

NameDescriptionEnabled by default
auto_increment.columnsCollect auto_increment columns and max values from information_schema.no
binlog_sizeCollect the current size of all registered binlog files.no
engine_innodb_statusCollect metrics from SHOW ENGINE INNODB STATUS.no
engine_tokudb_statusCollect metrics from SHOW ENGINE TOKUDB STATUS.no
global_statusCollect metrics from SHOW GLOBAL STATUS.yes
global_variablesCollect metrics from SHOW GLOBAL VARIABLES.yes
heartbeatCollect metrics from heartbeat database and tables.no
info_schema.clientstatsIf running with userstat=1, enable to collect client statistics.no
info_schema.innodb_cmpmemCollect metrics from information_schema.innodb_cmpmem.yes
info_schema.innodb_metricsCollect metrics from information_schema.innodb_metrics.yes
info_schema.innodb_tablespacesCollect metrics from information_schema.innodb_sys_tablespaces.no
info_schema.processlistCollect current thread state counts from the information_schema.processlist.no
info_schema.query_response_timeCollect query response time distribution if query_response_time_stats is ON.yes
info_schema.replica_hostCollect metrics from information_schema.replica_host_status.no
info_schema.schemastatsIf running with userstat=1, enable to collect schema statistics.no
info_schema.tablesCollect metrics from information_schema.tables.no
info_schema.tablestatsIf running with userstat=1, enable to collect table statistics.no
info_schema.userstatsIf running with userstat=1, enable to collect user statistics.no
mysql.userCollect data from mysql.user.no
perf_schema.eventsstatementsCollect metrics from performance_schema.events_statements_summary_by_digest.no
perf_schema.eventsstatementssumCollect metrics of grand sums from performance_schema.events_statements_summary_by_digest.no
perf_schema.eventswaitsCollect metrics from performance_schema.events_waits_summary_global_by_event_name.no
perf_schema.file_eventsCollect metrics from performance_schema.file_summary_by_event_name.no
perf_schema.file_instancesCollect metrics from performance_schema.file_summary_by_instance.no
perf_schema.indexiowaitsCollect metrics from performance_schema.table_io_waits_summary_by_index_usage.no
perf_schema.memory_eventsCollect metrics from performance_schema.memory_summary_global_by_event_name.no
perf_schema.replication_applier_status_by_workerCollect metrics from performance_schema.replication_applier_status_by_worker.no
perf_schema.replication_group_member_statsCollect metrics from performance_schema.replication_group_member_stats.no
perf_schema.replication_group_membersCollect metrics from performance_schema.replication_group_members.no
perf_schema.tableiowaitsCollect metrics from performance_schema.table_io_waits_summary_by_table.no
perf_schema.tablelocksCollect metrics from performance_schema.table_lock_waits_summary_by_table.no
slave_hostsScrape information from SHOW SLAVE HOSTS.no
slave_statusScrape information from SHOW SLAVE STATUS.yes

Exported fields

The following fields are exported and can be referenced by other components.

NameTypeDescription
targetslist(map(string))The targets that can be used to collect exporter metrics.

For example, the targets can either be passed to a discovery.relabel component to rewrite the targets’ label sets or to a prometheus.scrape component that collects the exposed metrics.

The exported targets use the configured in-memory traffic address specified by the run command.

Component health

prometheus.exporter.mysql is only reported as unhealthy if given an invalid configuration. In those cases, exported fields retain their last healthy values.

Debug information

prometheus.exporter.mysql does not expose any component-specific debug information.

Debug metrics

prometheus.exporter.mysql does not expose any component-specific debug metrics.

Example

This example uses a prometheus.scrape component to collect metrics from prometheus.exporter.mysql:

river
prometheus.exporter.mysql "example" {
  data_source_name  = "root@(server-a:3306)/"
  enable_collectors = ["heartbeat", "mysql.user"]
}

// Configure a prometheus.scrape component to collect mysql metrics.
prometheus.scrape "demo" {
  targets    = prometheus.exporter.mysql.example.targets
  forward_to = [prometheus.remote_write.demo.receiver]
}

prometheus.remote_write "demo" {
  endpoint {
    url = PROMETHEUS_REMOTE_WRITE_URL

    basic_auth {
      username = USERNAME
      password = PASSWORD
    }
  }
}

Replace the following:

  • PROMETHEUS_REMOTE_WRITE_URL: The URL of the Prometheus remote_write-compatible server to send metrics to.
  • USERNAME: The username to use for authentication to the remote_write API.
  • PASSWORD: The password to use for authentication to the remote_write API.

Compatible components

prometheus.exporter.mysql has exports that can be consumed by the following components:

Note

Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.