Provisioning Grafana Docker docker-compose.yml

  prometheus:
    image: prom/prometheus
    restart: always
    volumes:
      - ./prometheus/config.yaml:/etc/prometheus/prometheus.yml
    command: "--config.file=/etc/prometheus/prometheus.yml"
    ports:
      - "9090:9090" # ui
    networks:
      - service

  grafana:
    image: grafana/grafana
    restart: always
    volumes:
      - ./grafana/dashboards:/etc/grafana/provisioning/dashboards/
      - ./grafana/datasources:/etc/grafana/provisioning/datasources/
    ports:
      - "3000:3000" # ui
    networks:
      - service

File structure

./grafana
├── dashboards
│   ├── dashboard.yaml
│   └── go-processes_rev2.json
└── datasources
    └── datasources.yaml

dashboard.yaml

apiVersion: 1

providers:
  # <string> an unique provider name
  - name: "a unique provider name"
    # <int> org id. will default to orgId 1 if not specified
    orgId: 1
    # <string, required> name of the dashboard folder. Required
    folder: ""
    # <string> folder UID. will be automatically generated if not specified
    folderUid: ""
    # <string, required> provider type. Required
    type: file
    # <bool> disable dashboard deletion
    disableDeletion: false
    # <bool> enable dashboard editing
    editable: true
    # <int> how often Grafana will scan for changed dashboards
    updateIntervalSeconds: 10
    options:
      # <string, required> path to dashboard files on disk. Required
      path: /etc/grafana/provisioning/dashboards

datasources.yaml

apiVersion: 1

# https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources
datasources:
  - name: prometheus
    type: prometheus
    access: proxy
    orgId: 1
    url: http://prometheus:9090
    basicAuth: false
    isDefault: true
    version: 1

Prometheus Config (config.yaml)

global:
  scrape_interval: 15s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # Evaluate rules every 15 seconds.

scrape_configs:
  - job_name: "prometheus"
    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "service1"
    metrics_path: "/actuator/prometheus"
    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    static_configs:
      - targets: ["host.docker.internal:30010"]

  - job_name: "service2"
    metrics_path: "/metrics"
    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    static_configs:
      - targets: ["worker:30020"]