一、监控节点
1、node_exporter配置
推荐dashborad序号:9276
用于收集机器信息
[root@node02 node_exporter]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter.service
[Service]
ExecStart=/usr/local/node_exporter/node_exporter \
--web.listen-address=0.0.0.0:9100 \
--collector.systemd \
--collector.systemd.unit-whitelist=(ssh|docker).service \
# 监听service服务,通过正则匹配服务名称
--collector.textfile.directory=/usr/local/node_exporter/textfile.collected
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@localhost node_exporter]# systemctl daemon-reload
[root@localhost node_exporter]# systemctl start node_exporter
[root@localhost node_exporter]# ps -ef |grep node_
root 3401 1 0 22:49 ? 00:00:00 /usr/local/node_exporter/node_exporter --web.listen-address=0.0.0.0:9100 --collector.systemd --collector.systemd.unit-whitelist=(ssh|docker).service --collector.textfile.directory=/usr/local/node_exporter/textfile.collected
2、监控docker容器(cadvisor组件)
官网:https://github.com/google/cadvisor
推荐仪表盘:https://grafana.com/dashborads/193
在监控节点上使用docker运行cadvisor容器进行监控
sudo docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
--privileged \
--device=/dev/kmsg \
gcr.io/cadvisor/cadvisor:latest
修改Prometheus的配置文件,增加监听cadvisor的任务
访问192.168.10.10::9090
导入分享的仪表盘
3、mysql_exporter配置
用于收集mysql信息
官方下载地址:https://prometheus.io/download/
官方帮助文档:https://github.com/prometheus/mysqld_exporter
推荐dashborad:https://grafana.com/dashborads/7362
解压安装包
[root@localhost prometheus]# tar zxvf mysqld_exporter-0.13.0-rc.0.linux-amd64.tar.gz
[root@localhost prometheus]# mv mysqld_exporter-0.13.0-rc.0.linux-amd64 /usr/local/mysqld_exporter
[root@localhost prometheus]# cd /usr/local/mysqld_exporter
进入mysql授权用户
[root@localhost mysqld_exporter]# mysql -u root -p
……省略部分
MariaDB [(none)]> CREATE USER 'exporter'@'localhost' IDENTIFIED BY '123456'; # 创建授权用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
[root@localhost mysqld_exporter]# mkdir .my.cnf # 创建这个配置文件,使得客户端能免密码连接
[client]
user=exporter
password=123456
启动mysqld_exporter
# 指定客户端免密的配置文件启动,默认端口是9140
[root@localhost mysqld_exporter]# ./mysqld_exporter --config.my-cnf=".my.cnf"
level=info ts=2021-05-02T15:41:55.389Z caller=mysqld_exporter.go:274 msg="Starting msqyld_exporter" version="(version=0.13.0-rc.0, branch=HEAD, revision=0dde132736cc88c630edaa692afa5717ac1f7cc2)"
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:275 msg="Build context" (gogo1.16.3,userroot@d074e475b7b5,date20210425-16:58:28)=(MISSING)
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:290 msg="Scraper enabled" scraper=global_status
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:290 msg="Scraper enabled" scraper=global_variables
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:290 msg="Scraper enabled" scraper=slave_status
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:290 msg="Scraper enabled" scraper=info_schema.innodb_cmp
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:290 msg="Scraper enabled" scraper=info_schema.innodb_cmpmem
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:290 msg="Scraper enabled" scraper=info_schema.query_response_time
level=info ts=2021-05-02T15:41:55.390Z caller=mysqld_exporter.go:300 msg="Listening on address" address=:9104
配置systemd管理
[root@localhost mysqld_exporter]# vim /usr/lib/systemd/system/mysqld_exporter.service
[root@prometheus ~]# vi /etc/systemd/system/mysqld_exporter.service
[Unit]
Description= Prometheus MySQL Exporter
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
--config.my-cnf /usr/local/mysqld_exporter/.my.cnf \
--collect.auto_increment.columns \
--collect.binlog_size \
--collect.engine_innodb_status \
--collect.engine_tokudb_status \
--collect.global_status \
--web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
配置prometheus.yml配置文件
# 添加监听mysqld_exporter的任务
[root@localhost promtheus]# vim prometheus.yml
- job_name: 'mysqld'
static_configs:
- targets: ['192.168.10.20:9104']
访问192.168.10.10:9090
导入推荐的7362号grafana dashborad