容器监控工具很多,本文主要对比了cAdvisor、Weave Scope和Prometheus几种监控工具的特性和功能,并结合环境部署测试了各工具的使用。
容器监控工具很多,下表对比了cAdvisor、Weave Scope和Prometheus等几种监控工具在部署便捷性、信息详细度、集成度、告警功能、非Docker资源监控以及软件成本等方面的特性和功能:
5、Prometheus
Prometheus是强大的容器监控软件,其组件架构和生态如下所示:
图片来源:https://prometheus.io/docs/introduction/overview/
本篇简要介绍如何使用Prometheus和Grafana对本机服务器性能进行监控,关于Prometheus组件介绍和原理不在这里展开。监控本机只需要一个node_exporter用于机器系统数据收集。
1)下载镜像包
[root@tango-centos01 ~]# docker pull prom/node-exporter
[root@tango-centos01 ~]# docker pull prom/Prometheus
[root@tango-centos01 ~]# docker pull grafana/grafana
2)启动node-exporter
[root@tango-centos01 ~]# docker run -d -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter
29aad56cd2eba2b450f95eb03d2cd8286ae52438d9c67ae0295162e0dad6aca3
[root@tango-centos01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
29aad56cd2eb prom/node-exporter "/bin/node_exporter" 5 seconds ago Up 3 seconds 0.0.0.0:9100->9100/tcp charming_bose
访问url:http://192.168.112.101:9100/metrics
这些都是收集到数据,用于数据展示
2)新建目录prometheus,编辑配置文件prometheus.yml
[root@tango-centos01 ~]# mkdir /usr/local/prometheus
[root@tango-centos01 ~]# cd /usr/local/prometheus/
[root@tango-centos01 prometheus]# vi prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['192.168.112.101:9100']
labels:
instance: localhost
注意:修改IP地址,这里的192.168.112.101就是本机地址
3)启动prometheus
[root@tango-centos01 prometheus]# docker run -d -p 9090:9090 -v /usr/local/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
74efbc86fc26c7c3552282c9d89452c7bbfdf20d51131f44f3eae3cae4206a0b
[root@tango-centos01 prometheus]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74efbc86fc26 prom/prometheus "/bin/prometheus --c…" 4 seconds ago Up 3 seconds 0.0.0.0:9090->9090/tcp reverent_gauss
29aad56cd2eb prom/node-exporter "/bin/node_exporter" 13 minutes ago Up 13 minutes 0.0.0.0:9100->9100/tcp charming_bose
访问url:http://192.168.112.101:9090/graph,效果如下:
访问targets,http://192.168.112.101:9090/targets,效果如下:
4)启动grafana
[root@tango-centos01 prometheus]# docker run -itd -p 3000:3000 --name grafana grafana/grafana
a5cc86c7e84c1d4b8be0bac0bda3e771efa3b98faceb560dc472f586be4e3b55
[root@tango-centos01 prometheus]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5cc86c7e84c grafana/grafana "/run.sh" 4 seconds ago Up 2 seconds 0.0.0.0:3000->3000/tcp grafana
74efbc86fc26 prom/prometheus "/bin/prometheus --c…" 5 minutes ago Up 5 minutes 0.0.0.0:9090->9090/tcp reverent_gauss
29aad56cd2eb prom/node-exporter "/bin/node_exporter" 18 minutes ago Up 18 minutes 0.0.0.0:9100->9100/tcp charming_bose
访问url地址http://192.168.112.101:3000/,输入默认的用户名和密码admin登录到首页。
5)配置grafana
添加数据源data source,选择Prometheus:
点击下面的Save & Test,如果出现绿色的,说明ok了
6)编辑配置Dashboard
至此,Prometheus监控容器配置完成
参考资料:
转载请注明原文地址:https://blog.csdn.net/solihawk/article/details/121710998
文章会同步在公众号“牧羊人的方向”更新,感兴趣的可以关注公众号,谢谢!