DELAPARRA
Index
Kleur
EN

Grafana-dashboards

Maak en beheer Grafana-dashboards voor de realtime visualisatie van systeem- en applicatiestatistieken. Gebruik deze bij het bouwen van monitoringdashboards, het visualiseren van statistieken of het maken van interfaces voor operationele observabiliteit.

Licentie MIT

Bron wshobson/agents

Download zip

Grafana-dashboards

Maak en beheer Grafana-dashboards die klaar zijn voor productie, voor een uitgebreid inzicht in je systeem.

Doel

Ontwerp effectieve Grafana-dashboards voor het monitoren van applicaties, infrastructuur en bedrijfsstatistieken.

Wanneer gebruik je dit?

  • Prometheus-statistieken visualiseren
  • Maak je eigen dashboards
  • SLO-dashboards implementeren
  • Infrastructuur monitoren
  • Zakelijke KPI’s bijhouden

Ontwerpprincipes voor dashboards

1. Informatiehiërarchie

┌─────────────────────────────────────┐
│  Critical Metrics (Big Numbers)     │
├─────────────────────────────────────┤
│  Key Trends (Time Series)           │
├─────────────────────────────────────┤
│  Detailed Metrics (Tables/Heatmaps) │
└─────────────────────────────────────┘

2. RED-methode (Diensten)

  • Snelheid - Verzoeken per seconde
  • Fouten - Foutpercentage
  • Duur - Vertraging/responstijd

3. USE-methode (Bronnen)

  • Gebruik - % van de tijd dat de hulpbron bezet is
  • Verzadiging - Wachtrijlengte/wachttijd
  • Fouten - Aantal fouten

Opbouw van het dashboard

API-monitoringdashboard

{
  "dashboard": {
    "title": "API Monitoring",
    "tags": ["api", "production"],
    "timezone": "browser",
    "refresh": "30s",
    "panels": [
      {
        "title": "Request Rate",
        "type": "graph",
        "targets": [
          {
            "expr": "sum(rate(http_requests_total[5m])) by (service)",
            "legendFormat": "{{service}}"
          }
        ],
        "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 }
      },
      {
        "title": "Error Rate %",
        "type": "graph",
        "targets": [
          {
            "expr": "(sum(rate(http_requests_total{status=~\"5..\"}[5m])) / sum(rate(http_requests_total[5m]))) * 100",
            "legendFormat": "Error Rate"
          }
        ],
        "alert": {
          "conditions": [
            {
              "evaluator": { "params": [5], "type": "gt" },
              "operator": { "type": "and" },
              "query": { "params": ["A", "5m", "now"] },
              "type": "query"
            }
          ]
        },
        "gridPos": { "x": 12, "y": 0, "w": 12, "h": 8 }
      },
      {
        "title": "P95 Latency",
        "type": "graph",
        "targets": [
          {
            "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))",
            "legendFormat": "{{service}}"
          }
        ],
        "gridPos": { "x": 0, "y": 8, "w": 24, "h": 8 }
      }
    ]
  }
}

Soorten panelen

1. Stat-paneel (enkele waarde)

{
  "type": "stat",
  "title": "Total Requests",
  "targets": [
    {
      "expr": "sum(http_requests_total)"
    }
  ],
  "options": {
    "reduceOptions": {
      "values": false,
      "calcs": ["lastNotNull"]
    },
    "orientation": "auto",
    "textMode": "auto",
    "colorMode": "value"
  },
  "fieldConfig": {
    "defaults": {
      "thresholds": {
        "mode": "absolute",
        "steps": [
          { "value": 0, "color": "green" },
          { "value": 80, "color": "yellow" },
          { "value": 90, "color": "red" }
        ]
      }
    }
  }
}

2. Tijdreeksgrafiek

{
  "type": "graph",
  "title": "CPU Usage",
  "targets": [
    {
      "expr": "100 - (avg by (instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)"
    }
  ],
  "yaxes": [
    { "format": "percent", "max": 100, "min": 0 },
    { "format": "short" }
  ]
}

3. Tafelpaneel

{
  "type": "table",
  "title": "Service Status",
  "targets": [
    {
      "expr": "up",
      "format": "table",
      "instant": true
    }
  ],
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": { "Time": true },
        "indexByName": {},
        "renameByName": {
          "instance": "Instance",
          "job": "Service",
          "Value": "Status"
        }
      }
    }
  ]
}

4. Heatmap

{
  "type": "heatmap",
  "title": "Latency Heatmap",
  "targets": [
    {
      "expr": "sum(rate(http_request_duration_seconds_bucket[5m])) by (le)",
      "format": "heatmap"
    }
  ],
  "dataFormat": "tsbuckets",
  "yAxis": {
    "format": "s"
  }
}

Variabelen

Queryvariabelen

{
  "templating": {
    "list": [
      {
        "name": "namespace",
        "type": "query",
        "datasource": "Prometheus",
        "query": "label_values(kube_pod_info, namespace)",
        "refresh": 1,
        "multi": false
      },
      {
        "name": "service",
        "type": "query",
        "datasource": "Prometheus",
        "query": "label_values(kube_service_info{namespace=\"$namespace\"}, service)",
        "refresh": 1,
        "multi": true
      }
    ]
  }
}

Variabelen gebruiken in query's

sum(rate(http_requests_total{namespace="$namespace", service=~"$service"}[5m]))

Waarschuwingen in dashboards

{
  "alert": {
    "name": "High Error Rate",
    "conditions": [
      {
        "evaluator": {
          "params": [5],
          "type": "gt"
        },
        "operator": { "type": "and" },
        "query": {
          "params": ["A", "5m", "now"]
        },
        "reducer": { "type": "avg" },
        "type": "query"
      }
    ],
    "executionErrorState": "alerting",
    "for": "5m",
    "frequency": "1m",
    "message": "Error rate is above 5%",
    "noDataState": "no_data",
    "notifications": [{ "uid": "slack-channel" }]
  }
}

Dashboard instellen

dashboards.yml:

apiVersion: 1

providers:
  - name: "default"
    orgId: 1
    folder: "General"
    type: file
    disableDeletion: false
    updateIntervalSeconds: 10
    allowUiUpdates: true
    options:
      path: /etc/grafana/dashboards

Veelvoorkomende dashboardpatronen

Infrastructuurdashboard

Belangrijkste panelen:

  • CPU-gebruik per node
  • Geheugengebruik per node
  • Schijf-I/O
  • Netwerkverkeer
  • Aantal pods per naamruimte
  • Status van het knooppunt

Database-dashboard

Belangrijkste panelen:

  • Vragen per seconde
  • Gebruik van de verbindingspool
  • Verwerkingsvertraging (P50, P95, P99)
  • Actieve verbindingen
  • Grootte van de database
  • Replicatievertraging
  • Trage zoekopdrachten

Toepassingsdashboard

Belangrijkste panelen:

  • Verzoekfrequentie
  • Foutpercentage
  • Reactietijd (percentielen)
  • Actieve gebruikers/sessies
  • Cache-hitpercentage
  • Wachtrijlengte

Beste praktijken

  1. Begin met sjablonen (Grafana-communitydashboards)
  2. Gebruik een consistente naamgeving voor panelen en variabelen
  3. Groepsgerelateerde statistieken in rijen
  4. Stel de juiste tijdsperiodes in (standaard: de afgelopen 6 uur)
  5. Gebruik variabelen voor meer flexibiliteit
  6. Voeg paneelbeschrijvingen toe voor wat context
  7. Stel de eenheden correct in
  8. Stel zinvolle drempelwaarden in voor kleuren
  9. Gebruik dezelfde kleuren in alle dashboards
  10. Probeer eens verschillende tijdsperiodes

Dashboard als code

Terraform-provisioning

resource "grafana_dashboard" "api_monitoring" {
  config_json = file("${path.module}/dashboards/api-monitoring.json")
  folder      = grafana_folder.monitoring.id
}

resource "grafana_folder" "monitoring" {
  title = "Production Monitoring"
}

Ansible-provisioning

- name: Deploy Grafana dashboards
  copy:
    src: "{{ item }}"
    dest: /etc/grafana/dashboards/
  with_fileglob:
    - "dashboards/*.json"
  notify: restart grafana

Gerelateerde vaardigheden

  • prometheus-configuration - Voor het verzamelen van statistieken
  • slo-implementation - Voor SLO-dashboards

Bestanden

  • LICENSE
  • SKILL.md
  • SOURCE.md

Gerelateerde termen

Een skill installeren in je AI-assistent