Skip to content

Commit

Permalink
Add machine state to machine allocation info. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Oct 24, 2023
1 parent acf9977 commit 40169e7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions metalCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 40169e7

Please sign in to comment.