Dashboard automatisch provisionieren
Das Grafana-Dogu bietet die Möglichkeit, Dashboards mit Datasources automatisch zu provisionieren.
Diese sind dann über die Oberfläche sichtbar, aber unveränderbar. Um das zu erreichen, müssen bestimmte Dateien
in das Volume des Grafana-Dogus abgelegt werden. Wie genau diese zu erzeugen sind, kann in der offiziellen Dokumentation
dazu angesehen werden.
Im folgenden Abschnitt sind einige Beispieldateien, mit denen ein Dashboard für unsere
k8s-prometheus
-Komponente erzeugt werden kann. Die Dateien können entsprechend der oben genannten Dokumentation
beliebig angepasst werden.
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"
}
Diese Dateien dienen als Beispiel und könnten wie folgt in das Volume des Grafana-Dogus gelegt werden:
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}"
Standard-Dashboard überschreiben
Wenn die k8s-prometheus
-Komponente im CES installiert ist, wird ein Standard-Dashboard ausgebracht.
Dieses kann nicht gelöscht werden, aber es kann überschrieben werden. Dafür kann ein Custom-Dashboard mit einem
bestimmten Namen erstellt werden.
Folgende Dateien müssen wie weiter oben beschrieben in das Volume des Grafana-Dogus gelegt werden:
- ces-default-prometheus-datasource.yaml (Datasource-Konfiguration)
- datasources/ces-admin-default-dashboard-provider.yaml (Dashboard-Provider-Konfiguration)
- dashboards/ces-admin/ces-admin-default-dashboard.json (Dashboard-Definition)
Werden diese Dateien korrekt in das Volume gelegt, wird das standard-dashboard überschrieben.