About mysqld_exporter

mysqld_exporter is used to expose MySQL instance status to Prometheus. dbbot has provided default deployment variables and systemd templates.

Default values

The default variables are located in mysql_ansible/playbooks/default/var_mysqld_exporter_install.yml:

  • mysqld_exporter_install: true
  • mysqld_exporter_install_type: dbbot
  • mysqld_exporter_topology: auto
  • mysqld_exporter_port: auto

Description:

  • By default, the mysqld_exporter binary built into the dbbot repository is used.
  • mysqld_exporter_topology: auto resolves automatically to ms or mgr.
  • mysqld_exporter_port: auto will automatically derive the exporter listening port according to 9104 + (mysql_port - 3306).

Dependency chain

ItemDetails
PrerequisitesThe MySQL instance is already deployed, mysql_admin_user / mysql_admin_password can log in locally, and for package mode the control node either has internet access or the offline package is already prepared
Required variablesmysqld_exporter_install_type, mysqld_exporter_topology, and mysqld_exporter_port; if the monitor account should be created automatically, keep fcs_role_mysqld_exporter_create_monitor_user: true
Next stepRegister the exporter with dbbotctl exporter register -t mysql; if host metrics are also needed, run node_exporter_install.yml; if Router metrics are also needed, continue with router_exporter_install.yml

Common scenarios

Primary-replica or single instance:

mysqld_exporter_install: true
mysqld_exporter_install_type: dbbot
mysqld_exporter_topology: auto
mysqld_exporter_port: auto

MGR:

mysqld_exporter_install: true
mysqld_exporter_install_type: dbbot
mysqld_exporter_topology: mgr
mysqld_exporter_port: auto

Multi-instance port planning

Default automatic derivation rules:

  • 3306 -> 9104
  • 3307 -> 9105
  • 3310 -> 9108

If you prefer to fix it to a custom port, you can also specify it explicitly:

mysqld_exporter_port: 9201

package mode

If you want to use the official release package, you can switch to package mode:

mysqld_exporter_install_type: package
mysqld_exporter_package: mysqld_exporter-0.18.0.linux-amd64.tar.gz

Official download example:

wget "https://github.com/prometheus/mysqld_exporter/releases/download/v0.18.0/mysqld_exporter-0.18.0.linux-amd64.tar.gz"

At this time any of the following conditions need to be met:

  • Keep fcs_auto_download_packages: true so the control node can auto-download it
  • Or place the package into mysql_ansible/downloads/ in advance and set fcs_auto_download_packages: false

Used in conjunction with exporterregistrar

dbbotctl exporter register reuses exporterregistrar underneath and will also derive the MySQL exporter port from --db-port when -P is not explicitly specified.

Example:

dbbotctl exporter register -t mysql -H 192.0.2.131 --db-port 3310 -s 192.0.2.161 -p ${prometheus_server_root_password}

Execution entry

cd /usr/local/dbbot/mysql_ansible/playbooks
ansible-playbook mysqld_exporter_install.yml

Compatibility note:

  • The old exporter_install.yml entry still exists, but it is now only a compatibility alias for mysqld_exporter_install.yml and no longer installs node_exporter implicitly.