Merge pull request #160 from k0ste/help

Added Power Measurement State to DCMI collector
This commit is contained in:
Conrad Hoffmann 2023-08-30 15:22:40 +02:00 committed by GitHub
commit 34ff637a24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 9 deletions

View File

@ -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

View File

@ -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
}
// Returned value negative == Power Measurement is not avail
if currentPowerConsumption > -1 {
ch <- prometheus.MustNewConstMetric(
powerConsumptionDesc,
prometheus.GaugeValue,
currentPowerConsumption,
)
}
return 1, nil
}

View File

@ -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>.*)`)
@ -200,12 +201,21 @@ func GetCurrentPowerConsumption(ipmiOutput Result) (float64, error) {
if ipmiOutput.err != nil {
return -1, fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output)
}
// Check for Power Measurement are avail
value, err := getValue(ipmiOutput.output, ipmiDCMIPowerMeasurementRegex)
if err != nil {
return -1, err
}
// 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, nil
}
func GetChassisPowerState(ipmiOutput Result) (float64, error) {
if ipmiOutput.err != nil {