使用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