prometheus.exporter.mysql
General availability (GA)

prometheus.exporter.mysql

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

Usage

alloy
prometheus.exporter.mysql "<LABEL>" {
    data_source_name = "<DATA_SOURCE_NAME>"
}

Arguments

You can use the following arguments with prometheus.exporter.mysql:

NameTypeDescriptionDefaultRequired
data_source_namesecretData Source Name for the MySQL server to connect to.yes
disable_collectorslist(string)A list of collectors to disable from the default set.no
enable_collectorslist(string)A list of collectors to enable on top of 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_collectorslist(string)A list of collectors to run. Fully overrides the default set.no

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 isn’t supported by Oracle MySQL.

Blocks

You can use the following blocks with prometheus.exporter.mysql:

NameDescriptionRequired
heartbeatConfigures the heartbeat collector.no
info_schema.processlistConfigures the info_schema.processlist collector.no
info_schema.tablesConfigures the info_schema.tables collector.no
mysql.userConfigures the mysql.user collector.no
perf_schema.eventsstatementsConfigures the perf_schema.eventsstatements collector.no
perf_schema.file_instancesConfigures the perf_schema.file_instances collector.no
perf_schema.memory_eventsConfigures the perf_schema.memory_events collector.no

heartbeat

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

info_schema.processlist

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

info_schema.tables

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

mysql.user

NameTypeDescriptionDefaultRequired
privilegesboolEnable collecting user privileges from mysql.user.falseno

perf_schema.eventsstatements

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

perf_schema.file_instances

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

Refer to the MySQL documentation for more detailed information about the tables used in perf_schema_file_instances_filter and perf_schema_file_instances_remove_prefix.

perf_schema.memory_events

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

Supported Collectors

The full list of supported collectors is:

NameDescriptionEnabled by default
global_statusCollect metrics from SHOW GLOBAL STATUS.yes
global_variablesCollect metrics from SHOW GLOBAL VARIABLES.yes
info_schema.innodb_cmpmemCollect metrics from information_schema.innodb_cmpmem.yes
info_schema.innodb_metricsCollect metrics from information_schema.innodb_metrics.yes
info_schema.query_response_timeCollect query response time distribution if query_response_time_stats is ON.yes
slave_statusScrape information from SHOW SLAVE STATUS.yes
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
heartbeatCollect metrics from heartbeat database and tables.no
info_schema.clientstatsIf running with userstat=1, enable to collect client statistics.no
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.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

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 doesn’t expose any component-specific debug information.

Debug metrics

prometheus.exporter.mysql doesn’t expose any component-specific debug metrics.

Example

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

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