Skip to content

Commit

Permalink
Now, ipmi_dcmi_power_consumption_watts metric is not present if Power
Browse files Browse the repository at this point in the history
Measurement feature is not present. Before this change - the value was zero

Signed-off-by: Konstantin Shalygin <[email protected]>
  • Loading branch information
k0ste committed Aug 10, 2023
1 parent 357235b commit 76306bd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## next

* Now, `ipmi_dcmi_power_consumption_watts` metric is not present if Power
Measurement feature is not present. Before this change - the value was zero

## 1.6.1 / 2022-06-17

* Another "I screwed up the release" release
Expand Down
15 changes: 9 additions & 6 deletions collector_dcmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
var (
powerConsumptionDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "dcmi", "power_consumption_watts"),
"Current power consumption in Watts.",
"Current power consumption in Watts (no value if Power Measurement is not avail)",
[]string{},
nil,
)
Expand All @@ -53,10 +53,13 @@ func (c DCMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
level.Error(logger).Log("msg", "Failed to collect DCMI data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(
powerConsumptionDesc,
prometheus.GaugeValue,
currentPowerConsumption,
)
// Returned value negative == Power Measurement is not avail
if currentPowerConsumption > -1 {
ch <- prometheus.MustNewConstMetric(
powerConsumptionDesc,
prometheus.GaugeValue,
currentPowerConsumption,
)
}
return 1, nil
}
6 changes: 5 additions & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ case it will be exported as `"N/A"`.
This metric is only provided if the `chassis` collector is enabled.

The metric `ipmi_chassis_power_state` shows the current chassis power state of
the machine. The value is 1 for power on, and 0 otherwise.
the machine. The value is 1 for power on, and 0 otherwise.

## Power consumption

Expand All @@ -52,6 +52,10 @@ the live power consumption of the machine in Watts. If in doubt, this metric
should be used over any of the sensor data (see below), even if their name
might suggest that they measure the same thing. This metric has no labels.

In some cases, for example with cheap Power Supply Units power consumption may
be not available at all, to control this use `ipmi_dcmi_power_measurement_state`
metric. The value is 1 for power measure is available on, and 0 otherwise.

## System event log (SEL) info

These metrics are only provided if the `sel` collector is enabled (it isn't by
Expand Down
15 changes: 13 additions & 2 deletions freeipmi/freeipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
)

var (
ipmiDCMIPowerMeasurementRegex = regexp.MustCompile(`^Power Measurement\s*:\s*(?P<value>Active|Not\sAvailable).*`)
ipmiDCMICurrentPowerRegex = regexp.MustCompile(`^Current Power\s*:\s*(?P<value>[0-9.]*)\s*Watts.*`)
ipmiChassisPowerRegex = regexp.MustCompile(`^System Power\s*:\s(?P<value>.*)`)
ipmiChassisDriveFaultRegex = regexp.MustCompile(`^Drive Fault\s*:\s(?P<value>.*)`)
Expand Down Expand Up @@ -196,15 +197,25 @@ func GetSensorData(ipmiOutput Result, excludeSensorIds []int64) ([]SensorData, e
return result, err
}


func GetCurrentPowerConsumption(ipmiOutput Result) (float64, error) {
if ipmiOutput.err != nil {
return -1, fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output)
}
value, err := getValue(ipmiOutput.output, ipmiDCMICurrentPowerRegex)
// Check for Power Measurement are avail
value, err := getValue(ipmiOutput.output, ipmiDCMIPowerMeasurementRegex)
if err != nil {
return -1, err
}
return strconv.ParseFloat(value, 64)
// When Power Measurement in 'Active' state - we can get watts
if value == "Active" {
value, err := getValue(ipmiOutput.output, ipmiDCMICurrentPowerRegex)
if err != nil {
return -1, err
}
return strconv.ParseFloat(value, 64)
}
return -1, err
}

func GetChassisPowerState(ipmiOutput Result) (float64, error) {
Expand Down

0 comments on commit 76306bd

Please sign in to comment.