From 40169e7de4ce09fec6ae3aaebd8b64f6e11dd157 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 24 Oct 2023 14:20:00 +0200 Subject: [PATCH] Add machine state to machine allocation info. (#14) --- metalCollector.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/metalCollector.go b/metalCollector.go index a2dee47..d87cdb5 100644 --- a/metalCollector.go +++ b/metalCollector.go @@ -128,7 +128,7 @@ func newMetalCollector(client metalgo.Client) *metalCollector { machineAllocationInfo: prometheus.NewDesc( "metal_machine_allocation_info", "Provide information about the machine allocation", - []string{"machineid", "partition", "machinename", "clusterTag", "primaryASN", "role"}, nil, + []string{"machineid", "partition", "machinename", "clusterTag", "primaryASN", "role", "state"}, nil, ), machineIssuesInfo: prometheus.NewDesc( "metal_machine_issues_info", @@ -319,8 +319,13 @@ func (collector *metalCollector) Collect(ch chan<- prometheus.Metric) { hostname = "NOTALLOCATED" clusterID = "NOTALLOCATED" primaryASN = "NOTALLOCATED" + state = "AVAILABLE" ) + if m.State != nil && m.State.Value != nil && *m.State.Value != "" { + state = *m.State.Value + } + if m.Allocation != nil { if m.Allocation.Role != nil { role = *m.Allocation.Role @@ -342,7 +347,7 @@ func (collector *metalCollector) Collect(ch chan<- prometheus.Metric) { partitionID = *m.Partition.ID } - ch <- prometheus.MustNewConstMetric(collector.machineAllocationInfo, prometheus.GaugeValue, 1.0, *m.ID, partitionID, hostname, clusterID, primaryASN, role) + ch <- prometheus.MustNewConstMetric(collector.machineAllocationInfo, prometheus.GaugeValue, 1.0, *m.ID, partitionID, hostname, clusterID, primaryASN, role, state) for issueID := range allIssuesByID { machineIssues, ok := issuesByMachineID[*m.ID]