cadvisor+promethues+grafana监控docker容器
一、cadvisor介绍
CAdvisor是谷歌开发的用于分析运行中容器的资源占用和性能指标的开源工具。为容器用户提供了对其运行容器的资源使用和性能特征的理解。 它是一个运行守护程序,用于收集,
聚合,处理和导出有关正在运行的容器的信息。 具体而言,对于每个容器,它保留资源隔离参数,历史资源使用和完整历史资源使用的直方图。 此数据按容器和机器范围导出。
官方地址:
dockerhub: https://hub.docker.com/r/google/cadvisor/
github: https://github.com/google/cadvisor
二、docker宿主机上安装/启动cadvisor
1、准备
1 2 | docker命令监控容器: docker stats containerid |
1.设置权限 mount -o remount,rw '/sys/fs/cgroup' 2.建立软连接 ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu 注:可忽略
2、安装、启动
# 获取最新镜像(可以指定版本:google/cadvisor:v0.24.1)
docker pull google/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 --privileged=true --name=cadvisor --restart=always google/cadvisor:latest # 运行容器简写方式 docker run -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro -v /var/lib/docker/:/var/lib/docker:ro -p 8080:8080 --detach=true --privileged=true --name=cadvisor --restart=always google/cadvisor:latest # 查看容器日志 docker logs -f cadvisor
三、访问cAdvisor的WEB UI
访问地址:http://host:8080 ,下图为cAdvisor的web界面,数据实时刷新但是不能存储。
查看json格式 : http://host:8080/metrics。
四、配置prometheus
1、编辑prometheus.yml文件
vi prometheus.yml
#添加配置信息如下: # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'cadvisor' static_configs: - targets: ['192.168.0.122:8080']
2、重启prometheus,浏览器访问prometheus检查是否配置成功
访问地址:http://host/:9090
五.Grafana添加监控模板
1、配置Prometheus数据源
2、下载模板模板地址:https://grafana.com/dashboards,并导入
3、在grafana-dashboard-import,输入193、8321、10619模板,选择数据来源prometheus
4、查看统计仪表盘
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
2019-10-31 (十二)DVWA全等级SQL Injection(Blind)盲注--SQLMap测试过程解析
2019-10-31 (十一)DVWA全等级SQL Injection(Blind)盲注--手工测试过程解析