updated monitoring stack for k3s and added kube dashboards

This commit is contained in:
rezayaghobi-dev
2026-08-16 22:26:40 +03:30
parent 4acb8b5ac1
commit d5bc686665
10 changed files with 8131 additions and 43 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,574 @@
{
"apiVersion": "dashboard.grafana.app/v2",
"kind": "Dashboard",
"metadata": {
"name": "k3s-unified-custom",
"namespace": "default",
"uid": "bdd5aead-f832-414c-ae5a-d78512b329bc",
"resourceVersion": "1786873984999019",
"generation": 1,
"creationTimestamp": "2026-08-16T09:53:04Z",
"labels": {
"grafana.app/deprecatedInternalID": "3760385721421824"
},
"annotations": {
"grafana.app/createdBy": "user:dfbtp4cn32dj4f",
"grafana.app/folder": "",
"grafana.app/saved-from-ui": "Grafana v13.1.1 (a9cee6e172)"
}
},
"spec": {
"annotations": [
{
"kind": "AnnotationQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "grafana",
"version": "v0",
"datasource": {
"name": "-- Grafana --"
},
"spec": {}
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"builtIn": true,
"legacyOptions": {
"type": "dashboard"
}
}
}
],
"cursorSync": "Off",
"editable": true,
"elements": {
"panel-1": {
"kind": "Panel",
"spec": {
"id": 1,
"title": "Running Pods",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "${DS_PROMETHEUS}"
},
"spec": {
"expr": "sum(kube_pod_status_phase{namespace=~\"$namespace\", pod=~\"$pod\", phase=\"Running\"})"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "stat",
"version": "",
"spec": {
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "fixed",
"fixedColor": "green"
}
},
"overrides": []
}
}
}
}
},
"panel-2": {
"kind": "Panel",
"spec": {
"id": 2,
"title": "Problem Pods",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "${DS_PROMETHEUS}"
},
"spec": {
"expr": "sum(kube_pod_status_phase{namespace=~\"$namespace\", pod=~\"$pod\", phase=~\"Failed|Pending|Unknown\"})"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "stat",
"version": "",
"spec": {
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "fixed",
"fixedColor": "red"
}
},
"overrides": []
}
}
}
}
},
"panel-3": {
"kind": "Panel",
"spec": {
"id": 3,
"title": "Pod CPU Usage",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "${DS_PROMETHEUS}"
},
"spec": {
"expr": "sum by (pod) (rate(container_cpu_usage_seconds_total{namespace=~\"$namespace\", pod=~\"$pod\", image!=\"\"}[$__rate_interval]))",
"legendFormat": "{{pod}}"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "timeseries",
"version": "",
"spec": {
"options": {},
"fieldConfig": {
"defaults": {},
"overrides": []
}
}
}
}
},
"panel-4": {
"kind": "Panel",
"spec": {
"id": 4,
"title": "Pod Memory Usage",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "${DS_PROMETHEUS}"
},
"spec": {
"expr": "sum by (pod) (container_memory_working_set_bytes{namespace=~\"$namespace\", pod=~\"$pod\", image!=\"\"})",
"legendFormat": "{{pod}}"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "timeseries",
"version": "",
"spec": {
"options": {},
"fieldConfig": {
"defaults": {
"unit": "bytes"
},
"overrides": []
}
}
}
}
},
"panel-5": {
"kind": "Panel",
"spec": {
"id": 5,
"title": "Live Pod Logs",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"expr": "{cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\"} |~ \"$search\""
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "logs",
"version": "",
"spec": {
"options": {
"showLabels": true,
"showTime": true,
"wrapLogMessage": true
},
"fieldConfig": {
"defaults": {},
"overrides": []
}
}
}
}
}
},
"layout": {
"kind": "RowsLayout",
"spec": {
"rows": [
{
"kind": "RowsLayoutRow",
"spec": {
"title": "K3s Cluster Status (kube-state-metrics)",
"collapse": false,
"layout": {
"kind": "GridLayout",
"spec": {
"items": [
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 0,
"width": 12,
"height": 5,
"element": {
"kind": "ElementReference",
"name": "panel-1"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 12,
"y": 0,
"width": 12,
"height": 5,
"element": {
"kind": "ElementReference",
"name": "panel-2"
}
}
}
]
}
}
}
},
{
"kind": "RowsLayoutRow",
"spec": {
"title": "K3s Compute (cAdvisor)",
"collapse": false,
"layout": {
"kind": "GridLayout",
"spec": {
"items": [
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 0,
"width": 12,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-3"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 12,
"y": 0,
"width": 12,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-4"
}
}
}
]
}
}
}
},
{
"kind": "RowsLayoutRow",
"spec": {
"title": "K3s Logs (Loki + Alloy)",
"collapse": false,
"layout": {
"kind": "GridLayout",
"spec": {
"items": [
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 0,
"width": 24,
"height": 14,
"element": {
"kind": "ElementReference",
"name": "panel-5"
}
}
}
]
}
}
}
}
]
}
},
"links": [],
"liveNow": false,
"preload": false,
"tags": [],
"timeSettings": {
"from": "now-1h",
"to": "now",
"autoRefresh": "",
"autoRefreshIntervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"hideTimepicker": false,
"fiscalYearStartMonth": 0
},
"title": "K3s Unified Application Dashboard",
"variables": [
{
"kind": "DatasourceVariable",
"spec": {
"name": "DS_PROMETHEUS",
"pluginId": "prometheus",
"refresh": "never",
"regex": "",
"current": {
"text": "",
"value": ""
},
"options": [],
"multi": false,
"includeAll": false,
"label": "Prometheus Data Source",
"hide": "dontHide",
"skipUrlSync": false,
"allowCustomValue": true
}
},
{
"kind": "DatasourceVariable",
"spec": {
"name": "DS_LOKI",
"pluginId": "loki",
"refresh": "never",
"regex": "",
"current": {
"text": "",
"value": ""
},
"options": [],
"multi": false,
"includeAll": false,
"label": "Loki Data Source",
"hide": "dontHide",
"skipUrlSync": false,
"allowCustomValue": true
}
},
{
"kind": "QueryVariable",
"spec": {
"name": "namespace",
"current": {
"text": "",
"value": ""
},
"label": "Namespace",
"hide": "dontHide",
"refresh": "onDashboardLoad",
"skipUrlSync": false,
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "${DS_PROMETHEUS}"
},
"spec": {
"__legacyStringValue": "label_values(kube_pod_info, namespace)"
}
},
"regex": "",
"sort": "disabled",
"options": [],
"multi": true,
"includeAll": true,
"allValue": ".*",
"allowCustomValue": true
}
},
{
"kind": "QueryVariable",
"spec": {
"name": "pod",
"current": {
"text": "",
"value": ""
},
"label": "Pod",
"hide": "dontHide",
"refresh": "onDashboardLoad",
"skipUrlSync": false,
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "${DS_PROMETHEUS}"
},
"spec": {
"__legacyStringValue": "label_values(kube_pod_info{namespace=~\"$namespace\"}, pod)"
}
},
"regex": "",
"sort": "disabled",
"options": [],
"multi": true,
"includeAll": true,
"allValue": ".*",
"allowCustomValue": true
}
},
{
"kind": "TextVariable",
"spec": {
"name": "search",
"current": {
"text": "",
"value": ""
},
"query": "",
"label": "Log String Filter",
"hide": "dontHide",
"skipUrlSync": false
}
}
]
}
}

View File

@@ -0,0 +1,635 @@
{
"apiVersion": "dashboard.grafana.app/v2",
"kind": "Dashboard",
"metadata": {
"name": "k3s-pro-logs",
"namespace": "default",
"uid": "4b031c52-1c0a-4a18-8f0e-0c8f3e7e6011",
"resourceVersion": "1786876489507019",
"generation": 1,
"creationTimestamp": "2026-08-16T10:34:49Z",
"labels": {
"grafana.app/deprecatedInternalID": "3770890413830144"
},
"annotations": {
"grafana.app/createdBy": "user:dfbtp4cn32dj4f",
"grafana.app/folder": "",
"grafana.app/saved-from-ui": "Grafana v13.1.1 (a9cee6e172)"
}
},
"spec": {
"annotations": [
{
"kind": "AnnotationQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "grafana",
"version": "v0",
"datasource": {
"name": "-- Grafana --"
},
"spec": {}
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"builtIn": true,
"legacyOptions": {
"type": "dashboard"
}
}
}
],
"cursorSync": "Crosshair",
"editable": true,
"elements": {
"panel-1": {
"kind": "Panel",
"spec": {
"id": 1,
"title": "Critical Events Over Time",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"editorMode": "code",
"expr": "sum(count_over_time({cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\", container=~\"$container\"} !~ \"(?i)(No files matching import glob pattern|v1 Endpoints is deprecated)\" |~ \"(?i)(error|err|fatal|crit|fail|exception)\" [$__interval]))",
"legendFormat": "Errors",
"queryType": "range"
}
},
"refId": "A",
"hidden": false
}
},
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"editorMode": "code",
"expr": "sum(count_over_time({cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\", container=~\"$container\"} !~ \"(?i)(No files matching import glob pattern|v1 Endpoints is deprecated)\" |~ \"(?i)(warn|warning)\" [$__interval]))",
"legendFormat": "Warnings",
"queryType": "range"
}
},
"refId": "B",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "timeseries",
"version": "",
"spec": {
"options": {
"legend": {
"calcs": [
"sum"
],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": {
"mode": "absolute",
"steps": [
{
"value": null,
"color": "green"
},
{
"value": 80,
"color": "red"
}
]
},
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "bars",
"fillOpacity": 80,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "normal"
},
"thresholdsStyle": {
"mode": "off"
}
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "Errors"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "red",
"mode": "fixed"
}
}
]
},
{
"matcher": {
"id": "byName",
"options": "Warnings"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "orange",
"mode": "fixed"
}
}
]
}
]
}
}
}
}
},
"panel-2": {
"kind": "Panel",
"spec": {
"id": 2,
"title": "Top Error-Producing Pods",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"editorMode": "code",
"expr": "topk(5, sum by (pod) (count_over_time({cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\", container=~\"$container\"} !~ \"(?i)(No files matching import glob pattern|v1 Endpoints is deprecated)\" |~ \"(?i)(error|err|fatal|crit|fail|exception)\" [$__range])))",
"legendFormat": "{{pod}}",
"queryType": "range"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "bargauge",
"version": "10.4.0",
"spec": {
"options": {
"displayMode": "gradient",
"minVizHeight": 10,
"minVizWidth": 0,
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showUnfilled": true,
"text": {}
},
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": {
"mode": "absolute",
"steps": [
{
"value": null,
"color": "green"
},
{
"value": 1,
"color": "orange"
},
{
"value": 10,
"color": "red"
}
]
},
"color": {
"mode": "thresholds"
}
},
"overrides": []
}
}
}
}
},
"panel-3": {
"kind": "Panel",
"spec": {
"id": 3,
"title": "Live Pod Logs",
"description": "",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"editorMode": "code",
"expr": "{cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\", container=~\"$container\"} !~ \"(?i)(No files matching import glob pattern|v1 Endpoints is deprecated)\" |~ \"$log_severity\" |~ \"$search\"",
"queryType": "range"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "logs",
"version": "",
"spec": {
"options": {
"dedupStrategy": "exact",
"enableLogDetails": true,
"prettifyLogMessage": true,
"showCommonLabels": false,
"showLabels": true,
"showLogLabels": true,
"showTime": true,
"sortOrder": "Descending",
"wrapLogMessage": true
},
"fieldConfig": {
"defaults": {},
"overrides": []
}
}
}
}
}
},
"layout": {
"kind": "RowsLayout",
"spec": {
"rows": [
{
"kind": "RowsLayoutRow",
"spec": {
"title": "Log Severity & Anomaly Overview",
"collapse": false,
"layout": {
"kind": "GridLayout",
"spec": {
"items": [
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 0,
"width": 16,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-1"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 16,
"y": 0,
"width": 8,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-2"
}
}
}
]
}
}
}
},
{
"kind": "RowsLayoutRow",
"spec": {
"title": "Filtered Container Log Stream",
"collapse": false,
"layout": {
"kind": "GridLayout",
"spec": {
"items": [
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 0,
"width": 24,
"height": 18,
"element": {
"kind": "ElementReference",
"name": "panel-3"
}
}
}
]
}
}
}
}
]
}
},
"links": [],
"liveNow": false,
"preload": false,
"tags": [
"k3s",
"loki",
"logs",
"alloy"
],
"timeSettings": {
"timezone": "browser",
"from": "now-1h",
"to": "now",
"autoRefresh": "5s",
"autoRefreshIntervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"hideTimepicker": false,
"fiscalYearStartMonth": 0
},
"title": "K3s Professional Log Analyzer",
"variables": [
{
"kind": "DatasourceVariable",
"spec": {
"name": "DS_LOKI",
"pluginId": "loki",
"refresh": "onDashboardLoad",
"regex": "",
"current": {
"text": "Loki",
"value": "Loki"
},
"options": [],
"multi": false,
"includeAll": false,
"label": "Loki Data Source",
"hide": "dontHide",
"skipUrlSync": false,
"allowCustomValue": true
}
},
{
"kind": "QueryVariable",
"spec": {
"name": "namespace",
"current": {
"text": "All",
"value": "$__all"
},
"label": "Namespace",
"hide": "dontHide",
"refresh": "onDashboardLoad",
"skipUrlSync": false,
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"__legacyStringValue": "label_values({cluster=\"k3s-homeserver\"}, namespace)"
}
},
"regex": "",
"sort": "alphabeticalAsc",
"definition": "label_values({cluster=\"k3s-homeserver\"}, namespace)",
"options": [],
"multi": true,
"includeAll": true,
"allValue": ".*",
"allowCustomValue": true
}
},
{
"kind": "QueryVariable",
"spec": {
"name": "pod",
"current": {
"text": "All",
"value": "$__all"
},
"label": "Pod",
"hide": "dontHide",
"refresh": "onDashboardLoad",
"skipUrlSync": false,
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"__legacyStringValue": "label_values({cluster=\"k3s-homeserver\", namespace=~\"$namespace\"}, pod)"
}
},
"regex": "",
"sort": "alphabeticalAsc",
"definition": "label_values({cluster=\"k3s-homeserver\", namespace=~\"$namespace\"}, pod)",
"options": [],
"multi": true,
"includeAll": true,
"allValue": ".*",
"allowCustomValue": true
}
},
{
"kind": "QueryVariable",
"spec": {
"name": "container",
"current": {
"text": "All",
"value": "$__all"
},
"label": "Container",
"hide": "dontHide",
"refresh": "onDashboardLoad",
"skipUrlSync": false,
"query": {
"kind": "DataQuery",
"group": "loki",
"version": "v0",
"datasource": {
"name": "${DS_LOKI}"
},
"spec": {
"__legacyStringValue": "label_values({cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\"}, container)"
}
},
"regex": "",
"sort": "alphabeticalAsc",
"definition": "label_values({cluster=\"k3s-homeserver\", namespace=~\"$namespace\", pod=~\"$pod\"}, container)",
"options": [],
"multi": true,
"includeAll": true,
"allValue": ".*",
"allowCustomValue": true
}
},
{
"kind": "CustomVariable",
"spec": {
"name": "log_severity",
"query": "Warnings & Errors Only : (?i)(warn|warning|error|err|fatal|crit|fail|exception), Errors Only : (?i)(error|err|fatal|crit|fail|exception), All Logs (Including Info & Debug) : .*",
"current": {
"text": "Warnings & Errors Only",
"value": "(?i)(warn|warning|error|err|fatal|crit|fail|exception)"
},
"options": [
{
"selected": true,
"text": "Warnings & Errors Only",
"value": "(?i)(warn|warning|error|err|fatal|crit|fail|exception)"
},
{
"selected": false,
"text": "Errors Only",
"value": "(?i)(error|err|fatal|crit|fail|exception)"
},
{
"selected": false,
"text": "All Logs (Including Info & Debug)",
"value": ".*"
}
],
"multi": false,
"includeAll": false,
"label": "Log Severity Level",
"hide": "dontHide",
"skipUrlSync": false,
"allowCustomValue": true
}
},
{
"kind": "TextVariable",
"spec": {
"name": "search",
"current": {
"text": "",
"value": ""
},
"query": "",
"label": "Line Search Text",
"hide": "dontHide",
"skipUrlSync": false
}
}
]
}
}

View File

@@ -0,0 +1,84 @@
// Discover all running Docker containers
discovery.docker "containers" {
host = "unix:///var/run/docker.sock"
}
// Extract a clean "container" label from the container name
discovery.relabel "containers" {
targets = discovery.docker.containers.targets
rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container_name"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
// Tail logs from every discovered container
loki.source.docker "containers" {
host = "unix:///var/run/docker.sock"
targets = discovery.relabel.containers.output
forward_to = [loki.write.default.receiver]
}
// Ship to the local Loki instance
loki.write "default" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
}
// Discover K3s pods via the Kubernetes API
discovery.kubernetes "k3s_pods" {
role = "pod"
api_server = "https://192.168.100.6:6443"
bearer_token_file = "/etc/alloy/k3s-token"
tls_config {
insecure_skip_verify = true
}
}
// Label pod logs with namespace/pod/container for clean Grafana filtering
discovery.relabel "k3s_pods" {
targets = discovery.kubernetes.k3s_pods.targets
rule {
source_labels = ["__meta_kubernetes_namespace"]
target_label = "namespace"
}
rule {
source_labels = ["__meta_kubernetes_pod_name"]
target_label = "pod"
}
rule {
source_labels = ["__meta_kubernetes_pod_container_name"]
target_label = "container"
}
rule {
target_label = "cluster"
replacement = "k3s-homeserver"
}
}
// Tail logs from every discovered K3s pod
loki.source.kubernetes "k3s_pods" {
targets = discovery.relabel.k3s_pods.output
forward_to = [loki.write.default.receiver]
client {
api_server = "https://192.168.100.6:6443"
bearer_token_file = "/etc/alloy/k3s-token"
tls_config {
insecure_skip_verify = true
}
}
}

View File

@@ -1,40 +0,0 @@
// Discover all running Docker containers
discovery.docker "containers" {
host = "unix:///var/run/docker.sock"
}
// Extract a clean "container" label from the container name
discovery.relabel "containers" {
targets = discovery.docker.containers.targets
rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container_name"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
// Tail logs from every discovered container
loki.source.docker "containers" {
host = "unix:///var/run/docker.sock"
targets = discovery.relabel.containers.output
forward_to = [loki.write.default.receiver]
}
// Ship to the local Loki instance
loki.write "default" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
}

View File

@@ -5,15 +5,13 @@ services:
restart: unless-stopped
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus:ro
- ./data/prometheus:/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.enable-lifecycle"
networks:
- monitoring
@@ -64,6 +62,7 @@ services:
ports:
- "3100:3100"
volumes:
- ./loki/local-config.yaml:/etc/loki/local-config.yaml:ro
- ./data/loki:/loki
mem_limit: 400m
cpus: 1
@@ -83,6 +82,7 @@ services:
- "12345:12345"
volumes:
- ./alloy/config.alloy:/etc/alloy/config.alloy:ro
- ./alloy/k3s-token:/etc/alloy/k3s-token:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/alloy:/var/lib/alloy/data
mem_limit: 300m

View File

@@ -0,0 +1,44 @@
auth_enabled: false
server:
http_listen_port: 3100
common:
instance_addr: 127.0.0.1
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://localhost:9093
limits_config:
reject_old_samples: false
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
# reporting_enabled: false

View File

@@ -21,3 +21,16 @@ scrape_configs:
- job_name: 'gitlab-runner'
static_configs:
- targets: ['192.168.100.6:9252'] # Or your runner container name/IP
- job_name: 'kube-state-metrics'
static_configs:
- targets: ['192.168.100.6:30900']
- job_name: 'k3s-kubelet-cadvisor'
scheme: https
metrics_path: /metrics/cadvisor
tls_config:
insecure_skip_verify: true
bearer_token_file: /etc/prometheus/k3s-token
static_configs:
- targets: ['192.168.100.6:10250']