Convert HA API service IDs (vm:106, ct:200) to the resource ID format used by /cluster/resources and the Python exporter (qemu/106, lxc/200). Rename label from "sid" to "id" so HA metrics can be joined with pve_ha_state, pve_guest_info, and other id-labeled metrics. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package collector
|
|
|
|
import (
|
|
"log/slog"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
)
|
|
|
|
func TestHAStatusCollector(t *testing.T) {
|
|
client := newTestClient(t, map[string]string{
|
|
"/cluster/ha/status/manager_status": "ha_manager_status.json",
|
|
"/cluster/ha/resources": "ha_resources.json",
|
|
})
|
|
|
|
collector := newHAStatusCollector(slog.Default())
|
|
adapter := &testCollectorAdapter{client: client, collector: collector}
|
|
|
|
reg := prometheus.NewRegistry()
|
|
reg.MustRegister(adapter)
|
|
|
|
expected := `
|
|
# HELP pve_ha_crm_master Whether a node is the CRM master.
|
|
# TYPE pve_ha_crm_master gauge
|
|
pve_ha_crm_master{node="node01"} 0
|
|
pve_ha_crm_master{node="node02"} 0
|
|
pve_ha_crm_master{node="node03"} 1
|
|
# HELP pve_ha_lrm_mode LRM mode for a node.
|
|
# TYPE pve_ha_lrm_mode gauge
|
|
pve_ha_lrm_mode{mode="active",node="node01"} 1
|
|
pve_ha_lrm_mode{mode="active",node="node02"} 1
|
|
pve_ha_lrm_mode{mode="active",node="node03"} 1
|
|
# HELP pve_ha_lrm_timestamp_seconds Last LRM heartbeat as Unix timestamp.
|
|
# TYPE pve_ha_lrm_timestamp_seconds gauge
|
|
pve_ha_lrm_timestamp_seconds{node="node01"} 1.77401635e+09
|
|
pve_ha_lrm_timestamp_seconds{node="node02"} 1.774016351e+09
|
|
pve_ha_lrm_timestamp_seconds{node="node03"} 1.774016351e+09
|
|
# HELP pve_ha_node_status HA node status.
|
|
# TYPE pve_ha_node_status gauge
|
|
pve_ha_node_status{node="node01",status="online"} 1
|
|
pve_ha_node_status{node="node02",status="online"} 1
|
|
pve_ha_node_status{node="node03",status="online"} 1
|
|
# HELP pve_ha_service_config HA service configuration.
|
|
# TYPE pve_ha_service_config gauge
|
|
pve_ha_service_config{failback="1",id="qemu/106",max_relocate="2",max_restart="2",type="vm"} 1
|
|
# HELP pve_ha_service_status HA service runtime status.
|
|
# TYPE pve_ha_service_status gauge
|
|
pve_ha_service_status{id="qemu/106",node="node01",state="started"} 1
|
|
`
|
|
|
|
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
|
|
"pve_ha_crm_master", "pve_ha_node_status",
|
|
"pve_ha_lrm_timestamp_seconds", "pve_ha_lrm_mode",
|
|
"pve_ha_service_config", "pve_ha_service_status",
|
|
); err != nil {
|
|
t.Errorf("unexpected metrics: %s", err)
|
|
}
|
|
}
|