Add custom nix-daemon exporter #99
Reference in New Issue
Block a user
Delete Branch "monitor-nix-daemon"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Allows us to see which derivations are being built in realtime. It is a
bit of a hack, but it seems to work. We simply look at the environment
of the child processes of nix-daemon (usually bash) and then look for
the $name variable which should hold the current derivation being
built. Needs root to be able to read the environ file of the different
nix-daemon processes as they are owned by the nixbld* users.
See: https://discourse.nixos.org/t/query-ongoing-builds/23486
See in action: https://jungle.bsc.es/grafana/d/EKkKVvLVz/hut?orgId=1&from=now-6h&to=now&timezone=browser&refresh=5s&viewPanel=panel-47
Left some suggestions on rip-grep, the rest LGTM (although it's a little scary to run this as root given that name is arbitrary user input)
@@ -0,0 +18,4 @@EOFfor pid in $pids2; doname=$(cat /proc/$pid/environ 2>/dev/null | tr '\0' '\n' | rg "^name=(.+)" - --replace '$1')I think we could use
--null-datainrgand avoidtr. There is also--max-count 1I'm not able to make it work with --null-data:
Maybe you can open another MR to improve it.
Edit: Reproducer:
Yeah I know. Any ideas how to improve it?
Not really. I was thinking of using
{pre,post}-build-hooksbut I don't think it is viable, since it would require some form of state management and produce a lot of noise.I think this could be added to the nix binary directly, so it reports the stats over a TCP port, but that won't be done in the short term. If you don't see any obvious problem with the current approach I'll be willing to merge it, as I think the benefits outweight the potential drawbacks.
@@ -0,0 +21,4 @@name=$(cat /proc/$pid/environ 2>/dev/null | tr '\0' '\n' | rg "^name=(.+)" - --replace '$1')user=$(ps -o uname= -p "$pid")if [ -n "$name" -a -n "$user" ]; thenprintf 'nix_daemon_build{user="%s",name="%s"} 1\n' "$user" "$name"I would pass name through
tr -dc ' [:alnum:]_\-\.'to avoid getting garbage in grafana.Done
13e084f34ftoc12eceb897c12eceb897to1c15e77c83