Kitloft

All tools / Docker Compose examples

Monitoring stack with Docker Compose

A complete single-host monitoring stack: Prometheus scraping itself and Node Exporter, Alertmanager for alerts, and Grafana with Prometheus already connected.

Customize names, versions and passwords →

compose.yaml
services:
  prometheus:
    image: prom/prometheus:v3.4.0
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --storage.tsdb.retention.time=15d
    configs:
      - source: prometheus_config
        target: /etc/prometheus/prometheus.yml
    volumes:
      - prometheus-data:/prometheus
    ports:
      - "127.0.0.1:9090:9090"

  node-exporter:
    image: prom/node-exporter:v1.9.1
    restart: unless-stopped
    command:
      - --path.rootfs=/host
    pid: host
    volumes:
      - /:/host:ro,rslave

  alertmanager:
    image: prom/alertmanager:v0.28.1
    restart: unless-stopped
    configs:
      - source: alertmanager_config
        target: /etc/alertmanager/alertmanager.yml

  grafana:
    image: grafana/grafana:12.0.0
    restart: unless-stopped
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: "change-me"
    configs:
      - source: grafana_datasources
        target: /etc/grafana/provisioning/datasources/datasources.yaml
    volumes:
      - grafana-data:/var/lib/grafana
    ports:
      - "127.0.0.1:3000:3000"
    depends_on:
      - prometheus

configs:
  prometheus_config:
    content: |
      global:
        scrape_interval: 30s
      alerting:
        alertmanagers:
          - static_configs:
              - targets: ["alertmanager:9093"]
      scrape_configs:
        - job_name: prometheus
          static_configs:
            - targets: ["localhost:9090"]
        - job_name: node
          static_configs:
            - targets: ["node-exporter:9100"]
  alertmanager_config:
    content: |
      route:
        receiver: default
      receivers:
        - name: default
  grafana_datasources:
    content: |
      apiVersion: 1
      datasources:
        - name: Prometheus
          type: prometheus
          access: proxy
          url: http://prometheus:9090
          isDefault: true

volumes:
  prometheus-data:
  grafana-data:

Passwords here are placeholders (change-me). The generator creates random ones for you.

How to use it

Commands
docker compose up -d
docker compose ps
docker compose logs -f