From 50df86e20c4495657551ea40340962513db238a8 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 23 Jun 2025 17:13:30 +0200 Subject: [PATCH] os/mixin/radicle-stats: Collect `rad stats` A systemd timer unit that will just take the output of `rad stats` and timestamp it. --- os/host/iris/radicle.nix | 1 + os/host/rosa/radicle.nix | 1 + os/host/seed/radicle.nix | 5 ++++- os/mixin/radicle-stats.nix | 40 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 os/mixin/radicle-stats.nix diff --git a/os/host/iris/radicle.nix b/os/host/iris/radicle.nix index 2421019..ca697ff 100644 --- a/os/host/iris/radicle.nix +++ b/os/host/iris/radicle.nix @@ -8,6 +8,7 @@ in { imports = [ ../../mixin/radicle.nix ../../mixin/radicle-permissive.nix + ../../mixin/radicle-stats.nix ]; fileSystems."/var/lib/radicle" = { diff --git a/os/host/rosa/radicle.nix b/os/host/rosa/radicle.nix index 25861b4..518d0ce 100644 --- a/os/host/rosa/radicle.nix +++ b/os/host/rosa/radicle.nix @@ -8,6 +8,7 @@ in { imports = [ ../../mixin/radicle.nix ../../mixin/radicle-permissive.nix + ../../mixin/radicle-stats.nix ]; fileSystems."/var/lib/radicle" = { diff --git a/os/host/seed/radicle.nix b/os/host/seed/radicle.nix index 3b8ccd5..a23b90f 100644 --- a/os/host/seed/radicle.nix +++ b/os/host/seed/radicle.nix @@ -3,7 +3,10 @@ pkgs, ... }: { - imports = [../../mixin/radicle.nix]; + imports = [ + ../../mixin/radicle.nix + ../../mixin/radicle-stats.nix + ]; fileSystems."/var/lib/radicle" = { device = "/dev/disk/by-id/scsi-0HC_Volume_30473554"; diff --git a/os/mixin/radicle-stats.nix b/os/mixin/radicle-stats.nix new file mode 100644 index 0000000..c1211fa --- /dev/null +++ b/os/mixin/radicle-stats.nix @@ -0,0 +1,40 @@ +{ + config, + pkgs, + lib, + ... +}: let + name = "radicle-stats"; +in { + systemd = { + timers.${name} = { + wantedBy = ["timers.target"]; + timerConfig = { + OnBootSec = "1m"; + OnUnitActiveSec = "6h"; + Unit = "${name}.service"; + }; + }; + services = { + ${name} = let + cmd = "rad-system"; + rad = + lib.findFirst (x: x.name == cmd) (throw "could not find `${cmd}`") config.environment.systemPackages; + in { + script = '' + set -xeu + mkdir -p /tmp/radicle + ${lib.getExe rad} stats | ${lib.getExe pkgs.jq} --compact-output '. * { timestamp: now | strftime("%s") }' >> /tmp/radicle/stats.jsonl + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; + nginx.serviceConfig.BindReadOnlyPaths = [ + "/tmp/radicle/stats.jsonl:/tmp/radicle/stats.jsonl" + ]; + }; + }; + services.nginx.virtualHosts.${config.networking.fqdn}.locations."/tmp/".alias = "/tmp/radicle/"; +}