diff --git a/5-2-loki-dashboards-flog/docker-compose.yml b/5-2-loki-dashboards-flog/docker-compose.yml new file mode 100644 index 0000000..cd5b4c8 --- /dev/null +++ b/5-2-loki-dashboards-flog/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3.9" + +services: + grafana: + image: "grafana/grafana:8.4.2" + ports: + - "3000:3000" + volumes: + - ./provisioning:/etc/grafana/provisioning + environment: + - GF_PLUGINS_PLUGIN_ADMIN_ENABLED=true + + loki: + image: "grafana/loki:2.4.2" + ports: + - "3100:3100" + + promtail: + image: "grafana/promtail:2.4.2" + volumes: + - logs_dir:/tmp/log + - ./promtail.yml:/etc/promtail/config.yaml + command: -config.file=/etc/promtail/config.yaml + + flog: + image: "mingrammer/flog:0.4.3" + command: -f json -t log -o /tmp/log/json.log -d 200ms -w -l + volumes: + - logs_dir:/tmp/log + +volumes: + logs_dir: \ No newline at end of file diff --git a/5-2-loki-dashboards-flog/promtail.yml b/5-2-loki-dashboards-flog/promtail.yml new file mode 100644 index 0000000..b237340 --- /dev/null +++ b/5-2-loki-dashboards-flog/promtail.yml @@ -0,0 +1,11 @@ +clients: + - url: http://loki:3100/loki/api/v1/push + +scrape_configs: + - job_name: flog + static_configs: + - targets: + - localhost + labels: + job: flogs + __path__: /tmp/log/*.log \ No newline at end of file diff --git a/5-2-loki-dashboards-flog/provisioning/dashboards/loki.yaml b/5-2-loki-dashboards-flog/provisioning/dashboards/loki.yaml new file mode 100644 index 0000000..e48c93c --- /dev/null +++ b/5-2-loki-dashboards-flog/provisioning/dashboards/loki.yaml @@ -0,0 +1,9 @@ +apiVersion: 1 + +providers: + - name: 'Loki dashboards' + type: file + allowUiUpdates: true + options: + path: /etc/grafana/provisioning/dashboards/loki + foldersFromFilesStructure: false \ No newline at end of file diff --git a/5-2-loki-dashboards-flog/provisioning/dashboards/loki/flog.json b/5-2-loki-dashboards-flog/provisioning/dashboards/loki/flog.json new file mode 100644 index 0000000..1bc0e47 --- /dev/null +++ b/5-2-loki-dashboards-flog/provisioning/dashboards/loki/flog.json @@ -0,0 +1,840 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + }, + { + "enable": true, + "expr": "{job=\"flogs\"} | json | bytes > 29900", + "hide": false, + "iconColor": "red", + "name": "Show Large Requests", + "target": {} + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 1, + "iteration": 1648254271582, + "links": [], + "liveNow": false, + "panels": [ + { + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "dedupStrategy": "none", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": false, + "showTime": false, + "sortOrder": "Descending", + "wrapLogMessage": false + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "{job=\"flogs\"}", + "refId": "A" + } + ], + "title": "Logs", + "transparent": true, + "type": "logs" + }, + { + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 8, + "options": { + "dedupStrategy": "none", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": false, + "showTime": false, + "sortOrder": "Descending", + "wrapLogMessage": false + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "{job=\"flogs\"} | json | line_format \"{{ .method }} {{ .request }} 👉 {{ .status }} by {{ .user_identifier }} ({{div .bytes 1000}} kb)\" ", + "refId": "A" + } + ], + "title": "Simplified logs", + "transparent": true, + "type": "logs" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "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 + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 6 + }, + "id": 6, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom" + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "max_over_time({job=\"flogs\"} | json | unwrap bytes[5m]) by (status)", + "legendFormat": "{{status}}", + "refId": "A" + } + ], + "title": "Max size per HTTP status", + "transparent": true, + "type": "timeseries" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "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 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 6 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom" + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "max_over_time({job=\"flogs\"} | json | unwrap bytes[5m]) by (method)", + "legendFormat": "{{method}}", + "refId": "A" + } + ], + "title": "Max size per HTTP method", + "transparent": true, + "type": "timeseries" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 7, + "x": 0, + "y": 12 + }, + "id": 5, + "options": { + "displayLabels": [], + "legend": { + "displayMode": "list", + "placement": "bottom", + "values": [ + "value", + "percent" + ] + }, + "pieType": "pie", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "sum by (method) (count_over_time({job=\"flogs\"} | json [5m]))", + "legendFormat": "{{method}}", + "queryType": "range", + "refId": "A" + } + ], + "title": "Distribution by method", + "transparent": true, + "type": "piechart" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 7, + "x": 8, + "y": 12 + }, + "id": 7, + "options": { + "displayLabels": [], + "legend": { + "displayMode": "list", + "placement": "bottom", + "values": [ + "value", + "percent" + ] + }, + "pieType": "pie", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "sum by (status) (count_over_time({job=\"flogs\"} | json [5m]))", + "legendFormat": "{{status}}", + "queryType": "range", + "refId": "A" + } + ], + "title": "Distribution by status", + "transparent": true, + "type": "piechart" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 7, + "x": 15, + "y": 12 + }, + "id": 13, + "options": { + "displayLabels": [], + "legend": { + "displayMode": "list", + "placement": "bottom", + "values": [ + "value", + "percent" + ] + }, + "pieType": "pie", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "sum by (protocol) (count_over_time({job=\"flogs\"} | json [5m]))", + "legendFormat": "{{protocol}}", + "queryType": "range", + "refId": "A" + } + ], + "title": "Distribution by protocol", + "transparent": true, + "type": "piechart" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlYlRd" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "percentunit" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 0, + "y": 18 + }, + "id": 12, + "options": { + "colorMode": "background", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "sum(count_over_time({job=\"flogs\"} | json | user_identifier != \"-\" [5m])) / sum(count_over_time({job=\"flogs\"} [5m]))", + "queryType": "range", + "refId": "A" + } + ], + "title": "Identified requests (5m)", + "transparent": true, + "type": "stat" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 4, + "y": 18 + }, + "id": 9, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "sum(count_over_time({job=\"flogs\"} | json | bytes > 10000[5m])) / sum(count_over_time({job=\"flogs\"} | json [5m])) * 100", + "queryType": "range", + "refId": "A" + } + ], + "title": "> 10kb (5m)", + "transparent": true, + "type": "stat" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 8, + "y": 18 + }, + "id": 10, + "options": { + "colorMode": "background", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "count_over_time({job=\"flogs\"}[5m])", + "queryType": "range", + "refId": "A" + } + ], + "title": "Total lines (5m)", + "transparent": true, + "type": "stat" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "/s" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 12, + "y": 18 + }, + "id": 18, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "rate({job=\"flogs\"}[5m])", + "queryType": "range", + "refId": "A" + } + ], + "title": "Lines/sec (5m)", + "transparent": true, + "type": "stat" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 16, + "y": 18 + }, + "id": 11, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "max(max_over_time({job=\"flogs\"} | json | unwrap bytes[5m]))", + "queryType": "range", + "refId": "A" + } + ], + "title": "Largest request body (5m)", + "transparent": true, + "type": "stat" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "binBps" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 20, + "y": 18 + }, + "id": 19, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "8.4.2", + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "P8E80F9AEF21F6940" + }, + "expr": "bytes_rate({job=\"flogs\"}[5m])", + "queryType": "range", + "refId": "A" + } + ], + "title": "Bytes/sec (5m)", + "transparent": true, + "type": "stat" + } + ], + "refresh": "", + "schemaVersion": 35, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "flogs", + "value": "flogs" + }, + "definition": "label_values(job)", + "hide": 0, + "includeAll": false, + "multi": false, + "name": "job", + "options": [], + "query": "label_values(job)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-5m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Loki flog example", + "uid": "_JSEbzL7z", + "version": 14, + "weekStart": "" +} \ No newline at end of file diff --git a/5-2-loki-dashboards-flog/provisioning/datasources/loki.yml b/5-2-loki-dashboards-flog/provisioning/datasources/loki.yml new file mode 100644 index 0000000..fd2fc24 --- /dev/null +++ b/5-2-loki-dashboards-flog/provisioning/datasources/loki.yml @@ -0,0 +1,8 @@ +apiVersion: 1 + +datasources: + - name: Loki + type: loki + url: http://loki:3100 + isDefault: true + editable: true