Added ZFS state metrics
Build Docker image on push / docker (push) Successful in 23s
Build and push Docker image on tag / docker (push) Successful in 23s

This commit is contained in:
2026-08-17 22:08:57 +02:00
parent f8f9e0c852
commit ba88e5997a
9 changed files with 363 additions and 3 deletions
+64
View File
@@ -0,0 +1,64 @@
package metrics
import (
"testing"
"lostak.dev/pve-exporter/proxmox"
)
func TestFlattenZfsComponents(t *testing.T) {
zero := uint64(0)
status := &proxmox.PveZfsPoolStatus{
PveZfsComponent: proxmox.PveZfsComponent{
Name: "hdd",
State: "ONLINE",
Children: []proxmox.PveZfsComponent{
{
Name: "hdd",
Children: []proxmox.PveZfsComponent{
{
Name: "raidz1-0",
State: "ONLINE",
Read: &zero,
Write: &zero,
Checksum: &zero,
Children: []proxmox.PveZfsComponent{
{
Name: "/dev/disk/by-id/disk-1-part1",
State: "ONLINE",
Leaf: 1,
Read: &zero,
Write: &zero,
Checksum: &zero,
},
},
},
},
},
},
},
}
components := flattenZfsComponents(status)
if len(components) != 4 {
t.Fatalf("flattenZfsComponents() returned %d components, want 4", len(components))
}
leaf := components[3]
wantPath := "hdd > hdd > raidz1-0 > /dev/disk/by-id/disk-1-part1"
if leaf.Path != wantPath {
t.Fatalf("leaf path = %q, want %q", leaf.Path, wantPath)
}
if leaf.Leaf != 1 || leaf.Read == nil || leaf.Write == nil || leaf.Checksum == nil {
t.Fatal("leaf component lost its type or error counters")
}
}
func TestZfsStateNumeric(t *testing.T) {
if got := zfsStateNumeric("ONLINE"); got != 1 {
t.Fatalf("zfsStateNumeric(ONLINE) = %v, want 1", got)
}
if got := zfsStateNumeric("DEGRADED"); got != 0 {
t.Fatalf("zfsStateNumeric(DEGRADED) = %v, want 0", got)
}
}