Grafana

#Setup

//  - docker-compose.yaml - 
x-common-user:
  username: &username admin
  password: &password Password123

x-common-settings: &settings
  restart: unless-stopped
  networks:
    - dap

x-healthchecks: &healthchecks
  start_period: 20s
  interval: 10s
  timeout: 1s
  retries: 60

services:

  grafana:
    <<: *settings
    image: grafana/grafana:11.0.0
    ports:
      - "3000:3000"
    volumes:
    - grafanadata:/var/lib/grafana/
    - ./datasources.yaml:/etc/grafana/provisioning/datasources/datasource.yaml
    - ./dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml
    environment:
      GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
      GF_AUTH_BASIC_ENABLED: true
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_SECURITY_ADMIN_USER: admin
      GF_INSTALL_PLUGINS: grafana-piechart-panel,grafana-worldmap-panel
    healthcheck:
      <<: *healthchecks
      test: [ "CMD-SHELL", "curl -s --fail '0.0.0.0:3000/healthz' > /dev/null"]

  prometheus:
    <<: *settings
    image: prom/prometheus:v2.52.0
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - --config.file=/etc/prometheus/prometheus.yml
    healthcheck:
      <<: *healthchecks
      test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider '0.0.0.0:9090/-/healthy' || exit 1"]

volumes:
  elasticsearchdata:
    driver: local
  grafanadata:
    driver: local


networks:
  dap: {}
//  - datasources.yaml - 
apiVersion: 1

datasources:
  - name: PrometheusDS
    type: prometheus
    # access: proxy
    url: http://prometheus:9090
    orgId: 1
    isDefault: true
    jsonData:
      httpMethod: POST
      # manageAlerts: true
      prometheusType: Prometheus
//  - dashboard.yaml - 
apiVersion: 1

providers:
  - name: 'default'
    orgId: 1
    folder: ''
    type: file
    disableDeletion: false
    editable: true
    updateIntervalSeconds: 3
    allowUiUpdates: true
    options:
      path: /var/lib/grafana/dashboards/
//  - prometheus.yml - 
global:
  scrape_interval: 15s
  evaluation_interval: 15s
rule_files:
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
    - targets:
      - 'localhost:9090'

#Mac

brew install grafana

# then
/opt/homebrew/opt/grafana/bin/grafana server --config /opt/homebrew/etc/grafana/grafana.ini --homepath /opt/homebrew/opt/grafana/share/grafana --packaging\=brew cfg:default.paths.logs\=/opt/homebrew/var/log/grafana cfg:default.paths.data\=/opt/homebrew/var/lib/grafana cfg:default.paths.plugins\=/opt/homebrew/var/lib/grafana/plugins

# or
brew services start grafana

#Dashboards

#Variables

Open Dashboard Settings, select Variables, and click Add Variable. Select the Query variable type and use these settings:

  • Name: “Var Name”
  • Label: “Var”

And then templating:

Dashboard -> Variable -> Add Variable

#Data Sources

#Elasticsearch

  • {{metric}} metric name (e.g. Count for count)
  • {{term fieldname}}
  • {{field}}