4、监控 MySQL
官网下载地址:
https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
1、安装 MySQL_exporter 插件
# MySQL 数据库创建用户并授权 注意如果不在一台 权限请给 % ,
create user 'exporter'@'localhost' identified by 'exporter';
grant process, replication client, select on *.* to 'exporter'@'localhost';
flush privileges;
# 下载 mysql_exporter 工具包
tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
cd mysqld_exporter-0.12.1.linux-amd64/
vim .my.cnf
[client]
user=exporter
password=exporter
# 配置system 启动文件
vim /etc/systemd/system/prometheus-mysql.service
[Unit]
Description=Prometheus Mysql
After=network.target prometheus.service
[Service]
Type=simple
ExecStart=/montion/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter --config.my-cnf=/montion/mysqld_exporter-0.12.1.linux-amd64/.my.cnf --web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
# 将 mysqld_exporter 服务设为开机自启并启动
systemctl daemon-reload
systemctl enable prometheus-mysql.service
systemctl start prometheus-mysql.service
# 查看 mysqld_exporter 服务 (默认端口为: 9104)
2、 Prometheus 中集成 mysqld_exporter
修改 Prometheus 的配置文件 (prometheus.yml),添加 mysql 服务 (在 scrape_configs 属性下添加)
# 修改配置文件
vim prometheus.yml
- job_name: 'mysql'
static_configs:
- targets: ['x.x.x.x:9104']
# 重启 prometheus 服务
systemctl restart prometheus.service
3、cosoul 注册中心
[root@mysy_193_51 mysqld_exporter-0.11.0.linux-amd64]# cat mysql.json
{
"ID": "mysql-instance-x.x.x.x",
"Name": "mysql-instance-x.x.x.x",
"Tags": [
"mysql_instance"
],
"Address": "x.x.x.x",
"Port": 9104,
"Meta": {
"instance": "mysql-instance-x.x.x.x",
"role": "mysql"
},
"EnableTagOverride": false,
"Check": {
"HTTP": "http://x.x.x.x:9104/metrics",
"Interval": "10s"
},
"Weights": {
"Passing": 10,
"Warning": 1
}
}
curl -X PUT --data @mysql.json http://x.x.x.x:8500/v1/agent/service/register
4、删除注册中心
curl --request PUT http://x.x.x.x:8500/v1/agent/service/deregister/node-instance-10.105.193.41
node-instance-x.x.x.x CheckID
3、配置 grafana 仪表盘
下载地址:
https://github.com/percona/grafana-dashboards/blob/master/dashboards/
直接导入
插件安装
grafana-cli plugins install blackmirror1-singlestat-math-panel