官方参考文档:
Monitoring Docker container metrics using cAdvisor | Prometheus
一、创建项目目录,编辑Prometheus.yml主配置文件,添加监控的容器cAdvisor为目标容器
[root@localhost ~]# mkdir prom
[root@localhost ~]# cd prom
[root@localhost ~]# vi prometheus.yml
[root@localhost prom]# cat prometheus.yml |egrep -v "^([ ]*#)|^$" #过滤掉注释和空行
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.
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# 加入以下内容:
- job_name: cadvisor
scrape_interval: 5s
static_configs:
- targets:
- cadvisor:8080
将prometheus.yml拷贝到/etc/prometheus/目录下
[root@localhost ~]# mkdir /etc/prometheus
[root@localhost ~]# cp prometheus.yml /etc/prometheus
二、编写docker-compose文件启动prom、cAdvisor、redis容器
[root@localhost prom]# vi docker-compose.yml
version: '3.2'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- 9090:9090
command:
- --config.file=/etc/prometheus/prometheus.yml # 本机存放的配置文件路径,但感觉读的还是当前目录的文件,
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro # 只读挂载
depends_on:
- cadvisor # 依赖容器,要先启动cadvisor容器
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest # gcr.io为谷歌云,国内访问不了,需提前准备
container_name: cadvisor
ports:
- 8080:8080
volumes: # 挂载——获取其他容器信息的原因
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
depends_on:
- redis
redis:
image: redis:latest
container_name: redis
ports:
- 6379:6379
加载本地acdvisor软件包到本地
[root@localhost prom]# ls
cadvisor.tar docker-compose.yml prometheus.yml
[root@localhost prom]# docker load -i cadvisor.tar # 加载镜像
ace0eda3e3be: Loading layer 5.843MB/5.843MB
33bb68b99ee4: Loading layer 102.4MB/102.4MB
d3174d703c76: Loading layer 13.25MB/13.25MB
8b7599e512b6: Loading layer 44.19MB/44.19MB
Loaded image: gcr.io/cadvisor/cadvisor:latest
[root@localhost prom]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis alpine 0b405767398c 3 days ago 29.9MB
scweb 1.0 d07d5978a7b5 4 days ago 214MB
47.120.37.21:8088/zhihe/zh-nginx latest 080ed0ed8312 3 weeks ago 142MB
prom/prometheus latest a07b618ecd1d 4 weeks ago 234MB
busybox 1.36 7cfbbec8963d 5 weeks ago 4.86MB
hello-world latest feb5d9fea6a5 19 months ago 13.3kB
gcr.io/cadvisor/cadvisor latest 68c29634fe49 2 years ago 163MB
切换到Prom目录启动容器
[root@localhost prom]# docker compose up -d
[+] Running 3/3
✔ Container redis Started 0.4s
✔ Container cadvisor Started 0.7s
✔ Container prometheus Started 1.5s
三、访问localhost:8080查看cadvisor的Web界面,访问 localhost:9090 查看Prom界面
cadvisor可以看到所有正在运行的容器即可
哪里说得不对欢迎留言评论哈,会第一时间修改滴
redis6版本下载 redis 6.2
文章目录安装系统要求下载RedisRedis安装(单机版)Redis安装(哨兵)Redis安装(分片集群)总结 安装系统要求关于操作系统的选择,Centos7下载Rediswget https://download.redis.io/releases/redis-6.2.4.tar.gzRedis安装(单机版)####编绎如下yum install -y gcc gcc-c++
tar -zxv