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 ## 1.6.1 / 2022-06-17
* Another "I screwed up the release" release * 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) level.Error(logger).Log("msg", "Failed to collect DCMI data", "target", targetName(target.host), "error", err)
return 0, err return 0, err
} }
ch <- prometheus.MustNewConstMetric( // Returned value negative == Power Measurement is not avail
powerConsumptionDesc, if currentPowerConsumption > -1 {
prometheus.GaugeValue, ch <- prometheus.MustNewConstMetric(
currentPowerConsumption, powerConsumptionDesc,
) prometheus.GaugeValue,
currentPowerConsumption,
)
}
return 1, nil return 1, nil
} }

View File

@ -41,7 +41,7 @@ case it will be exported as `"N/A"`.
This metric is only provided if the `chassis` collector is enabled. 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 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 ## Power consumption
@ -159,7 +159,7 @@ explicit [power consumption metrics](#power_consumption) for this.
### Generic sensors ### Generic sensors
For all sensors that can not be classified, two generic metrics are exported, For all sensors that can not be classified, two generic metrics are exported,
the state and the value. However, to provide a little more context, the sensor the state and the value. However, to provide a little more context, the sensor
type is added as label (in addition to name and ID). Example: type is added as label (in addition to name and ID). Example:
ipmi_sensor_state{id="139",name="Power Cable",type="Cable/Interconnect"} 0 ipmi_sensor_state{id="139",name="Power Cable",type="Cable/Interconnect"} 0

View File

@ -33,6 +33,7 @@ import (
) )
var ( 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.*`) ipmiDCMICurrentPowerRegex = regexp.MustCompile(`^Current Power\s*:\s*(?P<value>[0-9.]*)\s*Watts.*`)
ipmiChassisPowerRegex = regexp.MustCompile(`^System Power\s*:\s(?P<value>.*)`) ipmiChassisPowerRegex = regexp.MustCompile(`^System Power\s*:\s(?P<value>.*)`)
ipmiChassisDriveFaultRegex = regexp.MustCompile(`^Drive Fault\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 { if ipmiOutput.err != nil {
return -1, fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output) 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 { if err != nil {
return -1, err 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, nil
} }
func GetChassisPowerState(ipmiOutput Result) (float64, error) { func GetChassisPowerState(ipmiOutput Result) (float64, error) {