From fa64b364c987714874de0cbb0331474bac8e45ca Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 1 Dec 2019 17:42:13 -0800 Subject: [PATCH] fix more ratios, combine export loops --- pkg/promunifi/collector.go | 55 +++++++++++++++++++++++++++++++++++--- pkg/promunifi/loops.go | 47 -------------------------------- pkg/promunifi/uap.go | 8 +++--- 3 files changed, 55 insertions(+), 55 deletions(-) delete mode 100644 pkg/promunifi/loops.go diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 42a821cf..1e06c0e5 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -118,10 +118,7 @@ func (u *promUnifi) Collect(ch chan<- prometheus.Metric) { // Pass Report interface into our collecting and reporting methods. go u.exportMetrics(r, ch) - for _, f := range []func(report){u.loopClients, u.loopSites, u.loopUAPs, u.loopUSWs, u.loopUSGs, u.loopUDMs} { - r.add() - go f(r) // in loops.go. - } + u.loopExports(r) } // This is closely tied to the method above with a sync.WaitGroup. @@ -148,3 +145,53 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) { r.done() } } + +func (u *promUnifi) loopExports(r report) { + r.add() + go func() { + defer r.done() + for _, s := range r.metrics().Sites { + u.exportSite(r, s) + } + }() + + r.add() + go func() { + defer r.done() + for _, d := range r.metrics().UAPs { + u.exportUAP(r, d) + } + }() + + r.add() + go func() { + defer r.done() + for _, d := range r.metrics().UDMs { + u.exportUDM(r, d) + } + }() + + r.add() + go func() { + defer r.done() + for _, d := range r.metrics().USGs { + u.exportUSG(r, d) + } + }() + + r.add() + go func() { + defer r.done() + for _, d := range r.metrics().USWs { + u.exportUSW(r, d) + } + }() + + r.add() + go func() { + defer r.done() + for _, c := range r.metrics().Clients { + u.exportClient(r, c) + } + }() +} diff --git a/pkg/promunifi/loops.go b/pkg/promunifi/loops.go deleted file mode 100644 index 9e086ec3..00000000 --- a/pkg/promunifi/loops.go +++ /dev/null @@ -1,47 +0,0 @@ -package promunifi - -// This file contains all the loop methods for each device type, clients and sites. -// Moved them here to consolate clutter from the other files. Also, if these change, -// they usually all change at once since they're pretty much the same code. - -func (u *promUnifi) loopSites(r report) { - defer r.done() - for _, s := range r.metrics().Sites { - u.exportSite(r, s) - } -} - -func (u *promUnifi) loopUAPs(r report) { - defer r.done() - for _, d := range r.metrics().UAPs { - u.exportUAP(r, d) - } -} - -func (u *promUnifi) loopUDMs(r report) { - defer r.done() - for _, d := range r.metrics().UDMs { - u.exportUDM(r, d) - } -} - -func (u *promUnifi) loopUSGs(r report) { - defer r.done() - for _, d := range r.metrics().USGs { - u.exportUSG(r, d) - } -} - -func (u *promUnifi) loopUSWs(r report) { - defer r.done() - for _, d := range r.metrics().USWs { - u.exportUSW(r, d) - } -} - -func (u *promUnifi) loopClients(r report) { - defer r.done() - for _, c := range r.metrics().Clients { - u.exportClient(r, c) - } -} diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index c5a4f699..f70b0ad2 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -103,10 +103,10 @@ func descUAP(ns string) *uap { WifiTxAttempts: prometheus.NewDesc(ns+"stat_wifi_transmit_attempts_total", "Wifi Transmission Attempts", labelA, nil), MacFilterRejections: prometheus.NewDesc(ns+"stat_mac_filter_rejects_total", "MAC Filter Rejections", labelA, nil), // N each - 1 per Virtual AP (VAP) - VAPCcq: prometheus.NewDesc(ns+"vap_ccq", "VAP Client Connection Quality", labelV, nil), + VAPCcq: prometheus.NewDesc(ns+"vap_ccq_ratio", "VAP Client Connection Quality", labelV, nil), VAPMacFilterRejections: prometheus.NewDesc(ns+"vap_mac_filter_rejects_total", "VAP MAC Filter Rejections", labelV, nil), VAPNumSatisfactionSta: prometheus.NewDesc(ns+"vap_satisfaction_stations", "VAP Number Satisifaction Stations", labelV, nil), - VAPAvgClientSignal: prometheus.NewDesc(ns+"vap_average_client_signal", "VAP Average Client Signal", labelV, nil), + VAPAvgClientSignal: prometheus.NewDesc(ns+"vap_average_client_signal_ratio", "VAP Average Client Signal", labelV, nil), VAPSatisfaction: prometheus.NewDesc(ns+"vap_satisfaction_ratio", "VAP Satisfaction", labelV, nil), VAPSatisfactionNow: prometheus.NewDesc(ns+"vap_satisfaction_now_ratio", "VAP Satisfaction Now", labelV, nil), VAPDNSAvgLatency: prometheus.NewDesc(ns+"vap_dns_latency_average_seconds", "VAP DNS Latency Average", labelV, nil), @@ -256,10 +256,10 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) labelV := append([]string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage}, labels[6:]...) r.send([]*metric{ - {u.UAP.VAPCcq, prometheus.GaugeValue, v.Ccq / 10, labelV}, + {u.UAP.VAPCcq, prometheus.GaugeValue, v.Ccq / 100.0, labelV}, {u.UAP.VAPMacFilterRejections, prometheus.CounterValue, v.MacFilterRejections, labelV}, {u.UAP.VAPNumSatisfactionSta, prometheus.GaugeValue, v.NumSatisfactionSta, labelV}, - {u.UAP.VAPAvgClientSignal, prometheus.GaugeValue, v.AvgClientSignal, labelV}, + {u.UAP.VAPAvgClientSignal, prometheus.GaugeValue, v.AvgClientSignal.Val / 100.0, labelV}, {u.UAP.VAPSatisfaction, prometheus.GaugeValue, v.Satisfaction.Val / 100.0, labelV}, {u.UAP.VAPSatisfactionNow, prometheus.GaugeValue, v.SatisfactionNow.Val / 100.0, labelV}, {u.UAP.VAPDNSAvgLatency, prometheus.GaugeValue, v.DNSAvgLatency.Val / 1000, labelV},