Add PSU voltage sensors with 220V range highlighting
This commit is contained in:
@@ -268,7 +268,42 @@ func (s *Server) handleGetSensors(w http.ResponseWriter, r *http.Request) {
|
||||
jsonResponse(w, []interface{}{})
|
||||
return
|
||||
}
|
||||
jsonResponse(w, result.Sensors)
|
||||
sensors := append([]models.SensorReading{}, result.Sensors...)
|
||||
sensors = append(sensors, synthesizePSUVoltageSensors(result.Hardware)...)
|
||||
jsonResponse(w, sensors)
|
||||
}
|
||||
|
||||
func synthesizePSUVoltageSensors(hw *models.HardwareConfig) []models.SensorReading {
|
||||
if hw == nil || len(hw.PowerSupply) == 0 {
|
||||
return nil
|
||||
}
|
||||
const (
|
||||
nominalV = 220.0
|
||||
minV = nominalV * 0.9 // 198V
|
||||
maxV = nominalV * 1.1 // 242V
|
||||
)
|
||||
out := make([]models.SensorReading, 0, len(hw.PowerSupply))
|
||||
for _, psu := range hw.PowerSupply {
|
||||
if psu.InputVoltage <= 0 {
|
||||
continue
|
||||
}
|
||||
name := "PSU " + strings.TrimSpace(psu.Slot) + " input voltage"
|
||||
if strings.TrimSpace(psu.Slot) == "" {
|
||||
name = "PSU input voltage"
|
||||
}
|
||||
status := "ok"
|
||||
if psu.InputVoltage < minV || psu.InputVoltage > maxV {
|
||||
status = "warn"
|
||||
}
|
||||
out = append(out, models.SensorReading{
|
||||
Name: name,
|
||||
Type: "voltage",
|
||||
Value: psu.InputVoltage,
|
||||
Unit: "V",
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user