cAdvisor + Prometheus + Grafana

2023-03-15  本文已影响0人  伊丽莎白菜

写在前面

cAdvisor:google开源的一个docker container监控工具,自带web ui,并支持导出到prometheus、influxdb等存储;

prometheus + grafana安装看这里

安装配置

cAdvisor

  1. 配置用户名密码
    为cAdvisor web ui生成认证文件auth.htpasswd,用户http basic认证:

    yum install -y httpd-tools
    htpasswd -b -c auth.htpasswd user1 password1
    
  2. docker-compose配置
    auth.htpasswddocker-compose.yml放到同一目录下:

    version: '3.3'
    services:
     cadvisor:
      image: google/cadvisor:v0.33.0
      ports:
        - "8030:8080"
      volumes:
        - /:/rootfs:ro
        - /var/run:/var/run:rw
        - /sys:/sys:ro
        #- /var/lib/docker/:/var/lib/docker:ro
        - /apps/data/docker/:/var/lib/docker:ro
        - /dev/disk/:/dev/disk:ro
        - /cgroup:/cgroup:ro
        - ./auth.htpasswd:/etc/auth.htpasswd
      command:
        - '--http_auth_file=/etc/auth.htpasswd'
      privileged: true
      devices:
        - /dev/kmsg
    
  3. 启动并验证
    docker-compose up -d启动,浏览器访问cAdvisor web uihttp://{host}:8030,输入用户名密码登录,可以看到如下界面:

image-20230316151046713.png
  1. 每台宿主机分别启动cAdvisor

Prometheus

prometheus.yml添加job,指向cAdvisorhttp地址:

scrape_configs:
  - job_name: 'cadvisor_docker_exporter'
    static_configs:
      - targets:
        - 192.168.0.182:8030
        - 192.168.1.10:8030
        - 192.168.3.220:8030

Grafana

  1. 导入dashboard模板
    docker-container.json
  2. 查看效果
image-20230316151944037.png
上一篇 下一篇

猜你喜欢

热点阅读