编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Docker+Prometheus+grafana+cadvisor监控Docker容器

wxchong 2024-10-15 17:19:58 开源技术 10 ℃ 0 评论

一、安装Docker

操作系统要求

要安装Docker Engine,您需要一个CentOS 7或8的维护版本。不支持或未测试存档版本。

centos-extras库必须启用。默认情况下,此存储库是启用的,但是如果已禁用它,则需要 重新启用它。

安装

     sudo yum install -y yum-utils
     sudo yum-config-manager \
     --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    sudo yum install docker-ce docker-ce-cli containerd.io

启动

   systemctl start docker
   systemctl status docker
   systemctl enable docker

二、安装prometheus

注意:docker安装完成后,需要设置阿里云加速器,这里不再赘述。
编辑start_prometheus.sh脚本,如下:

 #!/bin/bash
 docker run -d \
--name prometheus \
--restart=always \
--privileged=true  \
-p 9090:9090 \
-e TZ=Asia/Shanghai \
-v /etc/localtime:/etc/localtime \
-v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus 

三、安装grafana

#!/bin/bash
docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -v /server/grafana:/var/lib/grafana \
  --restart=always \
  --privileged=true  \
  -e TZ=Asia/Shanghai \
  -v /etc/localtime:/etc/localtime \
  --name grafana \
 grafana/grafana  

四、安装cadvisor

sudo docker run \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:rw \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
 --restart=always \
  --privileged=true  \
  -e TZ=Asia/Shanghai \
  -v /etc/localtime:/etc/localtime \
 -p 18104:8080 \
  --name=cadvisor \
  google/cadvisor

五、prometheus添加Docker监控

  vim prometheus.yml
  - job_name: 'MyDocker'
    static_configs:
    - targets: ['127.0.0.1:18104']

重启prometheus:

pkill -9 prometheus
nohup /server/prometheus/prometheus --config.file=/server/prometheus/prometheus.yml  > /dev/null &

六、添加docker仪表

打开grafana后台:http://Ip:3000
然后点击'+',导入仪表。
填入模板ID:
11558,选择数据源,导入即可。





至此,Docker+Prometheus+grafana+cadvisor监控Docker容器完美结束,so easy!

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表