Grafana集成cadvisor和prometheus 监控容器和宿主机占用-视频-gif教程

先看效果


image.png

image.png

概念介绍:

grafana :用于数据展示,有丰富的模版
cadvisor :用于容器和宿主机的状态监控
prometheus :主动收集cadvisor上的数据,集成到Grafana显示

服务部署:

目录结构

./docker-compose.yaml
./prometheus/config/prometheus.yml

docker-compose.yaml文件:

version: '3.4'
services:
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"

  cadvisor:
    image: google/cadvisor:latest
    restart: unless-stopped
    container_name: cadvisor
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /dev/disk/:/dev/disk:ro
      - /var/lib/docker/:/var/lib/docker:ro
    command:
      - "--disable_metrics=udp,tcp,percpu,sched"
      - "--storage_duration=15s"
      - "-docker_only=true"
      - "-housekeeping_interval=30s"
      - "-disable_metrics=disk"
    ports:
      - 8180:8080

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    network_mode: host
    user: root
    hostname: prometheus
    restart: unless-stopped
    volumes:
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
      - ./prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus/data:/prometheus
      - ./prometheus/discovery:/etc/prometheus/discovery
    command:
      - '--web.enable-lifecycle'
      - '--web.enable-admin-api'
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention=30d'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
    logging:
      driver: json-file
      options:
        max-file: '3'
        max-size: 100m

/prometheus/config/prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus-service'
    file_sd_configs:
     - files: ['/etc/prometheus/discovery/prometheus.yml']
       refresh_interval: 5s
  - job_name: 'cadvisor'
    static_configs:
      - targets: ['x.x.x.x:8180']

x.x.x.x:8180为 cadvisor内网地址

在当前目录执行命令部署

 docker-compose up -d

服务启动后访问自己部署的grafana账号和密码都是admin

配置监控

1.登录grafana配置prometheus数据源
2.登录grafana官网寻找容器监控插件 grafana官网:https://grafana.com
3.选择数据源
4.展示并添加收藏

grafana配置数据源以及数据模板GIF:


grafana2.gif

你可能感兴趣的:(Grafana集成cadvisor和prometheus 监控容器和宿主机占用-视频-gif教程)