39 lines
899 B
Nix
39 lines
899 B
Nix
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
textfileDir = "/var/lib/prometheus-node-exporter-textfiles";
|
|
|
|
diskUsageCollector = pkgs.writeShellApplication {
|
|
name = "disk-usage-collector";
|
|
runtimeInputs = with pkgs; [
|
|
coreutils
|
|
gawk
|
|
config.boot.zfs.package
|
|
util-linux # for mountpoint
|
|
];
|
|
text = builtins.readFile ./disk-usage-collector.sh;
|
|
};
|
|
in
|
|
lib.mkIf config.services.grafana.enable {
|
|
systemd.services.disk-usage-collector = {
|
|
description = "Collect ZFS pool and partition usage metrics for Prometheus";
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
ExecStart = lib.getExe diskUsageCollector;
|
|
};
|
|
environment.TEXTFILE = "${textfileDir}/disk-usage.prom";
|
|
};
|
|
|
|
systemd.timers.disk-usage-collector = {
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig = {
|
|
OnCalendar = "minutely";
|
|
RandomizedDelaySec = "10s";
|
|
};
|
|
};
|
|
}
|