diff --git a/modules/monitoring.nix b/modules/monitoring.nix index 477a4af..081150b 100644 --- a/modules/monitoring.nix +++ b/modules/monitoring.nix @@ -1,6 +1,20 @@ { config, pkgs, lib, ... }: let cfg = config.skyworks.monitoring; + zpoolHealthScript = pkgs.writeShellScript "zpool-health" '' + ${pkgs.zfs}/bin/zpool list -H -o name,health | while read -r pool health; do + case "$health" in + ONLINE) val=0 ;; + DEGRADED) val=1 ;; + FAULTED) val=2 ;; + OFFLINE) val=3 ;; + UNAVAIL) val=4 ;; + REMOVED) val=5 ;; + *) val=6 ;; + esac + echo "zpool_health,pool=$pool health=''${val}i" + done + ''; in { options.skyworks.monitoring = { enable = lib.mkEnableOption "Telegraf monitoring to door1 InfluxDB"; @@ -68,6 +82,12 @@ attributes = true; devices = cfg.smartDevices; }]; + exec = [{ + commands = [ "${zpoolHealthScript}" ]; + interval = "60s"; + timeout = "10s"; + data_format = "influx"; + }]; }; }; };