prometheus监控系统搭建
prometheus监控系统搭建
其他参考https://blog.csdn.net/weixin_43815140/article/details/119730821
服务端安装
>服务端使用docker部署prometheus、grafana
准备文件
mkdir -p /data/docker/prometheus/server/
chmod -R 755 /data/docker/prometheus/server/
mkdir -p /data/docker/prometheus/grafana/
vi /data/docker/prometheus/server/prometheus.yml
global:
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: 'node_exporter-199'
scrape_interval: 10s
static_configs:
- targets: ['192.168.2.199:9100'] #主机 192.168.2.199:9100
创建prometheus容器
docker run --name prometheus -p 9090:9090 --restart=always \
-v /data/docker/prometheus/server/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /data/docker/prometheus/server/rules.yml:/etc/prometheus/rules.yml \
-itd prom/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--web.enable-lifecycle
创建grafana容器获取到grafana.ini后删除容器
docker run --name=grafana -p 3000:3000 -itd grafana/grafana
docker cp grafana:/etc/grafana/grafana.ini /data/docker/prometheus/grafana/
docker rm -f grafana
chmod 777 /data/docker/prometheus/*
创建正式的grafana容器
docker run -p 3000:3000 --name grafana --restart=always \
-v /data/docker/prometheus/grafana/grafana.ini:/etc/grafana/grafana.ini \
-v /data/docker/prometheus/grafana/data:/var/lib/grafana \
-itd grafana/grafana
测试
浏览器访问:http://192.168.2.199:9090
被监控端安装
https://prometheus.io/docs/instrumenting/exporters/
根据需要选择监控主机资源、mysql、redis等对应的exporter。
此处以centos7系统监控为例
安装node_exporter监控主机
centos7:
https://github.com/prometheus/node_exporter
curl -Lo /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo
yum install node_exporter -y
systemctl start node_exporter && systemctl enable node_exporter
模板推荐 16098
其他主机介绍:
win主机监控 https://github.com/prometheus-community/windows_exporter/releases
#win主机模板 https://grafana.com/grafana/dashboards/10467
安装cadvisor监控主机上的docker容器
docker run -v /:/rootfs:ro -v /var/run:/var/run/:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -p 18001:8080 --detach=true --name=cadvisor google/cadvisor
模板id 1566 893 10619 11600 395 193
安装mysqld_exporter监控主机上的mysql
下载地址
https://github.com/prometheus/mysqld_exporter/releases
mysql创建账号并授权
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'xxx'; #mysql5.6不能用WITH MAX_USER_CONNECTIONS 3,后面手动限制下连接数
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
创建配置/mysqld_exporter.my.cnf
[client]
user=exporter
password=xxx
host=localhost
port=3306
运行:
./mysqld_exporter --config.my-cnf=/mysqld_exporter.my.cnf
模板id :
配置
grafanas设置数据源为prometheus ,docekr部署的注意下图ip
prometheuss设置exporters
vim /data/docker/prometheus/server/prometheus.yml
添加如下:
- job_name: 'node_exporter-1'
scrape_interval: 10s
static_configs:
- targets: ['192.168.2.xx:9100']
重启prometheuss容器
docker restart prometheuss
grafanas导入模板
下图输入位置,输入8919,8919是别人做的中文的主机监控模板,
https://starsl.cn/article/8919.html
推荐使用id为16098的模板,效果直观,对应效果图如下