aboutsummaryrefslogtreecommitdiffstats
path: root/modules/packages.nix
blob: 5e76f103a6375e4456ac52970b3d6e2f3e967b12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# The two textfile collectors, as ordinary packages.
#
# They are wrappers rather than inline `writeShellApplication` bodies in the module so
# that the Python is runnable by hand -- `zfs-metrics --output /tmp/x.prom` behaves
# exactly as the timer does, which is how every one of these metrics was validated.
# Neither wrapper hardcodes an output path; the unit passes it.
{ lib, writeShellApplication, python3, smartmontools, zfs }:

{
  # Pool capacity and health, vdev errors, scrub history, dataset properties and
  # snapshot retention -- none of which node_exporter's built-in zfs collector reports,
  # because it reads /proc/spl/kstat/zfs and that only carries ARC statistics and objset
  # counters. OpenZFS 2.2+ also dropped the per-pool `io` kstat, so node_zfs_zpool_* is
  # largely empty. This shells out to the zpool/zfs CLIs instead.
  #
  # runtimeInputs is the whole reason for the wrapper: the collector must run against
  # the same zfs userland as the running kernel module.
  zfs-metrics = writeShellApplication {
    name = "zfs-metrics";
    runtimeInputs = [ zfs ];
    text = ''
      exec ${python3.interpreter} ${../collectors/zfs-metrics.py} "$@"
    '';
    meta = {
      description = "Export ZFS pool, dataset and snapshot metrics in Prometheus format";
      mainProgram = "zfs-metrics";
    };
  };

  # smartctl_exporter reads only the entry *count* out of each drive's self-test log and
  # discards the log table, so it cannot say when a drive last ran a short or extended
  # test or whether it passed. It also has no way to render a drive's identity as a
  # display string, which the dashboards need for row titles. Both come from here.
  smart-selftest = writeShellApplication {
    name = "smart-selftest";
    runtimeInputs = [ smartmontools ];
    text = ''
      exec ${python3.interpreter} ${../collectors/smart-selftest.py} "$@"
    '';
    meta = {
      description = "Export SMART self-test history and drive identity in Prometheus format";
      mainProgram = "smart-selftest";
    };
  };
}