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
+61 -1
View File
@@ -1,6 +1,9 @@
package proxmox
import "testing"
import (
"encoding/json"
"testing"
)
func TestPveClusterStatusGetClusterModeNumeric(t *testing.T) {
tests := []struct {
@@ -52,3 +55,60 @@ func TestPveSubscriptionGetStatusNumeric(t *testing.T) {
})
}
}
func TestPveZfsPoolStatusUnmarshal(t *testing.T) {
payload := []byte(`{
"errors": "No known data errors",
"state": "ONLINE",
"leaf": 0,
"name": "hdd",
"children": [
{
"name": "hdd",
"state": "ONLINE",
"read": 0,
"write": 0,
"cksum": 0,
"children": [
{
"name": "/dev/disk/by-id/disk-1-part1",
"state": "ONLINE",
"leaf": 1,
"read": 0,
"write": 0,
"cksum": 0
}
]
},
{
"name": "cache",
"leaf": 0
}
]
}`)
var status PveZfsPoolStatus
if err := json.Unmarshal(payload, &status); err != nil {
t.Fatalf("unable to unmarshal ZFS pool status: %v", err)
}
if status.Name != "hdd" || status.State != "ONLINE" || status.Errors != "No known data errors" {
t.Fatalf("unexpected pool status: %+v", status)
}
if len(status.Children) != 2 || len(status.Children[0].Children) != 1 {
t.Fatalf("unexpected ZFS topology: %+v", status.Children)
}
leaf := status.Children[0].Children[0]
if leaf.Leaf != 1 || leaf.Read == nil || leaf.Write == nil || leaf.Checksum == nil {
t.Fatal("leaf component is missing its type or error counters")
}
if *leaf.Read != 0 || *leaf.Write != 0 || *leaf.Checksum != 0 {
t.Fatalf("unexpected leaf error counters: read=%d write=%d checksum=%d", *leaf.Read, *leaf.Write, *leaf.Checksum)
}
cache := status.Children[1]
if cache.Read != nil || cache.Write != nil || cache.Checksum != nil {
t.Fatal("missing cache counters must stay absent instead of becoming zero metrics")
}
}