Skip to content

Commit

Permalink
add power supply metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mwennrich committed Oct 1, 2024
1 parent cad6630 commit b3c1508
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/metal-stack/metal-metrics-exporter
go 1.23

require (
github.com/metal-stack/metal-go v0.35.2
github.com/metal-stack/metal-go v0.37.1-0.20241001061321-b6fa718f2176
github.com/prometheus/client_golang v1.20.3
k8s.io/klog/v2 v2.130.1
)
Expand Down Expand Up @@ -40,7 +40,7 @@ require (
github.com/lestrrat-go/jwx/v2 v2.1.1 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/metal-stack/metal-lib v0.18.2
github.com/metal-stack/metal-lib v0.18.3
github.com/metal-stack/security v0.8.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/metal-stack/metal-go v0.35.2 h1:brTbmPUiYSH9IdbnCkrcRWFRlIfc0H/53f2phsB+5kY=
github.com/metal-stack/metal-go v0.35.2/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ=
github.com/metal-stack/metal-go v0.37.1-0.20241001061321-b6fa718f2176 h1:QRHcudgrKQtVzyVFlsyjkJO9EQwUM0/dhbOs6PhSNaw=
github.com/metal-stack/metal-go v0.37.1-0.20241001061321-b6fa718f2176/go.mod h1:MQN5ni2Gzu+x2sdk8blbh7elQD1W1vaf0E+RkiV2aoo=
github.com/metal-stack/metal-lib v0.18.2 h1:EAmZkZeKpenAvxZRSKsA6gj9Jd8XLR6Z0/QhABFCCDE=
github.com/metal-stack/metal-lib v0.18.2/go.mod h1:GJjipRpHmpd2vjBtsaw9gGk5ZFan7NlShyjIsTdY1x4=
github.com/metal-stack/metal-lib v0.18.3 h1:bovFiJPB9SMvuGLqcXVWz6jFB8HrdzwnCX7TFlen4r0=
github.com/metal-stack/metal-lib v0.18.3/go.mod h1:Ctyi6zaXFr2NVrQZLFsDLnFCzupKnYErTtgRFKAsnbw=
github.com/metal-stack/security v0.8.1 h1:4zmVUxZvDWShVvVIxM3XhIv7pTmPe9DvACRIHW6YTsk=
github.com/metal-stack/security v0.8.1/go.mod h1:OO8ZilZO6fUV5QEmwc7HP/RAjqYrGQxXoYIddJ9TvqE=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down
32 changes: 28 additions & 4 deletions metalCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ type metalCollector struct {
machineIssues *prometheus.Desc
machineIssuesInfo *prometheus.Desc

machineIpmiIpAddress *prometheus.Desc
machinePowerUsage *prometheus.Desc
machinePowerState *prometheus.Desc
machineHardwareInfo *prometheus.Desc
machineIpmiIpAddress *prometheus.Desc
machinePowerUsage *prometheus.Desc
machinePowerState *prometheus.Desc
machinePowerSuppliesTotal *prometheus.Desc
machinePowerSuppliesHealthy *prometheus.Desc
machineHardwareInfo *prometheus.Desc

projectInfo *prometheus.Desc

Expand Down Expand Up @@ -201,6 +203,16 @@ func newMetalCollector(client metalgo.Client) *metalCollector {
"Provide information about the machine power state",
[]string{"machineid"}, nil,
),
machinePowerSuppliesTotal: prometheus.NewDesc(
"metal_machine_power_supplies_total",
"Provide information about the total number of power supplies",
[]string{"machineid"}, nil,
),
machinePowerSuppliesHealthy: prometheus.NewDesc(
"metal_machine_power_supplies_healthy",
"Provide information about the number of healthy power supplies",
[]string{"machineid"}, nil,
),
machineHardwareInfo: prometheus.NewDesc(
"metal_machine_hardware_info",
"Provide information about the machine",
Expand Down Expand Up @@ -246,6 +258,8 @@ func (collector *metalCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.machineIpmiIpAddress
ch <- collector.machinePowerUsage
ch <- collector.machinePowerState
ch <- collector.machinePowerSuppliesTotal
ch <- collector.machinePowerSuppliesHealthy
}

func (collector *metalCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -459,6 +473,16 @@ func (collector *metalCollector) Collect(ch chan<- prometheus.Metric) {
}
ch <- prometheus.MustNewConstMetric(collector.machinePowerState, prometheus.GaugeValue, powerstate, *m.ID)
}
if m.Ipmi.Powersupplies != nil {
ch <- prometheus.MustNewConstMetric(collector.machinePowerSuppliesTotal, prometheus.GaugeValue, float64(len(m.Ipmi.Powersupplies)), *m.ID)
healthy := 0
for _, ps := range m.Ipmi.Powersupplies {
if ps.Status != nil && *ps.Status.Health == "OK" {
healthy++
}
}
ch <- prometheus.MustNewConstMetric(collector.machinePowerSuppliesHealthy, prometheus.GaugeValue, float64(healthy), *m.ID)
}
if m.Ipmi.Address != nil {
ch <- prometheus.MustNewConstMetric(collector.machineIpmiIpAddress, prometheus.GaugeValue, 1.0, *m.ID, *m.Ipmi.Address)
}
Expand Down

0 comments on commit b3c1508

Please sign in to comment.