monitoring: add zpool and boot partition usage metrics
Add textfile collector for ZFS pool utilization (tank, hdds) and boot drive partitions (/boot, /persistent, /nix). Runs every 60s. Add two Grafana dashboard panels: ZFS Pool Utilization and Boot Drive Partitions as Row 5.
This commit is contained in:
@@ -79,6 +79,17 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
dashboard = {
|
||||
editable = true;
|
||||
graphTooltip = 1;
|
||||
@@ -669,6 +680,94 @@ let
|
||||
overrides = [ ];
|
||||
};
|
||||
}
|
||||
|
||||
# -- Row 5: Storage --
|
||||
{
|
||||
id = 12;
|
||||
type = "timeseries";
|
||||
title = "ZFS Pool Utilization";
|
||||
gridPos = {
|
||||
h = 8;
|
||||
w = 12;
|
||||
x = 0;
|
||||
y = 32;
|
||||
};
|
||||
datasource = promDs;
|
||||
targets = [
|
||||
{
|
||||
datasource = promDs;
|
||||
expr = "zpool_used_bytes{pool=\"tank\"} / zpool_size_bytes{pool=\"tank\"} * 100";
|
||||
legendFormat = "tank";
|
||||
refId = "A";
|
||||
}
|
||||
{
|
||||
datasource = promDs;
|
||||
expr = "zpool_used_bytes{pool=\"hdds\"} / zpool_size_bytes{pool=\"hdds\"} * 100";
|
||||
legendFormat = "hdds";
|
||||
refId = "B";
|
||||
}
|
||||
];
|
||||
fieldConfig = {
|
||||
defaults = {
|
||||
unit = "percent";
|
||||
min = 0;
|
||||
max = 100;
|
||||
color.mode = "palette-classic";
|
||||
custom = {
|
||||
lineWidth = 2;
|
||||
fillOpacity = 20;
|
||||
spanNulls = true;
|
||||
};
|
||||
};
|
||||
overrides = [ ];
|
||||
};
|
||||
}
|
||||
{
|
||||
id = 13;
|
||||
type = "timeseries";
|
||||
title = "Boot Drive Partitions";
|
||||
gridPos = {
|
||||
h = 8;
|
||||
w = 12;
|
||||
x = 12;
|
||||
y = 32;
|
||||
};
|
||||
datasource = promDs;
|
||||
targets = [
|
||||
{
|
||||
datasource = promDs;
|
||||
expr = "partition_used_bytes{mount=\"/boot\"} / partition_size_bytes{mount=\"/boot\"} * 100";
|
||||
legendFormat = "/boot";
|
||||
refId = "A";
|
||||
}
|
||||
{
|
||||
datasource = promDs;
|
||||
expr = "partition_used_bytes{mount=\"/persistent\"} / partition_size_bytes{mount=\"/persistent\"} * 100";
|
||||
legendFormat = "/persistent";
|
||||
refId = "B";
|
||||
}
|
||||
{
|
||||
datasource = promDs;
|
||||
expr = "partition_used_bytes{mount=\"/nix\"} / partition_size_bytes{mount=\"/nix\"} * 100";
|
||||
legendFormat = "/nix";
|
||||
refId = "C";
|
||||
}
|
||||
];
|
||||
fieldConfig = {
|
||||
defaults = {
|
||||
unit = "percent";
|
||||
min = 0;
|
||||
max = 100;
|
||||
color.mode = "palette-classic";
|
||||
custom = {
|
||||
lineWidth = 2;
|
||||
fillOpacity = 20;
|
||||
spanNulls = true;
|
||||
};
|
||||
};
|
||||
overrides = [ ];
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
in
|
||||
@@ -875,6 +974,24 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# -- Disk/pool usage textfile collector --
|
||||
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 = "*:*:0/60"; # every 60 seconds
|
||||
RandomizedDelaySec = "10s";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d ${textfileDir} 0755 root root -"
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user