监控MySQL数据库
想通过grafana简单监控一下MySQL数据库的情况.
作为笔记处理.
创建用户
建议给数据库创建一个监控用户:
CREATE USER 'mysqlexporter'@'localhost' IDENTIFIED BY 'Testxxxxxxxx' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqlexporter'@'localhost';
创建配置文件
创建一个配置文件, 便于进行处理.
cat >/etc/mysql/mysql.conf <<EOF
[client]
user=mysqlexporter
password=Testxxxxxxxx
host=10.xxx.xx.116
port=3306
EOF
启动服务
将 mysqld部署为服务:
cat > /etc/systemd/system/mysqldexporter.service <<EOF
[Unit]
Description=mysqld
[Service]
Type=simple
ExecStart=/usr/bin/mysqld_exporter --config.my-cnf="/etc/mysql/mysql.conf"
Restart=always
LimitNOFILE=64000
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now mysqldexporter
systemctl daemon-reload && systemctl restart mysqldexporter
systemctl status mysqldexporter
Prometheus
prometheus进行获取监控指标
- job_name: 'mysqld-exporter'
static_configs:
- targets: ['localhost:9104']
labels:
nodename: 'mysql116'
导入面板
https://github.com/prometheus/mysqld_exporter/blob/main/mysqld-mixin/dashboards/mysql-overview.json
导入这个即可.
下一步 处理一下与Oracle 一样的 单独监控指标获取与展示