From 5f0c3835938618c708b2803448b90682c973db51 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 1 Dec 2019 17:42:13 -0800 Subject: [PATCH 1/4] fix more ratios, combine export loops --- .../inputunifi/pkg/promunifi/collector.go | 55 +++++++++++++++++-- .../inputunifi/pkg/promunifi/loops.go | 47 ---------------- integrations/inputunifi/pkg/promunifi/uap.go | 8 +-- 3 files changed, 55 insertions(+), 55 deletions(-) delete mode 100644 integrations/inputunifi/pkg/promunifi/loops.go diff --git a/integrations/inputunifi/pkg/promunifi/collector.go b/integrations/inputunifi/pkg/promunifi/collector.go index 42a821cf..1e06c0e5 100644 --- a/integrations/inputunifi/pkg/promunifi/collector.go +++ b/integrations/inputunifi/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/integrations/inputunifi/pkg/promunifi/loops.go b/integrations/inputunifi/pkg/promunifi/loops.go deleted file mode 100644 index 9e086ec3..00000000 --- a/integrations/inputunifi/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/integrations/inputunifi/pkg/promunifi/uap.go b/integrations/inputunifi/pkg/promunifi/uap.go index c5a4f699..f70b0ad2 100644 --- a/integrations/inputunifi/pkg/promunifi/uap.go +++ b/integrations/inputunifi/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}, From 3760442b45ef3c76120097d7005de58291271ac9 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 1 Dec 2019 19:04:17 -0800 Subject: [PATCH 2/4] a couple more fixes --- integrations/inputunifi/pkg/promunifi/clients.go | 2 +- integrations/inputunifi/pkg/promunifi/uap.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integrations/inputunifi/pkg/promunifi/clients.go b/integrations/inputunifi/pkg/promunifi/clients.go index 3464614a..e4788deb 100644 --- a/integrations/inputunifi/pkg/promunifi/clients.go +++ b/integrations/inputunifi/pkg/promunifi/clients.go @@ -95,7 +95,7 @@ func (u *promUnifi) exportClient(r report, c *unifi.Client) { labelW[len(labelW)-1] = "false" r.send([]*metric{ {u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, labelW}, - {u.Client.CCQ, prometheus.GaugeValue, c.Ccq / 1000, labelW}, + {u.Client.CCQ, prometheus.GaugeValue, float64(c.Ccq) / 1000.0, labelW}, {u.Client.Satisfaction, prometheus.GaugeValue, c.Satisfaction.Val / 100.0, labelW}, {u.Client.Noise, prometheus.GaugeValue, c.Noise, labelW}, {u.Client.RoamCount, prometheus.CounterValue, c.RoamCount, labelW}, diff --git a/integrations/inputunifi/pkg/promunifi/uap.go b/integrations/inputunifi/pkg/promunifi/uap.go index f70b0ad2..daa19911 100644 --- a/integrations/inputunifi/pkg/promunifi/uap.go +++ b/integrations/inputunifi/pkg/promunifi/uap.go @@ -106,7 +106,7 @@ func descUAP(ns string) *uap { 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_ratio", "VAP Average Client Signal", labelV, nil), + VAPAvgClientSignal: prometheus.NewDesc(ns+"vap_average_client_signal", "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 / 100.0, labelV}, + {u.UAP.VAPCcq, prometheus.GaugeValue, float64(v.Ccq) / 1000.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.Val / 100.0, labelV}, + {u.UAP.VAPAvgClientSignal, prometheus.GaugeValue, v.AvgClientSignal.Val, 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}, From 2511d2e2f0a079abfadcd2df359f9fc258a6da33 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 1 Dec 2019 19:28:44 -0800 Subject: [PATCH 3/4] reference new dashes --- integrations/inputunifi/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/integrations/inputunifi/README.md b/integrations/inputunifi/README.md index b81ca7c9..37a2de36 100644 --- a/integrations/inputunifi/README.md +++ b/integrations/inputunifi/README.md @@ -2,7 +2,7 @@ [![discord](https://badgen.net/badge/icon/Discord?color=0011ff&label&icon=https://simpleicons.now.sh/discord/eee "Ubiquiti Discord")](https://discord.gg/KnyKYt2) [![twitter](https://badgen.net/twitter/follow/TwitchCaptain?icon=https://simpleicons.now.sh/twitter/0099ff&label=TwitchCaptain&color=0116ff "TwitchCaptain @ Twitter")](https://twitter.com/TwitchCaptain) -[![grafana](https://badgen.net/https/golift.io/bd/grafana/dashboard-downloads/10414,10415,10416,10417,10418,11314,11315?icon=https://simpleicons.now.sh/grafana/ED7F38&color=0011ff "Grafana Dashboard Downloads")](http://grafana.com/dashboards?search=unifi-poller) +[![grafana](https://badgen.net/https/golift.io/bd/grafana/dashboard-downloads/10414,10415,10416,10417,10418,11311,11312,11313,11314,11315?icon=https://simpleicons.now.sh/grafana/ED7F38&color=0011ff "Grafana Dashboard Downloads")](http://grafana.com/dashboards?search=unifi-poller) [![pulls](https://badgen.net/docker/pulls/golift/unifi-poller?icon=https://simpleicons.now.sh/docker/38B1ED&label=pulls&color=0011ff "Docker Pulls")](https://hub.docker.com/r/golift/unifi-poller) [![DLs](https://img.shields.io/github/downloads/davidnewhall/unifi-poller/total.svg?logo=github&color=0116ff "GitHub Downloads")](https://www.somsubhra.com/github-release-stats/?username=davidnewhall&repository=unifi-poller) @@ -15,9 +15,8 @@ Collect your UniFi controller data and report it to an InfluxDB instance, or export it for Prometheus collection. Prometheus support is [new](https://github.com/davidnewhall/unifi-poller/issues/88), and much of the documentation still needs to be updated; 11/30/2019. -[Seven Grafana Dashboards](http://grafana.com/dashboards?search=unifi-poller) -included; with screenshots. Five for InfluxDB and two for Prometheus, although -three more Prometheus dashboards are coming! +[Ten Grafana Dashboards](http://grafana.com/dashboards?search=unifi-poller) +included; with screenshots. Five for InfluxDB and five for Prometheus. ## Installation [See the Wiki!](https://github.com/davidnewhall/unifi-poller/wiki/Installation) From 7dbd1321b55f31de9ff8e4b34873bd452424a1bb Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 1 Dec 2019 19:29:40 -0800 Subject: [PATCH 4/4] update example --- integrations/inputunifi/examples/up.conf.example | 2 -- 1 file changed, 2 deletions(-) diff --git a/integrations/inputunifi/examples/up.conf.example b/integrations/inputunifi/examples/up.conf.example index c2e8cbbe..15454dad 100644 --- a/integrations/inputunifi/examples/up.conf.example +++ b/integrations/inputunifi/examples/up.conf.example @@ -33,8 +33,6 @@ quiet = false # # Mode "prometheus" opens an HTTP server on port 9130 and exports the metrics at # /metrics for polling collection by a prometheus server. This disables influxdb. -# IMPORTANT: The prometheus mode is still beta. -# Please help us test and provide your feedback on the github repo! mode = "influx" # This controls on which ip and port /metrics is exported when mode is "prometheus".