prometheus监控docker容器(Rocky9)

1. 下载 cAdvisor 二进制

复制代码
cd /usr/local
wget https://github.com/google/cadvisor/releases/download/v0.49.1/cadvisor-v0.49.1-linux-amd64 -O cadvisor
chmod +x cadvisor

2. 后台启动 cAdvisor(教材端口:8080)

复制代码
nohup /usr/local/cadvisor \
--port=8080 \
--docker=/var/run/docker.sock \
>/dev/null 2>&1 &

3. 验证成功

复制代码
curl 127.0.0.1:8080/metrics

出现一大段指标 = 成功

cAdvisor查询界⾯和http接⼝,可访问ip:8080打开web界⾯:

cAdvisor也提供了供prometheus访问的接⼝,可访问ip:8080/metrics,如下图所⽰:


二、部署 node_exporter(二进制,不用 Docker)

复制代码
cd /usr/local
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar zxvf node_exporter-1.5.0.linux-amd64.tar.gz
mv node_exporter-1.5.0.linux-amd64 node_exporter

启动:

复制代码
nohup /usr/local/node_exporter/node_exporter >/dev/null 2>&1 &

验证:

复制代码
curl 127.0.0.1:9100/metrics

部署完成后,node-exporter服务默认监听在9100端⼝。


三、Prometheus 配置

复制代码
scrape_configs:
  - job_name: 'docker_host'
    static_configs:
      - targets: ['192.168.52.130:9100']

  - job_name: 'docker_containers'
    static_configs:
      - targets: ['192.168.52.130:8080']

热重载 Prometheus

复制代码
curl -XPOST http://192.168.52.130:9090/-/reload

http://192.168.52.130:9090/targets


四、Grafana 导入 Docker 面板

ID:10619


你现在只需要按顺序复制这 4 段命令即可

复制代码
cd /usr/local
wget https://github.com/google/cadvisor/releases/download/v0.49.1/cadvisor-v0.49.1-linux-amd64 -O cadvisor
chmod +x cadvisor
nohup /usr/local/cadvisor --port=8080 --docker=/var/run/docker.sock >/dev/null 2>&1 &

cd /usr/local
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar zxvf node_exporter-1.5.0.linux-amd64.tar.gz
mv node_exporter-1.5.0.linux-amd64 node_exporter
nohup /usr/local/node_exporter/node_exporter >/dev/null 2>&1 &

最终效果

  • cAdvisor 正常运行:192.168.52.130:8080/metrics
  • node_exporter 正常运行:192.168.52.130:9100/metrics
  • Prometheus 监控 Docker 容器
  • Grafana 面板正常出图(Docker 容器图:10619 Linux 主机图:8919)

下图是docker状态截图:

node_export获取的数据截图

相关推荐
lichenyang4535 小时前
Docker 学习笔记(五):Docker Compose,用一个 YAML 启动前端、后端和 MongoDB
docker
lichenyang4535 小时前
Docker 学习笔记(四):Dockerfile,把项目打成自己的镜像
docker·容器
lichenyang4535 小时前
Docker 学习笔记(三):Docker 网络、bridge、子网和容器互通
docker·容器
lichenyang4535 小时前
Docker 学习笔记(二):docker run 的参数到底在控制什么?
docker·容器
Patrick_Wilson5 天前
从「改个端口」到 502:Next.js on k8s 的容器端口、Service 映射与 env 覆盖
docker·kubernetes·next.js
SRETalk5 天前
Zabbix、Prometheus、Grafana、Nightingale,四个监控如何选型?
zabbix·grafana·prometheus·nightingale
Suroy5 天前
DockerView-Go:用 Go 写一个终端 Docker 监控工具,顺便做了个 Web 仪表盘
docker
云恒要逆袭5 天前
运行你的第一个Docker容器
后端·docker·容器
宋均浩6 天前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
程序员老赵7 天前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程