From 63bf858deade7dc3a6e33dc44eb45ab1fb70af68 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Thu, 28 Nov 2019 02:45:59 -0800 Subject: [PATCH] fixes --- promunifi/clients.go | 2 +- promunifi/collector.go | 10 ++++++++-- promunifi/site.go | 2 +- promunifi/uap.go | 3 +-- promunifi/udm.go | 2 +- promunifi/usg.go | 4 ++-- promunifi/usw.go | 4 ++-- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/promunifi/clients.go b/promunifi/clients.go index 7497fdc0..17229a2d 100644 --- a/promunifi/clients.go +++ b/promunifi/clients.go @@ -91,7 +91,7 @@ func (u *unifiCollector) exportClients(r *Report) { if r.Metrics == nil || len(r.Metrics.Clients) < 1 { return } - r.wg.Add(1) + r.wg.Add(one) go func() { defer r.wg.Done() for _, c := range r.Metrics.Clients { diff --git a/promunifi/collector.go b/promunifi/collector.go index 9bdbdd29..96da4aa8 100644 --- a/promunifi/collector.go +++ b/promunifi/collector.go @@ -12,6 +12,12 @@ import ( "golift.io/unifi" ) +// satisfy gomnd +const one = 1 + +// channel buffer, fits at least one batch. +const buffer = 50 + // UnifiCollectorCnfg defines the data needed to collect and report UniFi Metrics. type UnifiCollectorCnfg struct { // If non-empty, each of the collected metrics is prefixed by the @@ -104,7 +110,7 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) { // the current metrics (from another package) then exports them for prometheus. func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { var err error - r := &Report{Start: time.Now(), ch: make(chan []*metricExports, 50)} + r := &Report{Start: time.Now(), ch: make(chan []*metricExports, buffer)} defer func() { r.wg.Wait() close(r.ch) @@ -168,6 +174,6 @@ func (u *unifiCollector) exportMetrics(r *Report, ch chan<- prometheus.Metric) { } func (r *Report) send(m []*metricExports) { - r.wg.Add(1) + r.wg.Add(one) r.ch <- m } diff --git a/promunifi/site.go b/promunifi/site.go index 202fc57e..d39994e8 100644 --- a/promunifi/site.go +++ b/promunifi/site.go @@ -82,7 +82,7 @@ func (u *unifiCollector) exportSites(r *Report) { if r.Metrics == nil || len(r.Metrics.Sites) < 1 { return } - r.wg.Add(1) + r.wg.Add(one) go func() { defer r.wg.Done() for _, s := range r.Metrics.Sites { diff --git a/promunifi/uap.go b/promunifi/uap.go index a7815d3e..acb56e1f 100644 --- a/promunifi/uap.go +++ b/promunifi/uap.go @@ -217,7 +217,7 @@ func (u *unifiCollector) exportUAPs(r *Report) { if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.UAPs) < 1 { return } - r.wg.Add(1) + r.wg.Add(one) go func() { defer r.wg.Done() for _, a := range r.Metrics.Devices.UAPs { @@ -310,7 +310,6 @@ func (u *unifiCollector) exportUAPstat(r *Report, labels []string, a *unifi.Ap) } func (u *unifiCollector) exportVAPtable(r *Report, labels []string, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats) { - // vap table stats for _, v := range vt { if !v.Up.Val { diff --git a/promunifi/udm.go b/promunifi/udm.go index 1ebc5c27..5cc4142a 100644 --- a/promunifi/udm.go +++ b/promunifi/udm.go @@ -13,7 +13,7 @@ func (u *unifiCollector) exportUDMs(r *Report) { if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.UDMs) < 1 { return } - r.wg.Add(1) + r.wg.Add(one) go func() { defer r.wg.Done() for _, d := range r.Metrics.Devices.UDMs { diff --git a/promunifi/usg.go b/promunifi/usg.go index c21def5c..2a05a178 100644 --- a/promunifi/usg.go +++ b/promunifi/usg.go @@ -111,7 +111,7 @@ func (u *unifiCollector) exportUSGs(r *Report) { if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.USGs) < 1 { return } - r.wg.Add(1) + r.wg.Add(one) go func() { defer r.wg.Done() for _, s := range r.Metrics.Devices.USGs { @@ -179,7 +179,7 @@ func (u *unifiCollector) exportWANPorts(r *Report, labels []string, wans ...unif {u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, l}, {u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, l}, {u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, l}, - {u.USG.WanSpeed, prometheus.CounterValue, wan.Speed * 1000000, l}, + {u.USG.WanSpeed, prometheus.CounterValue, wan.Speed.Val * 1000000, l}, {u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, l}, {u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, l}, {u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, l}, diff --git a/promunifi/usw.go b/promunifi/usw.go index 8981604a..587fcb5a 100644 --- a/promunifi/usw.go +++ b/promunifi/usw.go @@ -139,7 +139,7 @@ func (u *unifiCollector) exportUSWs(r *Report) { if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.USWs) < 1 { return } - r.wg.Add(1) + r.wg.Add(one) go func() { defer r.wg.Done() for _, s := range r.Metrics.Devices.USWs { @@ -220,7 +220,7 @@ func (u *unifiCollector) exportPortTable(r *Report, pt []unifi.Port, labels []st {u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, l}, {u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, l}, {u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction, l}, - {u.USW.Speed, prometheus.GaugeValue, p.Speed * 1000000, l}, + {u.USW.Speed, prometheus.GaugeValue, p.Speed.Val * 1000000, l}, {u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, l}, {u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, l}, {u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, l},