feat: add CrowdSec metrics and dashboard integration

This commit is contained in:
2026-07-20 03:56:57 +08:00
parent d71d95161a
commit c07e21be51
4 changed files with 659 additions and 0 deletions
+1
View File
@@ -262,6 +262,7 @@ setup-grafana:
cmp -s ./swarm/grafana/provisioning/datasources/prometheus.yml /var/data/grafana/provisioning/datasources/prometheus.yml 2>/dev/null || cp ./swarm/grafana/provisioning/datasources/prometheus.yml /var/data/grafana/provisioning/datasources/prometheus.yml ;\
cmp -s ./swarm/grafana/provisioning/dashboards/default.yml /var/data/grafana/provisioning/dashboards/default.yml 2>/dev/null || cp ./swarm/grafana/provisioning/dashboards/default.yml /var/data/grafana/provisioning/dashboards/default.yml ;\
cmp -s ./swarm/grafana/dashboards/prometheus-overview.json /var/data/grafana/dashboards/prometheus-overview.json 2>/dev/null || cp ./swarm/grafana/dashboards/prometheus-overview.json /var/data/grafana/dashboards/prometheus-overview.json ;\
cmp -s ./swarm/grafana/dashboards/crowdsec-overview.json /var/data/grafana/dashboards/crowdsec-overview.json 2>/dev/null || cp ./swarm/grafana/dashboards/crowdsec-overview.json /var/data/grafana/dashboards/crowdsec-overview.json ;\
cmp -s ./swarm/grafana/dashboards/traefik-overview.json /var/data/grafana/dashboards/traefik-overview.json 2>/dev/null || cp ./swarm/grafana/dashboards/traefik-overview.json /var/data/grafana/dashboards/traefik-overview.json ;\
}
deploy-grafana: pull setup-grafana
+3
View File
@@ -3,10 +3,13 @@ services:
image: crowdsecurity/crowdsec:slim
networks:
- crowdsec-internal
- traefik-public
environment:
DOCKER_HOST: tcp://tasks.socket-proxy:2375
COLLECTIONS: "crowdsecurity/traefik"
CUSTOM_CS_LAPI_KEY: ${CROWDSEC_LAPI_KEY:?Variable not set}
METRICS_PORT: "6060"
METRICS_LEVEL: "full"
# Optional CrowdSec Console enrollment (https://app.crowdsec.net)
ENROLL_KEY: ${CROWDSEC_ENROLL_KEY:-}
ENROLL_INSTANCE_NAME: ${CROWDSEC_ENROLL_INSTANCE_NAME:-}
@@ -0,0 +1,647 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": null,
"links": [],
"panels": [
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [
{
"options": {
"0": {
"index": 0,
"text": "Down"
},
"1": {
"index": 1,
"text": "Up"
}
},
"type": "value"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "green",
"value": 1
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 6,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"colorMode": "background",
"graphMode": "none",
"justifyMode": "center",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "max(up{job=\"crowdsec\"})",
"legendFormat": "crowdsec",
"range": true,
"refId": "A"
}
],
"title": "CrowdSec Up",
"type": "stat"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 6,
"x": 6,
"y": 0
},
"id": 2,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum(cs_active_decisions)",
"legendFormat": "active",
"range": true,
"refId": "A"
}
],
"title": "Active Decisions",
"type": "stat"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 6,
"x": 12,
"y": 0
},
"id": 3,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum(cs_alerts)",
"legendFormat": "alerts",
"range": true,
"refId": "A"
}
],
"title": "Current Alerts",
"type": "stat"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 6,
"x": 18,
"y": 0
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum(rate(cs_lapi_route_requests_total[5m]))",
"legendFormat": "requests/s",
"range": true,
"refId": "A"
}
],
"title": "LAPI Requests",
"type": "stat"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 4,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 0,
"y": 8
},
"id": 5,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum by (bouncer) (rate(cs_lapi_bouncer_requests_total[5m]))",
"legendFormat": "{{bouncer}}",
"range": true,
"refId": "A"
}
],
"title": "Bouncer Requests",
"type": "timeseries"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 4,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 12,
"y": 8
},
"id": 6,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum by (machine) (rate(cs_lapi_machine_requests_total[5m]))",
"legendFormat": "{{machine}}",
"range": true,
"refId": "A"
}
],
"title": "Machine Requests",
"type": "timeseries"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 4,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 0,
"y": 17
},
"id": 7,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum by (route, method) (rate(cs_lapi_route_requests_total[5m]))",
"legendFormat": "{{method}} {{route}}",
"range": true,
"refId": "A"
}
],
"title": "LAPI Route Traffic",
"type": "timeseries"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 4,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 12,
"y": 17
},
"id": 8,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "12.0.2",
"targets": [
{
"editorMode": "code",
"expr": "sum by (bouncer) (rate(cs_lapi_decisions_ok_total[5m]))",
"legendFormat": "{{bouncer}} decisions ok",
"range": true,
"refId": "A"
},
{
"editorMode": "code",
"expr": "sum by (bouncer) (rate(cs_lapi_decisions_ko_total[5m]))",
"legendFormat": "{{bouncer}} decisions empty",
"range": true,
"refId": "B"
}
],
"title": "Decision Stream Responses",
"type": "timeseries"
}
],
"refresh": "30s",
"schemaVersion": 41,
"style": "dark",
"tags": [
"crowdsec",
"security",
"provisioned"
],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "CrowdSec Overview",
"uid": "crowdsec-overview",
"version": 1,
"weekStart": ""
}
+8
View File
@@ -17,3 +17,11 @@ scrape_configs:
- job_name: 'traefik'
static_configs:
- targets: ['192.168.50.220:8082']
# Scrape CrowdSec metrics.
# CrowdSec joins the traefik-public network in swarm/crowdsec.yml.
# Use task DNS with the fully qualified Swarm service name.
- job_name: 'crowdsec'
metrics_path: /metrics
static_configs:
- targets: ['tasks.crowdsec_crowdsec:6060']