Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
462eb4f80c |
@@ -69,7 +69,8 @@ unusable subscription.
|
|||||||
The ZFS collector discovers all pools on every node and exports their recursive
|
The ZFS collector discovers all pools on every node and exports their recursive
|
||||||
topology with `cluster`, `node`, `pool`, `component`, `path`, and `leaf` labels:
|
topology with `cluster`, `node`, `pool`, `component`, `path`, and `leaf` labels:
|
||||||
|
|
||||||
- `pve_node_zfs_state` (`1` for `ONLINE`, otherwise `0`)
|
- `pve_node_zfs_state` (`0=UNKNOWN`, `1=ONLINE`, `2=DEGRADED`, `3=FAULTED`,
|
||||||
|
`4=OFFLINE`, `5=REMOVED`, `6=UNAVAIL`)
|
||||||
- `pve_node_zfs_read_errors`
|
- `pve_node_zfs_read_errors`
|
||||||
- `pve_node_zfs_write_errors`
|
- `pve_node_zfs_write_errors`
|
||||||
- `pve_node_zfs_checksum_errors`
|
- `pve_node_zfs_checksum_errors`
|
||||||
|
|||||||
@@ -26,17 +26,26 @@ type zfsMetricComponent struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var zfsStateValues = map[string]float64{
|
||||||
|
"ONLINE": 1,
|
||||||
|
"DEGRADED": 2,
|
||||||
|
"FAULTED": 3,
|
||||||
|
"OFFLINE": 4,
|
||||||
|
"REMOVED": 5,
|
||||||
|
"UNAVAIL": 6,
|
||||||
|
}
|
||||||
|
|
||||||
// NewPveNodeZfsCollector creates a ZFS metrics collector.
|
// NewPveNodeZfsCollector creates a ZFS metrics collector.
|
||||||
func NewPveNodeZfsCollector(apiClient *proxmox.PveApiClient, registry *TTLRegistry) *PveNodeZfsCollector {
|
func NewPveNodeZfsCollector(apiClient *proxmox.PveApiClient, registry *TTLRegistry) *PveNodeZfsCollector {
|
||||||
c := PveNodeZfsCollector{apiClient: apiClient, registry: registry}
|
c := PveNodeZfsCollector{apiClient: apiClient, registry: registry}
|
||||||
labelNames := []string{"cluster", "node", "pool", "component", "path", "leaf"}
|
componentLabelNames := []string{"cluster", "node", "pool", "component", "path", "leaf"}
|
||||||
|
|
||||||
c.state = NewTTLGaugeVec(
|
c.state = NewTTLGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "pve_node_zfs_state",
|
Name: "pve_node_zfs_state",
|
||||||
Help: "ZFS pool component state (1 = ONLINE, 0 = any other state).",
|
Help: "ZFS pool component state (0 = UNKNOWN, 1 = ONLINE, 2 = DEGRADED, 3 = FAULTED, 4 = OFFLINE, 5 = REMOVED, 6 = UNAVAIL).",
|
||||||
},
|
},
|
||||||
labelNames,
|
componentLabelNames,
|
||||||
5*time.Minute,
|
5*time.Minute,
|
||||||
)
|
)
|
||||||
c.registry.Register(c.state)
|
c.registry.Register(c.state)
|
||||||
@@ -46,7 +55,7 @@ func NewPveNodeZfsCollector(apiClient *proxmox.PveApiClient, registry *TTLRegist
|
|||||||
Name: "pve_node_zfs_read_errors",
|
Name: "pve_node_zfs_read_errors",
|
||||||
Help: "ZFS pool component read error count.",
|
Help: "ZFS pool component read error count.",
|
||||||
},
|
},
|
||||||
labelNames,
|
componentLabelNames,
|
||||||
5*time.Minute,
|
5*time.Minute,
|
||||||
)
|
)
|
||||||
c.registry.Register(c.readErrors)
|
c.registry.Register(c.readErrors)
|
||||||
@@ -56,7 +65,7 @@ func NewPveNodeZfsCollector(apiClient *proxmox.PveApiClient, registry *TTLRegist
|
|||||||
Name: "pve_node_zfs_write_errors",
|
Name: "pve_node_zfs_write_errors",
|
||||||
Help: "ZFS pool component write error count.",
|
Help: "ZFS pool component write error count.",
|
||||||
},
|
},
|
||||||
labelNames,
|
componentLabelNames,
|
||||||
5*time.Minute,
|
5*time.Minute,
|
||||||
)
|
)
|
||||||
c.registry.Register(c.writeErrors)
|
c.registry.Register(c.writeErrors)
|
||||||
@@ -66,7 +75,7 @@ func NewPveNodeZfsCollector(apiClient *proxmox.PveApiClient, registry *TTLRegist
|
|||||||
Name: "pve_node_zfs_checksum_errors",
|
Name: "pve_node_zfs_checksum_errors",
|
||||||
Help: "ZFS pool component checksum error count.",
|
Help: "ZFS pool component checksum error count.",
|
||||||
},
|
},
|
||||||
labelNames,
|
componentLabelNames,
|
||||||
5*time.Minute,
|
5*time.Minute,
|
||||||
)
|
)
|
||||||
c.registry.Register(c.checksumErrors)
|
c.registry.Register(c.checksumErrors)
|
||||||
@@ -146,8 +155,8 @@ func appendZfsComponent(components *[]zfsMetricComponent, component proxmox.PveZ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func zfsStateNumeric(state string) float64 {
|
func zfsStateNumeric(state string) float64 {
|
||||||
if strings.EqualFold(state, "ONLINE") {
|
if value, ok := zfsStateValues[strings.ToUpper(state)]; ok {
|
||||||
return 1
|
return value
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,10 +55,24 @@ func TestFlattenZfsComponents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestZfsStateNumeric(t *testing.T) {
|
func TestZfsStateNumeric(t *testing.T) {
|
||||||
if got := zfsStateNumeric("ONLINE"); got != 1 {
|
tests := []struct {
|
||||||
t.Fatalf("zfsStateNumeric(ONLINE) = %v, want 1", got)
|
state string
|
||||||
|
want float64
|
||||||
|
}{
|
||||||
|
{state: "UNKNOWN", want: 0},
|
||||||
|
{state: "ONLINE", want: 1},
|
||||||
|
{state: "DEGRADED", want: 2},
|
||||||
|
{state: "FAULTED", want: 3},
|
||||||
|
{state: "OFFLINE", want: 4},
|
||||||
|
{state: "REMOVED", want: 5},
|
||||||
|
{state: "UNAVAIL", want: 6},
|
||||||
}
|
}
|
||||||
if got := zfsStateNumeric("DEGRADED"); got != 0 {
|
|
||||||
t.Fatalf("zfsStateNumeric(DEGRADED) = %v, want 0", got)
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.state, func(t *testing.T) {
|
||||||
|
if got := zfsStateNumeric(tt.state); got != tt.want {
|
||||||
|
t.Fatalf("zfsStateNumeric(%q) = %v, want %v", tt.state, got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user