1. Download the metric indicator collection plug-in of mysqld
Official website address
https://github.com/prometheus/mysqld_exporter/releases/
mysqld_ Exporter acquisition and decompression
# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
# tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz
2. Create an account for Prometheus to collect data in MySQL
mysql> create user ‘promethues’@’localhost’ IDENTIFIED BY ‘promethues1’;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select,replication client,process on *.* to ‘promethues’@’localhost’;
Query OK, 0 rows affected (0.00 sec)
※ localhost here does not refer to the IP address of mysqld service, but refers to mysqld_ The IP address of the exporter, because when the promethues service comes to mysqld to obtain data, it first finds mysqld_ Exporter, then mysqld_ The exporter goes to mysqld to get the data. So make sure mysqld_ The IP address of the exporter can connect to mysqld service.
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3. In mysqld_ Configure MySQL information in the exporter component
# cp -p mysqld_exporter/.my.cnf mysqld_exporter/.my.cnf.org
# vi mysqld_exporter/.my.cnf
[client]
user=promethues
password=promethues1
4. Start mysqld_ Exporter component, configure promethues YML, and specify the MySQL account information file
# ./mysqld_exporter –help
# nohup ./mysqld_exporter –web.listen-address=”:9104″ –config.my-cnf=”.my.cnf” &> /dev/null &
##Add the following configuration: VIM Prometheus yml
– job_name: ‘mysqld’
static_configs:
– targets: [‘localhost:9104’]
5. Add mysqld template in grafana
Grafana finds MySQL related templates and imports them by referring to and signing Josn files to generate dashboards
