一、安装配置
1、安装mysql_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
2、改名并移动到指定目录
mv mysqld_exporter-0.13.0.linux-amd64 /usr/local/prometheus_exporter
cd /usr/local/prometheus_exporter
ln -s mysqld_exporter-0.13.0.linux-amd64/ mysqld_exporter
3、登录mysql为exporter创建账号并授权
# 创建数据库用户
mysql> CREATE USER 'exporter'@'localhost' IDENTIFIED BY '123456';
# 可查看主从运行情况查看线程,及所有数据库。
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
4、创建mysql配置文件、运行时可免密码连接数据库:
vim /usr/local/mysql_exporter/.my.cnf
[client]
user=exporter
password=123456
5、启动exporter客户端
nohup /usr/local/prometheus_exporter/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/prometheus_exporter/mysqld_exporter/.my.cnf &
# 配置自启动
echo "##mysql exporter" >> /etc/rc.local
echo "nohup /usr/local/prometheus_exporter/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/prometheus_exporter/mysqld_exporter/.my.cnf >/dev/null 2>&1 &" >> /etc/rc.local
常用参数:
# 选择采集innodb
--collect.info_schema.innodb_cmp
# innodb存储引擎状态
--collect.engine_innodb_status
# 指定配置文件
--config.my-cnf=".my.cnf"
6、使用prometheus监控修改监控端配置文件:vim prometheus.yml
# 添加作业并命名
- job_name: 'mysql'
# 静态添加node
static_configs:
# 指定监控端
- targets: ['192.168.100.7:9104']
7、重启
systemctl restart prometheus
8、查看监控项
9、grafana导入模板
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容