From 4dffbcb222f7f68e9eb1c983b6ae78e380af1681 Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Thu, 18 Aug 2022 10:28:01 +1000 Subject: [PATCH] feat: added suspended as a node_zfs_zpool_state Signed-off-by: Pablo Caderno --- collector/fixtures/e2e-64k-page-output.txt | 9 +++++++++ collector/fixtures/e2e-output.txt | 9 +++++++++ collector/fixtures/proc/spl/kstat/zfs/pool2/state | 1 + collector/zfs_linux.go | 2 +- collector/zfs_linux_test.go | 9 +++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 collector/fixtures/proc/spl/kstat/zfs/pool2/state diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index f803dbb3f6..fc7cd9711b 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -4155,16 +4155,25 @@ node_zfs_zpool_rupdate{zpool="poolz1"} 1.10734831944501e+14 # HELP node_zfs_zpool_state kstat.zfs.misc.state # TYPE node_zfs_zpool_state gauge node_zfs_zpool_state{state="degraded",zpool="pool1"} 0 +node_zfs_zpool_state{state="degraded",zpool="pool2"} 0 node_zfs_zpool_state{state="degraded",zpool="poolz1"} 1 node_zfs_zpool_state{state="faulted",zpool="pool1"} 0 +node_zfs_zpool_state{state="faulted",zpool="pool2"} 0 node_zfs_zpool_state{state="faulted",zpool="poolz1"} 0 node_zfs_zpool_state{state="offline",zpool="pool1"} 0 +node_zfs_zpool_state{state="offline",zpool="pool2"} 0 node_zfs_zpool_state{state="offline",zpool="poolz1"} 0 node_zfs_zpool_state{state="online",zpool="pool1"} 1 +node_zfs_zpool_state{state="online",zpool="pool2"} 0 node_zfs_zpool_state{state="online",zpool="poolz1"} 0 node_zfs_zpool_state{state="removed",zpool="pool1"} 0 +node_zfs_zpool_state{state="removed",zpool="pool2"} 0 node_zfs_zpool_state{state="removed",zpool="poolz1"} 0 +node_zfs_zpool_state{state="suspended",zpool="pool1"} 0 +node_zfs_zpool_state{state="suspended",zpool="pool2"} 1 +node_zfs_zpool_state{state="suspended",zpool="poolz1"} 0 node_zfs_zpool_state{state="unavail",zpool="pool1"} 0 +node_zfs_zpool_state{state="unavail",zpool="pool2"} 0 node_zfs_zpool_state{state="unavail",zpool="poolz1"} 0 # HELP node_zfs_zpool_wcnt kstat.zfs.misc.io.wcnt # TYPE node_zfs_zpool_wcnt untyped diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index c4890888c3..83847356d7 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -4177,16 +4177,25 @@ node_zfs_zpool_rupdate{zpool="poolz1"} 1.10734831944501e+14 # HELP node_zfs_zpool_state kstat.zfs.misc.state # TYPE node_zfs_zpool_state gauge node_zfs_zpool_state{state="degraded",zpool="pool1"} 0 +node_zfs_zpool_state{state="degraded",zpool="pool2"} 0 node_zfs_zpool_state{state="degraded",zpool="poolz1"} 1 node_zfs_zpool_state{state="faulted",zpool="pool1"} 0 +node_zfs_zpool_state{state="faulted",zpool="pool2"} 0 node_zfs_zpool_state{state="faulted",zpool="poolz1"} 0 node_zfs_zpool_state{state="offline",zpool="pool1"} 0 +node_zfs_zpool_state{state="offline",zpool="pool2"} 0 node_zfs_zpool_state{state="offline",zpool="poolz1"} 0 node_zfs_zpool_state{state="online",zpool="pool1"} 1 +node_zfs_zpool_state{state="online",zpool="pool2"} 0 node_zfs_zpool_state{state="online",zpool="poolz1"} 0 node_zfs_zpool_state{state="removed",zpool="pool1"} 0 +node_zfs_zpool_state{state="removed",zpool="pool2"} 0 node_zfs_zpool_state{state="removed",zpool="poolz1"} 0 +node_zfs_zpool_state{state="suspended",zpool="pool1"} 0 +node_zfs_zpool_state{state="suspended",zpool="pool2"} 1 +node_zfs_zpool_state{state="suspended",zpool="poolz1"} 0 node_zfs_zpool_state{state="unavail",zpool="pool1"} 0 +node_zfs_zpool_state{state="unavail",zpool="pool2"} 0 node_zfs_zpool_state{state="unavail",zpool="poolz1"} 0 # HELP node_zfs_zpool_wcnt kstat.zfs.misc.io.wcnt # TYPE node_zfs_zpool_wcnt untyped diff --git a/collector/fixtures/proc/spl/kstat/zfs/pool2/state b/collector/fixtures/proc/spl/kstat/zfs/pool2/state new file mode 100644 index 0000000000..c3ddd0e661 --- /dev/null +++ b/collector/fixtures/proc/spl/kstat/zfs/pool2/state @@ -0,0 +1 @@ +SUSPENDED diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index 735e2154c9..b91fa0cad8 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go @@ -42,7 +42,7 @@ const ( // kstatDataString = "7" ) -var zfsPoolStatesName = []string{"online", "degraded", "faulted", "offline", "removed", "unavail"} +var zfsPoolStatesName = []string{"online", "degraded", "faulted", "offline", "removed", "unavail", "suspended"} func (c *zfsCollector) openProcFile(path string) (*os.File, error) { file, err := os.Open(procFilePath(path)) diff --git a/collector/zfs_linux_test.go b/collector/zfs_linux_test.go index b9aec14480..73427e8025 100644 --- a/collector/zfs_linux_test.go +++ b/collector/zfs_linux_test.go @@ -535,6 +535,15 @@ func TestPoolStateParsing(t *testing.T) { t.Fatalf("Incorrect parsed value for degraded state") } } + if poolName == "pool2" { + if isActive != uint64(1) && stateName == "suspended" { + t.Fatalf("Incorrect parsed value for suspended state") + } + if isActive != uint64(0) && stateName != "suspended" { + t.Fatalf("Incorrect parsed value for suspended state") + } + } + }) file.Close() if err != nil {