diff options
| author | Valentin <valentin@fricklerhandwerk.de> | 2025-11-12 22:11:01 +0100 |
|---|---|---|
| committer | Valentin <valentin@fricklerhandwerk.de> | 2025-11-20 16:36:45 +0100 |
| commit | 14cfede293410bcf60bb096a410257fce2d20886 (patch) | |
| tree | 40113f9776a10e99d38acf39f0e9a8924795dcdd | |
| parent | edd5c01698f321f530a8656d3678e39a3a1e98c2 (diff) | |
Überwachung der Systemlast
| -rw-r--r-- | tharos/dashboards/system.json | 195 | ||||
| -rw-r--r-- | tharos/grafana.nix | 20 | ||||
| -rw-r--r-- | tharos/prometheus.nix | 34 |
3 files changed, 249 insertions, 0 deletions
diff --git a/tharos/dashboards/system.json b/tharos/dashboards/system.json new file mode 100644 index 0000000..6b8ec35 --- /dev/null +++ b/tharos/dashboards/system.json @@ -0,0 +1,195 @@ +{ + "editable": true, + "id": 1, + "panels": [ + { + "id": 1, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "custom": { + "drawStyle": "bars" + }, + "unit": "decbytes" + } + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "options": { + "legend": { + "showLegend": false + } + }, + "pluginVersion": "12.0.5", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "editorMode": "code", + "expr": "node_memory_MemTotal_bytes", + "legendFormat": "Total", + "range": true, + "refId": "total" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes", + "refId": "used" + } + ], + "title": "Arbeitsspeicher", + "transformations": [ + { + "id": "configFromData", + "options": { + "applyTo": { + "id": "byName", + "options": "Value" + }, + "configRefId": "total", + "mappings": [ + { + "fieldName": "Total", + "handlerKey": "max" + } + ] + } + } + ] + }, + { + "id": 2, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "custom": { + "drawStyle": "bars", + "stacking": { + "group": "A", + "mode": "normal" + } + }, + "max": 1, + "unit": "percentunit" + } + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "options": { + "legend": { + "showLegend": true + } + }, + "pluginVersion": "12.0.5", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "sum by(mode) (rate(node_cpu_seconds_total{mode!~\"idle\"}[$__rate_interval])) / scalar(count(count by(cpu) (node_cpu_seconds_total)))", + "legendFormat": "{{mode}}" + } + ], + "title": "Prozessorlast" + }, + { + "id": 3, + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "custom": { + "drawStyle": "bars", + "stacking": { + "group": "A", + "mode": "normal" + } + }, + "max": 1, + "unit": "percentunit" + } + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 8 + }, + "options": { + "legend": { + "showLegend": true + } + }, + "pluginVersion": "12.0.5", + "repeat": "CPU", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "expr": "rate(node_cpu_seconds_total{cpu=\"$CPU\", mode!=\"idle\"}[$__rate_interval])", + "legendFormat": "{{mode}}", + "range": true, + "refId": "A" + } + ], + "title": "Prozessor $CPU", + "type": "timeseries" + } + ], + "refresh": "10s", + "schemaVersion": 41, + "templating": { + "list": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "allowCustomValue": false, + "definition": "label_values(node_cpu_seconds_total,cpu)", + "includeAll": true, + "name": "CPU", + "query": { + "qryType": 1, + "query": "label_values(node_cpu_seconds_total,cpu)", + "refId": "PrometheusVariableQueryEditor-VariableQuery" + }, + "refresh": 2, + "type": "query" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timezone": "browser", + "title": "System", + "uid": "d6a74067-e6b9-4460-8119-d205c606ef68", + "version": 1 +} diff --git a/tharos/grafana.nix b/tharos/grafana.nix index fa2259e..9ad5ecc 100644 --- a/tharos/grafana.nix +++ b/tharos/grafana.nix @@ -36,6 +36,23 @@ org_role = "Viewer"; }; }; + provision = { + enable = true; + datasources.settings = { + prune = true; + datasources = [ + { + name = "Prometheus"; + type = "prometheus"; + access = "proxy"; + url = "http://localhost:${toString config.services.prometheus.port}"; + } + ]; + }; + dashboards.settings.providers = [ + { options.path = ./dashboards; } + ]; + }; }; services.postgresql = { enable = true; @@ -68,6 +85,9 @@ domain = lib.mkForce "grafana.localhost"; root_url = lib.mkForce "http://${grafana.domain}:${toString grafana.port}"; }; + settings."auth.anonymous" = { + org_role = lib.mkForce "Admin"; + }; }; services.caddy.virtualHosts = { diff --git a/tharos/prometheus.nix b/tharos/prometheus.nix new file mode 100644 index 0000000..48d7a85 --- /dev/null +++ b/tharos/prometheus.nix @@ -0,0 +1,34 @@ +{ self, lib, ... }: +{ + flake.machines.tharos = { + nixos = + { config, ... }: + { + services.prometheus = { + enable = true; + exporters.node = { + enable = true; + openFirewall = true; + enabledCollectors = [ ]; + }; + globalConfig.scrape_interval = "10s"; + scrapeConfigs = [ + { + job_name = "node"; + static_configs = [ + { + targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; + } + ]; + } + ]; + }; + }; + + vm = + { ... }: + { + services.prometheus.globalConfig.scrape_interval = lib.mkForce "5s"; + }; + }; +} |
