Add support for fan sensors which report as a percentage

Fan sensors on HP servers report speed as a percentage of the
maximum instead of a raw RPM value.

Signed-off-by: Tom Hughes <tom@compton.nu>
This commit is contained in:
Tom Hughes 2021-11-14 10:32:52 +00:00
parent b806738818
commit 5d7b5cbb57
2 changed files with 34 additions and 13 deletions

View File

@ -42,13 +42,20 @@ var (
nil,
)
fanSpeedDesc = prometheus.NewDesc(
fanSpeedRPMDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "fan_speed", "rpm"),
"Fan speed in rotations per minute.",
[]string{"id", "name"},
nil,
)
fanSpeedRatioDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "fan_speed", "ratio"),
"Fan speed as a proportion of the maximum speed.",
[]string{"id", "name"},
nil,
)
fanSpeedStateDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "fan_speed", "state"),
"Reported state of a fan speed sensor (0=nominal, 1=warning, 2=critical).",
@ -162,15 +169,22 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
switch data.Unit {
case "RPM":
collectTypedSensor(ch, fanSpeedDesc, fanSpeedStateDesc, state, data)
collectTypedSensor(ch, fanSpeedRPMDesc, fanSpeedStateDesc, state, data, 1.0)
case "C":
collectTypedSensor(ch, temperatureDesc, temperatureStateDesc, state, data)
collectTypedSensor(ch, temperatureDesc, temperatureStateDesc, state, data, 1.0)
case "A":
collectTypedSensor(ch, currentDesc, currentStateDesc, state, data)
collectTypedSensor(ch, currentDesc, currentStateDesc, state, data, 1.0)
case "V":
collectTypedSensor(ch, voltageDesc, voltageStateDesc, state, data)
collectTypedSensor(ch, voltageDesc, voltageStateDesc, state, data, 1.0)
case "W":
collectTypedSensor(ch, powerDesc, powerStateDesc, state, data)
collectTypedSensor(ch, powerDesc, powerStateDesc, state, data, 1.0)
case "%":
switch data.Type {
case "Fan":
collectTypedSensor(ch, fanSpeedRatioDesc, fanSpeedStateDesc, state, data, 0.01)
default:
collectGenericSensor(ch, state, data)
}
default:
collectGenericSensor(ch, state, data)
}
@ -181,7 +195,8 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
func (c IPMICollector) Describe(ch chan<- *prometheus.Desc) {
ch <- sensorStateDesc
ch <- sensorValueDesc
ch <- fanSpeedDesc
ch <- fanSpeedRPMDesc
ch <- fanSpeedRatioDesc
ch <- fanSpeedStateDesc
ch <- temperatureDesc
ch <- temperatureStateDesc
@ -193,11 +208,11 @@ func (c IPMICollector) Describe(ch chan<- *prometheus.Desc) {
ch <- powerStateDesc
}
func collectTypedSensor(ch chan<- prometheus.Metric, desc, stateDesc *prometheus.Desc, state float64, data freeipmi.SensorData) {
func collectTypedSensor(ch chan<- prometheus.Metric, desc, stateDesc *prometheus.Desc, state float64, data freeipmi.SensorData, scale float64) {
ch <- prometheus.MustNewConstMetric(
desc,
prometheus.GaugeValue,
data.Value,
data.Value*scale,
strconv.FormatInt(data.ID, 10),
data.Name,
)

View File

@ -111,14 +111,20 @@ sensor ID and the sensor name as labels. Example:
### Fan speed sensors
Fan speed sensors measure fan speed in rotations per minute (RPM) and their
state usually reflects the speed being to low, indicating the fan might be
broken. For each fan speed sensor, two metrics are exported (state and value),
using the sensor ID and the sensor name as labels. Example:
Fan speed sensors measure fan speed in rotations per minute (RPM) or as a
percentage of the maximum speed, and their state usually reflects the speed
being to low, indicating the fan might be broken. For each fan speed sensor,
two metrics are exported (state and value), using the sensor ID and the
sensor name as labels. Example:
ipmi_fan_speed_rpm{id="12",name="Fan1A"} 4560
ipmi_fan_speed_state{id="12",name="Fan1A"} 0
or, for a percentage based fan:
ipmi_fan_speed_ratio{id="58",name="Fan 1 DutyCycle"} 0.2195
ipmi_fan_speed_state{id="58",name="Fan 1 DutyCycle"} 0
### Voltage sensors
Voltage sensors measure a voltage in Volts. For each voltage sensor, two