Expand UPS telemetry, charts and raw diagnostics with power estimates

This commit is contained in:
Maxim
2026-10-15 22:34:55 +03:00
parent 46bd6e8be6
commit ead9aaa713
6 changed files with 280 additions and 20 deletions

View File

@@ -28,6 +28,31 @@ func runHistoryCollector(collect func() (dashboardMetrics, error), store *Store)
func (s *Store) AddEntityMetrics(metrics dashboardMetrics) {
ts := time.Now().Unix()
u := metrics.UPS
usable := func(v *float64) *float64 {
if !u.Available || !u.CommunicationOK {
return nil
}
return v
}
for _, item := range []struct {
kind, name string
value *float64
}{
{"ups-voltage", "Вход", u.InputVoltage}, {"ups-voltage", "Выход", u.OutputVoltage},
{"ups-battery", "Батарея", u.BatteryVoltage}, {"ups-runtime", "Автономность", u.RuntimeSeconds},
{"ups-frequency", "Частота", u.InputFrequency},
} {
s.AddEntityHistory(item.kind, item.name, ts, usable(item.value), nil)
}
var measured, estimated *float64
if u.PowerEstimated {
estimated = u.Power
} else {
measured = u.Power
}
s.AddEntityHistory("ups-power", "Измеренная", ts, usable(measured), nil)
s.AddEntityHistory("ups-power", "Расчётная ≈", ts, usable(estimated), nil)
for _, p := range metrics.ZFS.Pools {
v := p.CapacityPercent
s.AddEntityHistory("zfs", p.Name, ts, &v, nil)
@@ -99,6 +124,10 @@ func historyPointFromMetrics(metrics dashboardMetrics) HistoryPoint {
NetworkTransmit: metrics.Network.TransmitPerSec, UPSCharge: metrics.UPS.ChargePercent,
UPSLoad: metrics.UPS.LoadPercent,
}
if !metrics.UPS.Available || !metrics.UPS.CommunicationOK {
point.UPSCharge = nil
point.UPSLoad = nil
}
if temperature := cpuTemperature(metrics.CPU.Temperatures); temperature != nil {
point.CPUTemperature = *temperature
}