Merge pull request #160 from k0ste/help
Added Power Measurement State to DCMI collector
This commit is contained in:
commit
34ff637a24
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,11 +201,20 @@ 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) {
|
||||
|
|
Loading…
Reference in New Issue