Merge pull request #144 from davidnewhall/dn2_ratios

Metrics Fixes
This commit is contained in:
David Newhall II 2019-12-01 19:36:13 -08:00 committed by GitHub
commit bb4d026ced
6 changed files with 58 additions and 61 deletions

View File

@ -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)

View File

@ -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".

View File

@ -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},

View File

@ -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)
}
}()
}

View File

@ -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)
}
}

View File

@ -103,7 +103,7 @@ 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),
@ -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, 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, 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},