[toc]
Prometheus简介 prometheus概述 Prometheus是一个开源系统监控和警报工具包,最初是在SoundCloud上构建的
自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发者和用户社区
Prometheus现在是一个独立的开源项目,独立于任何公司进行维护,为了强调这一点,并澄清项目的治理结构
Prometheus于2016年加入云原生计算基金会,作为继Kubernetes之后的第二个托管项目
我们可以简单的理解Prometheus是一个监控系统同时也是一个时间序列数据库
推荐阅读: 官网地址: https://prometheus.io 官方文档: https://prometheus.io/docs/introduction/overview/ GitHub地址: https://github.com/prometheus
prometheus架构
如上图所示,展示了普罗米修斯(prometheus)的建筑和它的一些生态系统组成部分
Prometheus server
prometheus的服务端,负责收集指标和存储时间序列数据,并提供查询接口
exporters
如果想要监控,前提是能获取被监控端数据,并且这个数据格式必须遵循Prometheus数据模型
这样才能识别和采集,一般使用exporter数据采集器(类似于zabbix_agent端)提供监控指标数据
exporter数据采集器,除了官方和GitHub提供的常用组件exporter外,我们也可以为自己自研的产品定制exporters组件
Pushgateway
短期存储指标数据,主要用于临时性的任务。比如备份数据库任务监控等
本质上我们可以理解为Pushgateway可以帮咱们监控自定义的监控项,这需要自己编写脚本来推送到Pushgateway端
而后由Prometheus server从Pushgateway去pull监控数据
咱们完全可以基于Pushgateway来监控咱们自定义的监控项,这些监控项完全可以是长期运行的
Service discovery
服务发现,如我们可以配置动态的服务监控,无需重启Prometheus server实例就能实现动态监控
Alertmanager
Prometheus Web UI
Prometheus比较简单的Web控制台,通常我们可以使用grafana来集成做更漂亮的Web展示
Prometheus部署
环境准备
主机
WanIP
LanIP
角色
应用
k8s01
10.0.0.11
172.16.1.11
k8s master、 Prometheus Server
k8s、docker、prometheus、 node_exporter、alertmanager、 pushgateway
k8s02
10.0.0.12
172.16.1.12
k8s node、客 户端数据收集 器
node_exporter
k8s03
10.0.0.13
172.16.1.13
k8s node、客 户端数据收集 器
node_exporter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 [root@k8s01 ~] https://github.com/prometheus/prometheus/releases/download/v2.45.0-rc.0/prometheus-2.45.0-rc.0.linux-amd64.tar.gz [root@k8s01 ~] [root@k8s01 ~] [root@k8s01 ~] [root@k8s01 ~] [root@k8s01 ~] total 0 lrwxrwxrwx 1 root root 22 Jun 19 09:15 prometheus -> /app/prometheus-2.45.0 drwxr-xr-x 4 1001 docker 132 Jun 7 19:12 prometheus-2.45.0 [root@k8s01 ~] total 227660 drwxr-xr-x 2 1001 docker 38 Jun 7 19:08 console_libraries drwxr-xr-x 2 1001 docker 173 Jun 7 19:08 consoles -rw-r--r-- 1 1001 docker 11357 Jun 7 19:08 LICENSE -rw-r--r-- 1 1001 docker 3773 Jun 7 19:08 NOTICE -rwxr-xr-x 1 1001 docker 120162879 Jun 7 18:40 prometheus // Promethues 启动程序 -rw-r--r-- 1 1001 docker 934 Jun 7 19:08 prometheus.yml // Promethues 配置文件 -rwxr-xr-x 1 1001 docker 112938518 Jun 7 18:42 promtool [root@k8s01 ~] [root@k8s01 ~] tcp6 0 0 :::9090 :::* LISTEN 9469/prometheus [root@k8s01 ~] static_configs: - targets: ["10.0.0.11:9090" ] [root@k8s01 ~]
Prometheus配置文件讲解
部署node_exporter 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [root@k8s01 ~] https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz [root@k8s01 ~] [root@k8s01 ~] [root@k8s01 ~] [root@k8s01 ~] [root@k8s01 node_exporter]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: rule_files: scrape_configs: - job_name: "prometheus" static_configs: - targets: ["10.0.0.11:9090" ] - job_name: "zls_node_exporter" static_configs: - targets: ["10.0.0.11:9100" ,"10.0.0.12:9100" ]
Prometheus动态发现 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: rule_files: scrape_configs: - job_name: "prometheus" static_configs: - targets: ["10.0.0.11:9090" ] - job_name: "zls_node_exporter" static_configs: - targets: ["10.0.0.11:9100" ,"10.0.0.12:9100" ] - job_name: 'dong tai fa xian' file_sd_configs: - files: - /app/prometheus/faxian.yaml refresh_interval: 5s [root@k8s01 prometheus] [ { "targets" : ["10.0.0.13:9100" ,"10.0.0.12:8080" ] } ] docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/zls/data/:/var/lib/docker:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@k8s01 prometheus] [ { "targets" : ["10.0.0.11:9100" ,"10.0.0.12:9100" ,"10.0.0.13:9100" ], "labels" : { "app" : "node_exporter" } }, { "targets" : ["10.0.0.11:8080" ,"10.0.0.12:8080" ,"10.0.0.13:8080" ], "labels" : { "app" : "cAdvisor" } } ]