Merge pull request #89 from tomhughes/fan-percent

Add support for fan sensors which report as a percentage
This commit is contained in:
Conrad Hoffmann 2022-01-11 20:30:43 +01:00 committed by GitHub
commit abcfdf3569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 13 deletions

View File

@ -43,13 +43,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).",
@ -163,15 +170,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)
}
@ -182,7 +196,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
@ -194,11 +209,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