13 grudnia 2021

Portainer #4 - Monitoring

Zbieranie danych

Instalujemy agenta zbierania danych Node exporter oraz cadvisor.

version: '3.8'

services:
  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    hostname: portainer-pc
    ports: [9100:9100]
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.rootfs=/rootfs'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'


  cadvisor:
    image: google/cadvisor:latest
    container_name: cadvisor
    restart: unless-stopped
    ports: ['19998:8080']
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro

cadvisor dla arm uruchomiony na raspberry PI

  image: braingamer/cadvisor-arm:latest

Node exporter możemy też zainstalować bez dockera.

sudo apt install prometheus-node-exporter

Docker stack dla Grafana i Prometheus

version: '3.8'

networks:
  grafana-net:
    name: grafana-net
    driver: bridge

services:
  grafana:
    container_name: grafana
    image: grafana/grafana:latest
    restart: unless-stopped
    networks: [grafana-net]
    ports: ['3000:3000']
    depends_on: [prometheus]
    environment: {}
    volumes:
      - grafana_storage:/var/lib/grafana
    

  prometheus:
    container_name: prometheus
    image: prom/prometheus
    command:
      - '--config.file=/config/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      #- '--storage.tsdb.retention=200h'
      - '--web.enable-lifecycle'
    networks: [grafana-net]
    ports: ['9090:9090']
    volumes:
      - prometheus_config:/config
      - prometheus_storage:/prometheus
      

volumes:
  grafana_storage:
    driver: local
    name: grafana_storage
  prometheus_storage:
    driver: local
    name: prometheus_storage
  prometheus_config:
    driver: local
    name: prometheus_config

prometheus config

global:
  scrape_interval:     15s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "node"
    static_configs:
      - "portainer-pc.lan:9100"
      - "portainer-pi.lan:9100"
      - "pi-hole.lan:9100"
        
  - job_name: 'cadvisor'
    metrics_path: '/metrics'
    static_configs:
      - targets:
          - "portainer-pc.lan:19998"
          - "portainer-pi.lan:19998"
        labels:
          group: 'cadvisor'
  

Pozostaje nam tylko skonfigurować dashboard w Grafana.

Linki