使用ansible部署 mysql_exporter
ansible-playbook -i host_file service_deploy.yaml -e "tgz=mysqld_exporter-0.12.1.linux-amd64.tar.gz" -e "app=mysqld_exporter"
建立采集使用者,并授權
mysql -uroot -p123123
CREATE USER 'exporter'@'%' IDENTIFIED BY '123123' ;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
FLUSH PRIVILEGES;
方式一:在mysqld_exporter的service 檔案中使用環境變量 DATA_SOURCE_NAME
# 代表localhost
Environment=DATA_SOURCE_NAME=exporter:123123@tcp/
方式二:使用my.cnf啟動服務
Environment=DATA_SOURCE_NAME='exporter:123123@(localhost:3306)/'
重新開機mysqld_exporter服務
systemctl daemon-reload
systemctl restart mysqld_exporter
将mysqld_exporter 采集加入的采集池中
[root@prome-master01 prometheus]# cat prometheus.yml
- job_name: mysqld_exporter
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- 127.0.0.1:9104
grafana 上導入mysqld-dashboard
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5SMyAzY1IWZ2MjNyUzM2cTY2QGZ0kjMlNjN3M2YxkjNw8CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)