From db0d8e7552412145d694d582fbe917fed2f12c95 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Thu, 30 Oct 2025 18:37:41 -0400 Subject: [PATCH] add status --- clients/quadraticserver/stats/grafana.nix | 35 +---- lib/status.nix | 175 ++++++++++++---------- 2 files changed, 104 insertions(+), 106 deletions(-) diff --git a/clients/quadraticserver/stats/grafana.nix b/clients/quadraticserver/stats/grafana.nix index 1dca310..a695c49 100644 --- a/clients/quadraticserver/stats/grafana.nix +++ b/clients/quadraticserver/stats/grafana.nix @@ -20,9 +20,6 @@ in enable = true; declarativePlugins = [ ]; settings = { - "auth.anonymous".enabled = true; - analytics.feedback_links_enabled = false; - users.default_theme = "system"; server = { inherit domain; root_url = "https://${domain}"; @@ -37,34 +34,10 @@ in admin_password = "$__file{${credentialDirectory}${passwordName}}"; }; - dashboards.default_home_dashboard_path = toString ( - (import ../../../lib/status.nix attrs) [ - { - name = "Matrix"; - service = "continuwuity.service"; - } - { - name = "LaSuite Docs"; - service = "lasuite-docs.service"; - } - { - name = "Forgejo (Git)"; - service = "forgejo.service"; - } - { - name = "SearXNG (Search)"; - service = "searx.service"; - } - { - name = "Redlib"; - service = "redlib.service"; - } - { - name = "GMessages Bridge"; - service = "matrix-as-gmessages.service"; - } - ] - ); + "auth.anonymous".enabled = true; + analytics.feedback_links_enabled = false; + users.default_theme = "system"; + dashboards.default_home_dashboard_path = toString (import ../../../lib/status.nix attrs); }; provision = { diff --git a/lib/status.nix b/lib/status.nix index 7889b48..86a5b2e 100644 --- a/lib/status.nix +++ b/lib/status.nix @@ -1,83 +1,108 @@ { pkgs, lib, ... }: -services: - -# { -# "collapsed": false, -# "gridPos": { -# "h": 1, -# "w": 24, -# "x": 0, -# "y": 0 -# }, -# "id": 261, -# "panels": [], -# "title": "Quick CPU / Mem / Disk", -# "type": "row" -# }, pkgs.writers.writeJSON "status.json" { title = "Service Status"; - panels = [ - { - collapsed = false; - title = "Federated Nexus Service Statuses"; - type = "row"; - gridPos = { - h = 1; - w = 24; - x = 0; - y = 0; - }; - } - ] - ++ (lib.imap0 ( - index: - { name, service }: - { - title = name; - type = "stat"; - gridPos = rec { - h = 3; - w = 4; - x = index * w; - y = (index * h) + 8; - }; - datasource = { - type = "prometheus"; - uid = "prometheus"; - }; - fieldConfig = { - defaults = { - color.mode = "thresholds"; - mappings = [ - { - options = { - "0".text = "Failed"; - "1".text = "Running"; + panels = + let + status = null; + offset = if status == null then 8 else 0; + in + (lib.optionals (status != null) [ + { + gridPos.w = 100; + title = "Status Update"; + type = "text"; + options.content = status; + } + ]) + ++ [ + { + collapsed = false; + title = "Federated Nexus Service Statuses"; + type = "row"; + gridPos = { + h = 8; + w = 24; + y = offset; + }; + } + ] + ++ (lib.imap0 + ( + index: + { name, service }: + { + title = name; + type = "stat"; + gridPos = rec { + h = 3; + w = 4; + x = index * w; + y = (index * h) + offset + 8; + }; + datasource = { + type = "prometheus"; + uid = "prometheus"; + }; + fieldConfig = { + defaults = { + color.mode = "thresholds"; + mappings = [ + { + options = { + "0".text = "Failed"; + "1".text = "Running"; + }; + type = "value"; + } + ]; + thresholds = { + mode = "absolute"; + steps = [ + { + color = "red"; + value = 0; + } + { + color = "green"; + value = 1; + } + ]; }; - type = "value"; + unit = "none"; + }; + }; + targets = [ + { + expr = "node_systemd_unit_state{name=\"${service}\",state=\"active\"}"; } ]; - thresholds = { - mode = "absolute"; - steps = [ - { - color = "red"; - value = 0; - } - { - color = "green"; - value = 1; - } - ]; - }; - unit = "none"; - }; - }; - targets = [ - { - expr = "node_systemd_unit_state{name=\"${service}\",state=\"active\"}"; } - ]; - } - ) services); + ) + [ + { + name = "Matrix"; + service = "continuwuity.service"; + } + { + name = "LaSuite Docs"; + service = "lasuite-docs.service"; + } + { + name = "Forgejo (Git)"; + service = "forgejo.service"; + } + { + name = "SearXNG (Search)"; + service = "searx.service"; + } + { + name = "Redlib"; + service = "redlib.service"; + } + { + name = "GMessages Bridge"; + service = "matrix-as-gmessages.service"; + } + ] + ); }