DE 

//Cloudogu EcoSystem Docs

Automatically provision dashboards

Grafana-Dogu offers the option of automatically provisioning dashboards with datasources. These are then visible via the interface, but cannot be changed. To achieve this, certain files must be must be stored in the Grafana-Dogu volume. How exactly these are to be created can be viewed in the official documentation for more information. The following section contains some example files that can be used to create a dashboard for our k8s-prometheus component can be created. The files can be customized according to the documentation can be customized as desired.

datasource.yaml

apiVersion: 1
datasources:
  - name: custom-prometheus-datasource
    type: prometheus
    url: http://k8s-prometheus:9090
    access: proxy
    isDefault: false
    basicAuth: true
    basicAuthUser: "$PROMETHEUS_USER"
    secureJsonData:
      basicAuthPassword: "$PROMETHEUS_PASSWORD"
    jsonData:
      httpMethod: POST
      manageAlerts: true
      prometheusType: Prometheus
      prometheusVersion: 2.50.1
      cacheLevel: 'High'

dashboard-provider.yaml

apiVersion: 1

providers:
  - name: 'custom-prometheus-provider'
    orgId: 1
    folder: ''
    folderUid: ''
    type: file
    disableDeletion: false
    updateIntervalSeconds: 60
    allowUiUpdates: false
    options:
      path: /opt/grafana/provisioning/dashboards
      foldersFromFilesStructure: true

dashboard.json

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "datasource",
          "uid": "prometheus-data"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "panels": [
    {
      "collapsed": false,
      "datasource": {
        "type": "prometheus",
        "uid": "PACA35AE2C051E366"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 79,
      "panels": [],
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "PACA35AE2C051E366"
          },
          "refId": "A"
        }
      ],
      "title": "Cluster Health",
      "type": "row"
    },
    {
      "datasource": {
        "uid": "$cluster"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [
            {
              "options": {
                "match": "null",
                "result": {
                  "text": "UP"
                }
              },
              "type": "special"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "none",
          "unitScale": true
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 4,
        "x": 0,
        "y": 1
      },
      "id": 81,
      "links": [],
      "maxDataPoints": 100,
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "sum"
          ],
          "fields": "",
          "values": false
        },
        "showPercentChange": false,
        "text": {},
        "textMode": "auto",
        "wideLayout": true
      },
      "pluginVersion": "10.3.3",
      "targets": [
        {
          "datasource": {
            "uid": "$cluster"
          },
          "expr": "sum(up{job=~\"apiserver|kube-scheduler|kube-controller-manager\"} == 0)",
          "refId": "A"
        }
      ],
      "title": "Control Plane Status",
      "type": "stat"
    }
  ],
  "refresh": "10s",
  "tags": [
    "kubernetes",
    "prometheus"
  ],
  "templating": {
    "list": [
      {
        "current": {
          "selected": false,
          "text": "prometheus-data",
          "value": "PACA35AE2C051E366"
        },
        "hide": 0,
        "includeAll": false,
        "multi": false,
        "name": "cluster",
        "options": [],
        "query": "prometheus",
        "queryValue": "",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      }
    ]
  },
  "time": {
    "from": "now-3h",
    "to": "now"
  },
  "title": "Kubernetes Monitoring Overview",
  "uid": "custom_dashboard",
  "version": 1,
  "timezone": "browser"
}

These files serve as an example and could be placed in the Grafana-Dogus volume as follows:

GRAFANA_POD="$(kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "^grafana")"
kubectl exec "${GRAFANA_POD}" -- mkdir -p /custom-provisioning/datasources
kubectl exec "${GRAFANA_POD}" -- mkdir -p /custom-provisioning/dashboards
kubectl exec "${GRAFANA_POD}" -- mkdir -p /custom-provisioning/dashboards/my
kubectl cp dashboard.json "${GRAFANA_POD}":/custom-provisioning/dashboards/my/dashboard.json
kubectl cp dashboard-provider.yaml "${GRAFANA_POD}":/custom-provisioning/dashboards/dashboard-provider.yaml
kubectl cp datasource.yaml "${GRAFANA_POD}":/custom-provisioning/datasources/datasource.yaml
kubectl delete pod "${GRAFANA_POD}"

Overwrite default dashboard

If the k8s-prometheus component is installed in the CES, a standard dashboard is deployed. This cannot be deleted, but it can be overwritten. A custom dashboard with a specific name can be name can be created. The following files must be placed in the Grafana-Dogus volume as described above:

  • ces-default-prometheus-datasource.yaml (Datasource configuration)
  • datasources/ces-admin-default-dashboard-provider.yaml (dashboard provider configuration)
  • dashboards/ces-admin/ces-admin-default-dashboard.json (dashboard definition)

If these files are placed correctly in the volume, the standard dashboard is overwritten.