Added ZFS state metrics
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user