From 7b44ba7eb396175deb24d405f526790efde704e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20n=C3=A8?= Date: Tue, 21 Oct 2025 03:03:04 +0000 Subject: [PATCH 1/3] chore: add extract logs --- configs/vector/vector.yaml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/configs/vector/vector.yaml b/configs/vector/vector.yaml index ff7c4d8..46e5bf8 100644 --- a/configs/vector/vector.yaml +++ b/configs/vector/vector.yaml @@ -10,9 +10,26 @@ sources: type: internal_metrics transforms: - msg_parser: + # Parse Docker labels and add Kubernetes-like labels + docker_labels: type: remap inputs: [docker] + source: | + # Extract Docker Compose labels + .container_name = .container.name + .namespace = .label.stackname + .app = .label."com.docker.compose.service" + .pod_name = .container.name + + # Add host info + .host = "docker-host" + + # Parse timestamp if available + .timestamp = parse_timestamp(.timestamp, format: "%+") ?? now() + + msg_parser: + type: remap + inputs: [docker_labels] # Changed from [docker] source: | .message = parse_json(.message) ?? .message @@ -29,7 +46,8 @@ sinks: enabled: false request: headers: - VL-Stream-Fields: source_type,label.com.docker.compose.service + # VL-Stream-Fields: container_name,namespace,app,host,pod_name + VL-Stream-Fields: container_name,namespace,app,host,pod_name,logging_jobname,stackname VL-Time-Field: timestamp VL-Msg-Field: message,log AccountID: "0" From 2ec27545063b0c29c3e1a016eaaa282672293ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20n=C3=A8?= Date: Tue, 21 Oct 2025 03:05:07 +0000 Subject: [PATCH 2/3] fix version grafana --- docker-compose.yml | 11 ++++++----- env.example | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bee7ed1..d8f3242 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,17 +2,17 @@ x-logging: &default-logging driver: "json-file" options: - max-size: "1m" - max-file: "1" + max-size: "10m" + max-file: "5" tag: "{{.Name}}" x-common-labels: &default-labels logging_jobname: "containerlogs" - stackname: "docker-monitoring-stack" + stackname: "docker-monitoring-vvc-stack" services: grafana: - image: grafana/grafana:${GRAFANA_VERSION:-latest} + image: grafana/grafana:${GRAFANA_VERSION:-12.2.0} # fix version to avoid breaking changes container_name: grafana restart: unless-stopped environment: @@ -36,8 +36,9 @@ services: - ./dashboards/vmalert.json:/var/lib/grafana/dashboards/vmalert.json:ro - ./dashboards/vm-cluster.json:/var/lib/grafana/dashboards/vm-cluster.json:ro # for victorialogs cluster - - ./dashboards/victorialogs_rev6.json:/var/lib/grafana/dashboards/victorialogs_rev6.json:ro + # - ./dashboards/victorialogs_rev6.json:/var/lib/grafana/dashboards/victorialogs_rev6.json:ro - ./dashboards/victorialogs-cluster.json:/var/lib/grafana/dashboards/victorialogs-cluster.json:ro + - ./dashboards/victorialogs-docker.json:/var/lib/grafana/dashboards/victorialogs-docker.json:ro # vector dashboard - ./dashboards/vector_21954.json:/var/lib/grafana/dashboards/vector_21954.json:ro - grafana-data:/var/lib/grafana diff --git a/env.example b/env.example index a95fc55..9c96913 100644 --- a/env.example +++ b/env.example @@ -2,7 +2,7 @@ # Copy this file to .env: cp env.example .env # Service Versions -GRAFANA_VERSION=12.0.0 +GRAFANA_VERSION=12.2.0 PROMETHEUS_VERSION=v2.42.0 CADVISOR_VERSION=v0.46.0 NODE_EXPORTER_VERSION=v1.5.0 From 8af950fe4e6ec871b6b8600da6cc0f3504e12e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20n=C3=A8?= Date: Tue, 21 Oct 2025 03:17:43 +0000 Subject: [PATCH 3/3] add new dashboard --- dashboards/victorialogs-docker.json | 453 ++++++++++++++++++++++++++++ 1 file changed, 453 insertions(+) create mode 100644 dashboards/victorialogs-docker.json diff --git a/dashboards/victorialogs-docker.json b/dashboards/victorialogs-docker.json new file mode 100644 index 0000000..40bf328 --- /dev/null +++ b/dashboards/victorialogs-docker.json @@ -0,0 +1,453 @@ +{ + "__inputs": [ + { + "name": "DS_VICTORIALOGS", + "label": "VictoriaLogs", + "description": "", + "type": "datasource", + "pluginId": "victoriametrics-logs-datasource", + "pluginName": "VictoriaLogs" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "10.4.14" + }, + { + "type": "panel", + "id": "logs", + "name": "Logs", + "version": "" + }, + { + "type": "panel", + "id": "piechart", + "name": "Pie chart", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + }, + { + "type": "datasource", + "id": "victoriametrics-logs-datasource", + "name": "VictoriaLogs", + "version": "0.21.1" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "description": "Dashboard to explore VictoriaLogs for Docker Compose", + "editable": true, + "fiscalYearStartMonth": 0, + "gnetId": 22759, + "graphTooltip": 0, + "id": null, + "links": [ + { + "asDropdown": false, + "icon": "bolt", + "includeVars": true, + "keepTime": true, + "tags": [], + "targetBlank": true, + "title": "View In Explore", + "tooltip": "", + "type": "link", + "url": "/explore?orgId=1&left={\"datasource\":\"$DS_VICTORIALOGS\",\"queries\":[{\"expr\":\"{container_name=\\\"$container\\\", namespace=\\\"$namespace\\\"} app:=\\\"$app\\\" AND ($query != \\\"\\\" or 1==1)\"}]}" + }, + { + "asDropdown": false, + "icon": "external link", + "includeVars": false, + "keepTime": false, + "tags": [], + "targetBlank": true, + "title": "Learn LogsQL", + "tooltip": "", + "type": "link", + "url": "https://docs.victoriametrics.com/victorialogs/logsql/" + } + ], + "panels": [ + { + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "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": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 18, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [ + "sum" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "editorMode": "code", + "expr": "{container_name=\"$container\", namespace=\"$namespace\", app=\"$app\"} | stats count()", + "legendFormat": "${namespace} ${container}", + "queryType": "statsRange", + "refId": "A" + } + ], + "title": "Logs in ${namespace} for ${container}", + "type": "timeseries" + }, + { + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [], + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 18, + "y": 0 + }, + "id": 3, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "editorMode": "code", + "expr": "{container_name=\"$container\", namespace=\"$namespace\", app=\"$app\"} | stats by (\"$count_by\") count() c | sort by (c desc) | limit 50", + "legendFormat": "{{$count_by}}", + "queryType": "stats", + "refId": "A" + } + ], + "title": "Count by $count_by", + "type": "piechart" + }, + { + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "gridPos": { + "h": 23, + "w": 24, + "x": 0, + "y": 6 + }, + "id": 1, + "options": { + "dedupStrategy": "none", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": false, + "showTime": true, + "sortOrder": "Descending", + "wrapLogMessage": false + }, + "targets": [ + { + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "editorMode": "code", + "expr": "{container_name=\"$container\", namespace=\"$namespace\", app=\"$app\"}", + "queryType": "range", + "refId": "A" + } + ], + "title": "Logs in ${namespace} for ${container}", + "type": "logs" + } + ], + "refresh": "", + "schemaVersion": 39, + "tags": ["docker", "victorialogs"], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "VictoriaLogs", + "value": "aec2c2ktzj6rkc" + }, + "description": "Datasource for logs", + "hide": 0, + "includeAll": false, + "label": "Logs Datasource", + "multi": false, + "name": "DS_VICTORIALOGS", + "options": [], + "query": "victoriametrics-logs-datasource", + "queryValue": "", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + }, + { + "current": {}, + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "definition": "", + "hide": 0, + "includeAll": false, + "multi": false, + "name": "namespace", + "options": [], + "query": { + "field": "namespace", + "limit": 100, + "query": "", + "refId": "VictoriaLogsVariableQueryEditor-VariableQuery", + "type": "fieldValue" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "type": "query" + }, + { + "allValue": "", + "current": {}, + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "definition": "{namespace=\"$namespace\"}", + "hide": 0, + "includeAll": false, + "multi": false, + "name": "app", + "options": [], + "query": { + "field": "app", + "limit": 0, + "query": "{namespace=\"$namespace\"}", + "refId": "VictoriaLogsVariableQueryEditor-VariableQuery", + "type": "fieldValue" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "type": "query" + }, + { + "allValue": "", + "current": {}, + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "definition": "{namespace=\"$namespace\"} app:=\"$app\"", + "hide": 0, + "includeAll": false, + "multi": false, + "name": "container", + "options": [], + "query": { + "field": "container_name", + "limit": 0, + "query": "{namespace=\"$namespace\"} app:=\"$app\"", + "refId": "VictoriaLogsVariableQueryEditor-VariableQuery", + "type": "fieldValue" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "type": "query" + }, + { + "allValue": "", + "current": {}, + "datasource": { + "type": "victoriametrics-logs-datasource", + "uid": "${DS_VICTORIALOGS}" + }, + "definition": "{namespace=\"$namespace\"} app:=\"$app\"", + "hide": 0, + "includeAll": false, + "multi": false, + "name": "count_by", + "options": [], + "query": { + "field": "container_name", + "limit": 25, + "query": "{namespace=\"$namespace\"} app:=\"$app\"", + "refId": "VictoriaLogsVariableQueryEditor-VariableQuery", + "type": "fieldName" + }, + "refresh": 2, + "regex": "/^[a-zA-Z].+/", + "skipUrlSync": false, + "sort": 1, + "type": "query" + }, + { + "current": { + "selected": false, + "text": "", + "value": "" + }, + "hide": 0, + "name": "query", + "options": [ + { + "selected": true, + "text": "", + "value": "" + } + ], + "query": "", + "skipUrlSync": false, + "type": "textbox" + } + ] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "VictoriaLogs Explorer (Docker)", + "uid": "victorialogs-docker", + "version": 1, + "weekStart": "" +} +