From da3741ff0de59802353cf8704f456217ffb62527 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 25 Mar 2021 01:28:05 -0700 Subject: [PATCH] batch udm storage --- integrations/influxunifi/udm.go | 18 ++++++++++++++++++ integrations/influxunifi/uxg.go | 1 + 2 files changed, 19 insertions(+) diff --git a/integrations/influxunifi/udm.go b/integrations/influxunifi/udm.go index 37acb158..23ce740f 100644 --- a/integrations/influxunifi/udm.go +++ b/integrations/influxunifi/udm.go @@ -59,6 +59,23 @@ func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]interf return output } +func (u *InfluxUnifi) batchUDMstorage(storage []*unifi.Storage) map[string]interface{} { + output := make(map[string]interface{}) + + for _, t := range storage { + output["storage_"+t.Name+"_size"] = t.Size.Val + output["storage_"+t.Name+"_used"] = t.Used.Val + + if t.Size.Val != 0 && t.Used.Val != 0 && t.Used.Val < t.Size.Val { + output["storage_"+t.Name+"_pct"] = t.Used.Val / t.Size.Val * 100 //nolint:gomnd + } else { + output["storage_"+t.Name+"_pct"] = 0 + } + } + + return output +} + // batchUDM generates Unifi Gateway datapoints for InfluxDB. // These points can be passed directly to influx. func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { // nolint: funlen @@ -77,6 +94,7 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { // nolint: funlen "type": s.Type, } fields := Combine( + u.batchUDMstorage(s.Storage), u.batchUDMtemps(s.Temperatures), u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), u.batchSysStats(s.SysStats, s.SystemStats), diff --git a/integrations/influxunifi/uxg.go b/integrations/influxunifi/uxg.go index 208ad2a6..f81bb8b4 100644 --- a/integrations/influxunifi/uxg.go +++ b/integrations/influxunifi/uxg.go @@ -25,6 +25,7 @@ func (u *InfluxUnifi) batchUXG(r report, s *unifi.UXG) { // nolint: funlen "type": s.Type, } fields := Combine( + u.batchUDMstorage(s.Storage), u.batchUDMtemps(s.Temperatures), u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), u.batchSysStats(s.SysStats, s.SystemStats),