您的位置:首页 > 运维架构

Prometheus监控系统的容器安装方式

2020-07-12 17:08 706 查看

简述

Node Exporter,负责收集 host 硬件和操作系统数据。它将以容器方式运行在所有 host 上。
cAdvisor,负责收集容器数据。它将以容器方式运行在所有 host 上。步骤如下:

安装node-exporters:

docker run -d -p 9100:9100
-v “/proc:/host/proc”
-v “/sys:/host/sys”
-v “/:/rootfs”
–privileged=true
–name=node-exporter
–net=host
prom/node-exporter
–path.procfs /host/proc
–path.sysfs /host/sys
–collector.filesystem.ignored-mount-points “^/(sys|proc|dev|host|etc)($|/)”

安装运行cAdvisor

docker run
–volume=/:/rootfs:ro
–volume=/var/run:/var/run:rw
–volume=/sys:/sys:ro
–volume=/var/lib/docker/:/var/lib/docker:ro
–publish=8080:8080
–detach=true
–name=cadvisor
–net=host
google/cadvisor:latest

安装Prometheus server:

docker run -d -p 9090:9090
-v /home/sw/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
–name prometheus
–net=host
prom/prometheus

注意:
①增加promtheus拉取数据的项目,需在挂载的配置文件prometheus.yml中增加对应的Endpoint设置并重启服务
②/home/sw/prometheus/prometheus.yml需要在之前写好,或者可以不使用-v选项,等prometheus容器运行之后,通过docker cp命令把prometheus.yml从容器中拷贝出来。配置文件重点修改的是scrape_configs部分,该部分可以加入不同的job,每个job底下可以有不同的获取数据的端口(-targets中的这个端口通常就是写exporter提供数据的端口)。此外,scrape_interval和evaluation_interval可以修改收集数据和评估规则(规则似乎与alert有关)的间隔。


由于cAdvisor通过 8080提供host的监控数据,node exporter通过9100端口提供数据,Prometheus server通过9090端口提供自己的数据,因此上述写法如此。另外,这里只收集localhost的数据,教程中还可以通过“-target:[ip:port]”的方式监控其他主机的信息,这就需要在其他主机中部署exporter,然后传到localhost:9090端口了,因此(我认为)其他主机必须和装有prometheus的主机是ip可达的。

运行grafana

docker run -d -i -p 3000:3000
-e “GF_SERVER_ROOT_URL=http://grafana.server.name”
-e “GF_SECURITY_ADMIN_PASSWORD=secret”
–net=host
grafana/grafana

接着输入在浏览器打开:
http://localhost:9090: prometheus的监控数据
http://localhost:3000: grafana
关于grafana的配置,这里不再详述,直接按原参考链接即可:
https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587965&idx=1&sn=8bce9449e4d00972fef77f7fafcda0f4&chksm=8d3081e4ba4708f270aea6bb7c8b60bc1480d5775668916ebe6beb69916411d7fe24b53812e3&scene=21#wechat_redirect

特别注意!!!!:
Node-exporter 0.16.0及更高版本重命名了许多指标,以符合Prometheus命名最佳实践的要求,但由于有的dashboard的根据旧版node-exporter确定的,因此参数需要手动修改(或根据官方的转换方式进行转换),也可以选择支持新版本Node-exporter的dashboard。
https://github.com/prometheus/node_exporter/blob/master/docs/V0_16_UPGRADE_GUIDE.md

grafana,可以为每个panel配置alert rule,具体以后再研究,以下为grafana的界面:
Docker监控

宿主机监控:

汇总cpu使用率写法:

  1. https://blog.csdn.net/yjph83/article/details/84909319
    avg without (cpu) (irate(node_cpu{instance=“88node”, mode!=“idle”}[5m]))
  2. https://www.cnblogs.com/qianyuliang/p/10479626.html
    sum( sum by (mode) (irate(node_cpu_seconds_total{mode !=‘idle’}[5m])) * 100) 根据自己理解写的
  3. https://www.cnblogs.com/zhenglisai/p/9207462.html
    sum(rate(node_cpu_seconds_total{mode!=“idle”}[1m])) by (instance_name)
  4. https://www.bilibili.com/video/av61747618?p=16
    视频9:04,使用率为
    (1-((sum(increase(node_cpu{mode=“idle”}[1m]))by(instance))/(sum(increase(node_cpu[1m]))by(instance))))*100

参考:
https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587965&idx=1&sn=8bce9449e4d00972fef77f7fafcda0f4&chksm=8d3081e4ba4708f270aea6bb7c8b60bc1480d5775668916ebe6beb69916411d7fe24b53812e3&scene=21#wechat_redirect

关于prometheus的exporter: https://prometheus.io/docs/instrumenting/exporters/
grafana的dashboard: https://grafana.com/dashboards

还有几篇:
https://www.cnblogs.com/suim1218/p/11358678.html
https://www.jianshu.com/p/413fd42ae660 比较有参考价值
https://www.cnblogs.com/tchua/p/11115146.html
3.18.2020:
https://blog.csdn.net/zeroctu/article/details/81184109 基于Prometheus&Grafana的监控方案[3]-监控样例(一些query使用方法)
https://www.cnblogs.com/Leslieblog/p/11157958.html Prometheus监控node-exporter常用指标含义
https://prometheus.io/docs/prometheus/latest/querying/basics/ 官方query
https://github.com/prometheus/node_exporter/blob/master/docs/V0_16_UPGRADE_GUIDE.md note-exporter的变化

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: