diff --git a/soc/docker-compose.yml b/soc/docker-compose.yml index c975ddf..318f1ea 100644 --- a/soc/docker-compose.yml +++ b/soc/docker-compose.yml @@ -8,9 +8,15 @@ services: volumes: - "/home/deploy/stack/soc/grafana-data:/var/lib/grafana" - "/home/deploy/stack/soc/grafana/provisioning:/etc/grafana/provisioning" - - "/opt/soc/grafana/dashboards:/var/lib/grafana/dashboards" + - "/home/deploy/stack/soc/grafana/dashboards:/var/lib/grafana/dashboards" environment: - GF_SECURITY_ADMIN_PASSWORD=wMjFvkQ3GRWCvJbd + - GF_SERVER_ROOT_URL=https://grafana.clube67.com + - GF_SERVER_SERVE_FROM_SUB_PATH=false + - GF_SECURITY_ALLOW_EMBEDDING=true + networks: + - soc + - web loki: image: grafana/loki:2.9.0 user: "0:0" @@ -56,3 +62,5 @@ services: networks: soc: external: true + web: + external: true diff --git a/soc/grafana/dashboards/soc.json b/soc/grafana/dashboards/soc.json new file mode 100644 index 0000000..ac1167a --- /dev/null +++ b/soc/grafana/dashboards/soc.json @@ -0,0 +1,495 @@ +{ + "__inputs": [], + "__elements": {}, + "__requires": [], + "annotations": { "list": [] }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 1, + "id": null, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 }, + "id": 100, + "title": "🖥️ SISTEMA — Métricas de Recursos", + "type": "row" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "thresholds" }, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { "color": "green", "value": null }, + { "color": "yellow", "value": 60 }, + { "color": "red", "value": 85 } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { "h": 6, "w": 6, "x": 0, "y": 1 }, + "id": 1, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "sizing": "auto", + "text": {} + }, + "pluginVersion": "12.4.1", + "targets": [ + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "100 - (avg(rate(node_cpu_seconds_total{mode=\"idle\"}[2m])) * 100)", + "instant": false, + "legendFormat": "CPU Total", + "refId": "A" + } + ], + "title": "🔥 CPU Usage", + "type": "gauge" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "thresholds" }, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { "color": "green", "value": null }, + { "color": "yellow", "value": 70 }, + { "color": "red", "value": 90 } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { "h": 6, "w": 6, "x": 6, "y": 1 }, + "id": 2, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "sizing": "auto", + "text": {} + }, + "pluginVersion": "12.4.1", + "targets": [ + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "100 - ((node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100)", + "legendFormat": "RAM Usada", + "refId": "A" + } + ], + "title": "🧠 RAM Usage", + "type": "gauge" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "thresholds" }, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { "color": "green", "value": null }, + { "color": "yellow", "value": 75 }, + { "color": "red", "value": 90 } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { "h": 6, "w": 6, "x": 12, "y": 1 }, + "id": 3, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "sizing": "auto", + "text": {} + }, + "pluginVersion": "12.4.1", + "targets": [ + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "100 - ((node_filesystem_avail_bytes{mountpoint=\"/\",fstype!=\"tmpfs\"} / node_filesystem_size_bytes{mountpoint=\"/\",fstype!=\"tmpfs\"}) * 100)", + "legendFormat": "Disco /", + "refId": "A" + } + ], + "title": "💾 Disco Usage", + "type": "gauge" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "thresholds" }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { "color": "green", "value": null }, + { "color": "yellow", "value": 50 }, + { "color": "red", "value": 150 } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { "h": 6, "w": 6, "x": 18, "y": 1 }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "area", + "justifyMode": "center", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "12.4.1", + "targets": [ + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "node_load1", + "legendFormat": "Load 1m", + "refId": "A" + } + ], + "title": "⚖️ Load Average (1m)", + "type": "stat" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "palette-classic" }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "opacity", + "hideFrom": { "legend": false, "tooltip": false, "viz": false }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "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": "Bps" + }, + "overrides": [] + }, + "gridPos": { "h": 7, "w": 12, "x": 0, "y": 7 }, + "id": 5, + "options": { + "legend": { "calcs": ["mean", "max"], "displayMode": "list", "placement": "bottom", "showLegend": true }, + "tooltip": { "hideZeros": false, "mode": "multi", "sort": "none" } + }, + "targets": [ + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "rate(node_network_receive_bytes_total{device=\"eth0\"}[2m])", + "legendFormat": "⬇ Entrada (eth0)", + "refId": "A" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "rate(node_network_transmit_bytes_total{device=\"eth0\"}[2m])", + "legendFormat": "⬆ Saída (eth0)", + "refId": "B" + } + ], + "title": "🌐 Tráfego de Rede (eth0)", + "type": "timeseries" + }, + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "palette-classic" }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "opacity", + "hideFrom": { "legend": false, "tooltip": false, "viz": false }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "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": "percent" + }, + "overrides": [] + }, + "gridPos": { "h": 7, "w": 12, "x": 12, "y": 7 }, + "id": 6, + "options": { + "legend": { "calcs": ["mean", "max"], "displayMode": "list", "placement": "bottom", "showLegend": true }, + "tooltip": { "hideZeros": false, "mode": "multi", "sort": "none" } + }, + "targets": [ + { + "datasource": { "type": "prometheus", "uid": "Prometheus" }, + "expr": "100 - (avg by (cpu) (rate(node_cpu_seconds_total{mode=\"idle\"}[2m])) * 100)", + "legendFormat": "CPU {{cpu}}", + "refId": "A" + } + ], + "title": "📊 CPU por Core (%)", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { "h": 1, "w": 24, "x": 0, "y": 14 }, + "id": 101, + "title": "🛡️ SEGURANÇA — Logs e Eventos", + "type": "row" + }, + { + "datasource": { "type": "loki", "uid": "Loki" }, + "fieldConfig": { "defaults": {}, "overrides": [] }, + "gridPos": { "h": 8, "w": 24, "x": 0, "y": 15 }, + "id": 7, + "options": { + "dedupStrategy": "none", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": true, + "showTime": true, + "sortOrder": "Descending", + "wrapLogMessage": true + }, + "targets": [ + { + "datasource": { "type": "loki", "uid": "Loki" }, + "expr": "{job=\"varlogs\"} |~ \"(?i)(error|fail|critical|warn|denied|refused|invalid|unauthorized)\"", + "legendFormat": "", + "refId": "A" + } + ], + "title": "⚠️ Eventos de Erro/Aviso nos Logs do Sistema", + "type": "logs" + }, + { + "datasource": { "type": "loki", "uid": "Loki" }, + "fieldConfig": { "defaults": {}, "overrides": [] }, + "gridPos": { "h": 8, "w": 24, "x": 0, "y": 23 }, + "id": 8, + "options": { + "dedupStrategy": "none", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": true, + "showTime": true, + "sortOrder": "Descending", + "wrapLogMessage": true + }, + "targets": [ + { + "datasource": { "type": "loki", "uid": "Loki" }, + "expr": "{job=\"falco\"}", + "legendFormat": "", + "refId": "A" + } + ], + "title": "🦅 Falco — Eventos de Segurança do Kernel", + "type": "logs" + }, + { + "collapsed": false, + "gridPos": { "h": 1, "w": 24, "x": 0, "y": 31 }, + "id": 102, + "title": "🐳 DOCKER — Containers e Self-Healing", + "type": "row" + }, + { + "datasource": { "type": "loki", "uid": "Loki" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "palette-classic" }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "eventos/min", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "bars", + "fillOpacity": 80, + "gradientMode": "none", + "hideFrom": { "legend": false, "tooltip": false, "viz": false }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { "type": "linear" }, + "showPoints": "never", + "spanNulls": false, + "stacking": { "group": "A", "mode": "none" }, + "thresholdsStyle": { "mode": "line+area" } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { "color": "transparent", "value": null }, + { "color": "red", "value": 1 } + ] + } + }, + "overrides": [] + }, + "gridPos": { "h": 7, "w": 12, "x": 0, "y": 32 }, + "id": 9, + "options": { + "legend": { "calcs": ["sum"], "displayMode": "list", "placement": "bottom", "showLegend": true }, + "tooltip": { "hideZeros": true, "mode": "single", "sort": "none" } + }, + "targets": [ + { + "datasource": { "type": "loki", "uid": "Loki" }, + "expr": "sum(count_over_time({job=\"varlogs\"} |~ \"(?i)(error|exception|fatal|fail)\" [1m]))", + "legendFormat": "Erros/min", + "refId": "A" + } + ], + "title": "🔴 Taxa de Erros — Logs do Sistema (por minuto)", + "type": "timeseries" + }, + { + "datasource": { "type": "loki", "uid": "Loki" }, + "fieldConfig": { + "defaults": { + "color": { "mode": "palette-classic" }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "alertas/min", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "bars", + "fillOpacity": 80, + "gradientMode": "none", + "hideFrom": { "legend": false, "tooltip": false, "viz": false }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { "type": "linear" }, + "showPoints": "never", + "spanNulls": false, + "stacking": { "group": "A", "mode": "none" }, + "thresholdsStyle": { "mode": "line+area" } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { "color": "transparent", "value": null }, + { "color": "orange", "value": 1 } + ] + } + }, + "overrides": [] + }, + "gridPos": { "h": 7, "w": 12, "x": 12, "y": 32 }, + "id": 10, + "options": { + "legend": { "calcs": ["sum"], "displayMode": "list", "placement": "bottom", "showLegend": true }, + "tooltip": { "hideZeros": true, "mode": "single", "sort": "none" } + }, + "targets": [ + { + "datasource": { "type": "loki", "uid": "Loki" }, + "expr": "sum(count_over_time({job=\"falco\"} [1m]))", + "legendFormat": "Alertas Falco/min", + "refId": "A" + } + ], + "title": "🦅 Taxa de Alertas Falco (por minuto)", + "type": "timeseries" + } + ], + "refresh": "30s", + "schemaVersion": 39, + "tags": ["soc", "security", "self-healing"], + "templating": { "list": [] }, + "time": { "from": "now-3h", "to": "now" }, + "timepicker": {}, + "timezone": "browser", + "title": "SOC Overview", + "uid": "soc-overview-v2", + "version": 2, + "weekStart": "" +} diff --git a/soc/grafana/provisioning/dashboards/provider.yml b/soc/grafana/provisioning/dashboards/provider.yml new file mode 100644 index 0000000..4c0e490 --- /dev/null +++ b/soc/grafana/provisioning/dashboards/provider.yml @@ -0,0 +1,8 @@ +apiVersion: 1 +providers: + - name: SOC + orgId: 1 + folder: "" + type: file + options: + path: /var/lib/grafana/dashboards diff --git a/traefik/dynamic/grafana.yml b/traefik/dynamic/grafana.yml new file mode 100644 index 0000000..67f9528 --- /dev/null +++ b/traefik/dynamic/grafana.yml @@ -0,0 +1,14 @@ +http: + routers: + grafana-router: + rule: "Host(`grafana.clube67.com`)" + service: grafana-service + entryPoints: + - websecure + tls: + certResolver: le + services: + grafana-service: + loadBalancer: + servers: + - url: "http://soc-grafana-1:3000"