From 77f38cdb84962a560fb338dfeda63a9a8261f398 Mon Sep 17 00:00:00 2001 From: "yunju.lly" Date: Sat, 24 Jun 2023 11:26:15 +0800 Subject: [PATCH] feat: add loki dashboard for kubernetes pods log (#3903) --- helm/dashboards/container-log.json | 301 ++++++++++++++++++ .../grafana/configmaps-datasources.yaml | 7 + 2 files changed, 308 insertions(+) create mode 100644 helm/dashboards/container-log.json diff --git a/helm/dashboards/container-log.json b/helm/dashboards/container-log.json new file mode 100644 index 000000000000..6e7f9a4de81e --- /dev/null +++ b/helm/dashboards/container-log.json @@ -0,0 +1,301 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "description": "Basic dashboard for Kubernetes Container Logs from Loki.", + "editable": true, + "fiscalYearStartMonth": 0, + "gnetId": 18494, + "graphTooltip": 0, + "id": 12, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 42, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "editorMode": "builder", + "expr": "sum(count_over_time({namespace=~\"$namespace\", pod=~\"$pod\", container=~\"$container\"} |~ `$search` [$__interval]))", + "legendFormat": "{{container}}", + "queryType": "range", + "refId": "A", + "resolution": 4 + } + ], + "title": "Logs Trend", + "type": "timeseries" + }, + { + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "gridPos": { + "h": 26, + "w": 24, + "x": 0, + "y": 10 + }, + "id": 3, + "options": { + "dedupStrategy": "exact", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": true, + "showTime": true, + "sortOrder": "Descending", + "wrapLogMessage": true + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "editorMode": "builder", + "expr": "{namespace=~\"$namespace\", pod=~\"$pod\", container=~\"$container\"} |~ `(?i)$search`", + "queryType": "range", + "refId": "A" + } + ], + "title": "Logs Panel", + "type": "logs" + } + ], + "refresh": false, + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "allValue": ".+", + "current": { + "selected": false, + "text": "All", + "value": "$__all" + }, + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "definition": "", + "hide": 0, + "includeAll": true, + "label": "Namespace", + "multi": false, + "name": "namespace", + "options": [], + "query": { + "label": "namespace", + "refId": "LokiVariableQueryEditor-VariableQuery", + "stream": "", + "type": 1 + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "type": "query" + }, + { + "allValue": ".+", + "current": { + "selected": false, + "text": "All", + "value": "$__all" + }, + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "definition": "", + "hide": 0, + "includeAll": true, + "label": "Pod", + "multi": false, + "name": "pod", + "options": [], + "query": { + "label": "pod", + "refId": "LokiVariableQueryEditor-VariableQuery", + "stream": "{namespace=~\"$namespace\"}", + "type": 1 + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "type": "query" + }, + { + "allValue": ".+", + "current": { + "selected": false, + "text": "All", + "value": "$__all" + }, + "datasource": { + "type": "loki", + "uid": "loki-kubeblocks" + }, + "definition": "", + "hide": 0, + "includeAll": true, + "label": "Container", + "multi": false, + "name": "container", + "options": [], + "query": { + "label": "container", + "refId": "LokiVariableQueryEditor-VariableQuery", + "stream": "{namespace=~\"$namespace\", pod=~\"$pod\"}", + "type": 1 + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "type": "query" + }, + { + "current": { + "selected": false, + "text": "", + "value": "" + }, + "hide": 0, + "label": "Search Term", + "name": "search", + "options": [ + { + "selected": true, + "text": "", + "value": "" + } + ], + "query": "", + "skipUrlSync": false, + "type": "textbox" + } + ] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "", + "title": "Container Logs", + "uid": "container-logs", + "version": 1, + "weekStart": "" +} \ No newline at end of file diff --git a/helm/templates/grafana/configmaps-datasources.yaml b/helm/templates/grafana/configmaps-datasources.yaml index cdf04becb4fd..2e4054f5acfd 100644 --- a/helm/templates/grafana/configmaps-datasources.yaml +++ b/helm/templates/grafana/configmaps-datasources.yaml @@ -42,5 +42,12 @@ data: isDefault: false jsonData: timeInterval: 15s + - name: Loki + type: loki + uid: loki-kubeblocks + access: proxy + url: http://loki-gateway:80 + jsonData: + maxLines: 1000 {{- end }} {{- end }}