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