os/mixin/radicle-stats: Collect rad stats

A systemd timer unit that will just take the output of `rad stats` and
timestamp it.
This commit is contained in:
Lorenz Leutgeb
2025-07-17 20:55:31 +02:00
parent 94e1a77205
commit 50df86e20c
4 changed files with 46 additions and 1 deletions
+1
View File
@@ -8,6 +8,7 @@ in {
imports = [
../../mixin/radicle.nix
../../mixin/radicle-permissive.nix
../../mixin/radicle-stats.nix
];
fileSystems."/var/lib/radicle" = {
+1
View File
@@ -8,6 +8,7 @@ in {
imports = [
../../mixin/radicle.nix
../../mixin/radicle-permissive.nix
../../mixin/radicle-stats.nix
];
fileSystems."/var/lib/radicle" = {
+4 -1
View File
@@ -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";
+40
View File
@@ -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/";
}