From 4d485769d6f5a0d42a7db7d4b88c6cdc11d05112 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 00:19:47 -0800 Subject: [PATCH 01/14] move pieces into methods --- pkg/poller/unifi.go | 5 +- pkg/promunifi/clients.go | 74 ++++++------ pkg/promunifi/collector.go | 17 ++- pkg/promunifi/report.go | 6 + pkg/promunifi/site.go | 80 ++++++------- pkg/promunifi/uap.go | 228 +++++++++++++++++-------------------- pkg/promunifi/udm.go | 77 ++++++++----- pkg/promunifi/usg.go | 85 ++++++-------- pkg/promunifi/usw.go | 112 +++++++++--------- 9 files changed, 327 insertions(+), 357 deletions(-) diff --git a/pkg/poller/unifi.go b/pkg/poller/unifi.go index ebd01f79..73708243 100644 --- a/pkg/poller/unifi.go +++ b/pkg/poller/unifi.go @@ -101,10 +101,7 @@ func (u *UnifiPoller) AugmentMetrics(metrics *metrics.Metrics) { for _, r := range metrics.USWs { devices[r.Mac] = r.Name } - for i, r := range metrics.UDMs { - if r.Model == "UDMPRO" { - metrics.UDMs[i].Type = "udmp" - } + for _, r := range metrics.UDMs { devices[r.Mac] = r.Name } // These come blank, so set them here. diff --git a/pkg/promunifi/clients.go b/pkg/promunifi/clients.go index e4788deb..c5477ac3 100644 --- a/pkg/promunifi/clients.go +++ b/pkg/promunifi/clients.go @@ -24,7 +24,7 @@ type uclient struct { TxRetries *prometheus.Desc TxPower *prometheus.Desc TxRate *prometheus.Desc - Uptime *prometheus.Desc + Info *prometheus.Desc WifiTxAttempts *prometheus.Desc WiredRxBytes *prometheus.Desc WiredRxBytesR *prometheus.Desc @@ -63,7 +63,7 @@ func descClient(ns string) *uclient { TxPower: prometheus.NewDesc(ns+"radio_transmit_power_dbm", "Client Transmit Power", labelW, nil), TxRate: prometheus.NewDesc(ns+"radio_transmit_rate_bps", "Client Transmit Rate", labelW, nil), WifiTxAttempts: prometheus.NewDesc(ns+"wifi_attempts_transmit_total", "Client Wifi Transmit Attempts", labelW, nil), - Uptime: prometheus.NewDesc(ns+"uptime_seconds", "Client Uptime", labelW, nil), + Info: prometheus.NewDesc(ns+"uptime_seconds", "Client Uptime", labelW, nil), // XXX: re-purpose for info tags. /* needs more "looking into" DpiStatsApp: prometheus.NewDesc(ns+"dpi_stats_app", "Client DPI Stats App", labels, nil), DpiStatsCat: prometheus.NewDesc(ns+"dpi_stats_cat", "Client DPI Stats Cat", labels, nil), @@ -83,47 +83,45 @@ func (u *promUnifi) exportClient(r report, c *unifi.Client) { labels[len(labels)-1] = "true" labelW[len(labelW)-1] = "true" r.send([]*metric{ - {u.Client.RxBytes, prometheus.CounterValue, c.WiredRxBytes, labels}, - {u.Client.RxBytesR, prometheus.GaugeValue, c.WiredRxBytesR, labels}, - {u.Client.RxPackets, prometheus.CounterValue, c.WiredRxPackets, labels}, - {u.Client.TxBytes, prometheus.CounterValue, c.WiredTxBytes, labels}, - {u.Client.TxBytesR, prometheus.GaugeValue, c.WiredTxBytesR, labels}, - {u.Client.TxPackets, prometheus.CounterValue, c.WiredTxPackets, labels}, + {u.Client.RxBytes, counter, c.WiredRxBytes, labels}, + {u.Client.RxBytesR, gauge, c.WiredRxBytesR, labels}, + {u.Client.RxPackets, counter, c.WiredRxPackets, labels}, + {u.Client.TxBytes, counter, c.WiredTxBytes, labels}, + {u.Client.TxBytesR, gauge, c.WiredTxBytesR, labels}, + {u.Client.TxPackets, counter, c.WiredTxPackets, labels}, }) } else { labels[len(labels)-1] = "false" labelW[len(labelW)-1] = "false" r.send([]*metric{ - {u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, 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}, - {u.Client.RSSI, prometheus.GaugeValue, c.Rssi, labelW}, - {u.Client.Signal, prometheus.GaugeValue, c.Signal, labelW}, - {u.Client.TxPower, prometheus.GaugeValue, c.TxPower, labelW}, - {u.Client.TxRate, prometheus.GaugeValue, c.TxRate * 1000, labelW}, - {u.Client.WifiTxAttempts, prometheus.CounterValue, c.WifiTxAttempts, labelW}, - {u.Client.RxRate, prometheus.GaugeValue, c.RxRate * 1000, labelW}, - {u.Client.TxRetries, prometheus.CounterValue, c.TxRetries, labels}, - {u.Client.TxBytes, prometheus.CounterValue, c.TxBytes, labels}, - {u.Client.TxBytesR, prometheus.GaugeValue, c.TxBytesR, labels}, - {u.Client.TxPackets, prometheus.CounterValue, c.TxPackets, labels}, - {u.Client.RxBytes, prometheus.CounterValue, c.RxBytes, labels}, - {u.Client.RxBytesR, prometheus.GaugeValue, c.RxBytesR, labels}, - {u.Client.RxPackets, prometheus.CounterValue, c.RxPackets, labels}, - {u.Client.BytesR, prometheus.GaugeValue, c.BytesR, labelW}, + {u.Client.Anomalies, counter, c.Anomalies, labelW}, + {u.Client.CCQ, gauge, float64(c.Ccq) / 1000.0, labelW}, + {u.Client.Satisfaction, gauge, c.Satisfaction.Val / 100.0, labelW}, + {u.Client.Noise, gauge, c.Noise, labelW}, + {u.Client.RoamCount, counter, c.RoamCount, labelW}, + {u.Client.RSSI, gauge, c.Rssi, labelW}, + {u.Client.Signal, gauge, c.Signal, labelW}, + {u.Client.TxPower, gauge, c.TxPower, labelW}, + {u.Client.TxRate, gauge, c.TxRate * 1000, labelW}, + {u.Client.WifiTxAttempts, counter, c.WifiTxAttempts, labelW}, + {u.Client.RxRate, gauge, c.RxRate * 1000, labelW}, + {u.Client.TxRetries, counter, c.TxRetries, labels}, + {u.Client.TxBytes, counter, c.TxBytes, labels}, + {u.Client.TxBytesR, gauge, c.TxBytesR, labels}, + {u.Client.TxPackets, counter, c.TxPackets, labels}, + {u.Client.RxBytes, counter, c.RxBytes, labels}, + {u.Client.RxBytesR, gauge, c.RxBytesR, labels}, + {u.Client.RxPackets, counter, c.RxPackets, labels}, + {u.Client.BytesR, gauge, c.BytesR, labelW}, }) } - r.send([]*metric{ - {u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labelW}, - /* needs more "looking into" - {u.Client.DpiStatsApp, prometheus.GaugeValue, c.DpiStats.App, labels}, - {u.Client.DpiStatsCat, prometheus.GaugeValue, c.DpiStats.Cat, labels}, - {u.Client.DpiStatsRxBytes, prometheus.CounterValue, c.DpiStats.RxBytes, labels}, - {u.Client.DpiStatsRxPackets, prometheus.CounterValue, c.DpiStats.RxPackets, labels}, - {u.Client.DpiStatsTxBytes, prometheus.CounterValue, c.DpiStats.TxBytes, labels}, - {u.Client.DpiStatsTxPackets, prometheus.CounterValue, c.DpiStats.TxPackets, labels}, - */ - }) + r.sendone(u.Client.Info, gauge, c.Uptime, labelW) + /* needs more "looking into" + {u.Client.DpiStatsApp, gauge, c.DpiStats.App, labels}, + {u.Client.DpiStatsCat, gauge, c.DpiStats.Cat, labels}, + {u.Client.DpiStatsRxBytes, counter, c.DpiStats.RxBytes, labels}, + {u.Client.DpiStatsRxPackets, counter, c.DpiStats.RxPackets, labels}, + {u.Client.DpiStatsTxBytes, counter, c.DpiStats.TxBytes, labels}, + {u.Client.DpiStatsTxPackets, counter, c.DpiStats.TxPackets, labels}, + */ } diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 1e06c0e5..3116c2db 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -16,6 +16,10 @@ import ( // channel buffer, fits at least one batch. const buffer = 50 +// simply fewer letters. +const counter = prometheus.CounterValue +const gauge = prometheus.GaugeValue + // 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 @@ -147,10 +151,11 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) { } func (u *promUnifi) loopExports(r report) { + m := r.metrics() r.add() go func() { defer r.done() - for _, s := range r.metrics().Sites { + for _, s := range m.Sites { u.exportSite(r, s) } }() @@ -158,7 +163,7 @@ func (u *promUnifi) loopExports(r report) { r.add() go func() { defer r.done() - for _, d := range r.metrics().UAPs { + for _, d := range m.UAPs { u.exportUAP(r, d) } }() @@ -166,7 +171,7 @@ func (u *promUnifi) loopExports(r report) { r.add() go func() { defer r.done() - for _, d := range r.metrics().UDMs { + for _, d := range m.UDMs { u.exportUDM(r, d) } }() @@ -174,7 +179,7 @@ func (u *promUnifi) loopExports(r report) { r.add() go func() { defer r.done() - for _, d := range r.metrics().USGs { + for _, d := range m.USGs { u.exportUSG(r, d) } }() @@ -182,7 +187,7 @@ func (u *promUnifi) loopExports(r report) { r.add() go func() { defer r.done() - for _, d := range r.metrics().USWs { + for _, d := range m.USWs { u.exportUSW(r, d) } }() @@ -190,7 +195,7 @@ func (u *promUnifi) loopExports(r report) { r.add() go func() { defer r.done() - for _, c := range r.metrics().Clients { + for _, c := range m.Clients { u.exportClient(r, c) } }() diff --git a/pkg/promunifi/report.go b/pkg/promunifi/report.go index 4262a546..3fc36466 100644 --- a/pkg/promunifi/report.go +++ b/pkg/promunifi/report.go @@ -16,6 +16,7 @@ type report interface { add() done() send([]*metric) + sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string) metrics() *metrics.Metrics channel() chan []*metric report(descs map[*prometheus.Desc]bool) @@ -34,6 +35,11 @@ func (r *Report) done() { r.wg.Add(-one) } +func (r *Report) sendone(d *prometheus.Desc, tv prometheus.ValueType, i interface{}, s []string) { + r.wg.Add(one) + r.ch <- []*metric{{d, tv, i, s}} +} + func (r *Report) send(m []*metric) { r.wg.Add(one) r.ch <- m diff --git a/pkg/promunifi/site.go b/pkg/promunifi/site.go index 5d7ff9c3..c15db2c6 100644 --- a/pkg/promunifi/site.go +++ b/pkg/promunifi/site.go @@ -70,62 +70,62 @@ func (u *promUnifi) exportSite(r report, s *unifi.Site) { switch h.Subsystem { case "www": r.send([]*metric{ - {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels}, - {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels}, - {u.Site.Uptime, prometheus.GaugeValue, h.Uptime, labels}, - {u.Site.Latency, prometheus.GaugeValue, h.Latency.Val / 1000, labels}, - {u.Site.XputUp, prometheus.GaugeValue, h.XputUp, labels}, - {u.Site.XputDown, prometheus.GaugeValue, h.XputDown, labels}, - {u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing, labels}, - {u.Site.Drops, prometheus.CounterValue, h.Drops, labels}, + {u.Site.TxBytesR, gauge, h.TxBytesR, labels}, + {u.Site.RxBytesR, gauge, h.RxBytesR, labels}, + {u.Site.Uptime, gauge, h.Uptime, labels}, + {u.Site.Latency, gauge, h.Latency.Val / 1000, labels}, + {u.Site.XputUp, gauge, h.XputUp, labels}, + {u.Site.XputDown, gauge, h.XputDown, labels}, + {u.Site.SpeedtestPing, gauge, h.SpeedtestPing, labels}, + {u.Site.Drops, counter, h.Drops, labels}, }) case "wlan": r.send([]*metric{ - {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels}, - {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels}, - {u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, labels}, - {u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, labels}, - {u.Site.NumPending, prometheus.GaugeValue, h.NumPending, labels}, - {u.Site.NumUser, prometheus.GaugeValue, h.NumUser, labels}, - {u.Site.NumGuest, prometheus.GaugeValue, h.NumGuest, labels}, - {u.Site.NumIot, prometheus.GaugeValue, h.NumIot, labels}, - {u.Site.NumAp, prometheus.GaugeValue, h.NumAp, labels}, - {u.Site.NumDisabled, prometheus.GaugeValue, h.NumDisabled, labels}, + {u.Site.TxBytesR, gauge, h.TxBytesR, labels}, + {u.Site.RxBytesR, gauge, h.RxBytesR, labels}, + {u.Site.NumAdopted, gauge, h.NumAdopted, labels}, + {u.Site.NumDisconnected, gauge, h.NumDisconnected, labels}, + {u.Site.NumPending, gauge, h.NumPending, labels}, + {u.Site.NumUser, gauge, h.NumUser, labels}, + {u.Site.NumGuest, gauge, h.NumGuest, labels}, + {u.Site.NumIot, gauge, h.NumIot, labels}, + {u.Site.NumAp, gauge, h.NumAp, labels}, + {u.Site.NumDisabled, gauge, h.NumDisabled, labels}, }) case "wan": r.send([]*metric{ - {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels}, - {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels}, - {u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, labels}, - {u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, labels}, - {u.Site.NumPending, prometheus.GaugeValue, h.NumPending, labels}, - {u.Site.NumGw, prometheus.GaugeValue, h.NumGw, labels}, - {u.Site.NumSta, prometheus.GaugeValue, h.NumSta, labels}, + {u.Site.TxBytesR, gauge, h.TxBytesR, labels}, + {u.Site.RxBytesR, gauge, h.RxBytesR, labels}, + {u.Site.NumAdopted, gauge, h.NumAdopted, labels}, + {u.Site.NumDisconnected, gauge, h.NumDisconnected, labels}, + {u.Site.NumPending, gauge, h.NumPending, labels}, + {u.Site.NumGw, gauge, h.NumGw, labels}, + {u.Site.NumSta, gauge, h.NumSta, labels}, }) case "lan": r.send([]*metric{ - {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels}, - {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels}, - {u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, labels}, - {u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, labels}, - {u.Site.NumPending, prometheus.GaugeValue, h.NumPending, labels}, - {u.Site.NumUser, prometheus.GaugeValue, h.NumUser, labels}, - {u.Site.NumGuest, prometheus.GaugeValue, h.NumGuest, labels}, - {u.Site.NumIot, prometheus.GaugeValue, h.NumIot, labels}, - {u.Site.NumSw, prometheus.GaugeValue, h.NumSw, labels}, + {u.Site.TxBytesR, gauge, h.TxBytesR, labels}, + {u.Site.RxBytesR, gauge, h.RxBytesR, labels}, + {u.Site.NumAdopted, gauge, h.NumAdopted, labels}, + {u.Site.NumDisconnected, gauge, h.NumDisconnected, labels}, + {u.Site.NumPending, gauge, h.NumPending, labels}, + {u.Site.NumUser, gauge, h.NumUser, labels}, + {u.Site.NumGuest, gauge, h.NumGuest, labels}, + {u.Site.NumIot, gauge, h.NumIot, labels}, + {u.Site.NumSw, gauge, h.NumSw, labels}, }) case "vpn": r.send([]*metric{ - {u.Site.RemoteUserNumActive, prometheus.GaugeValue, h.RemoteUserNumActive, labels}, - {u.Site.RemoteUserNumInactive, prometheus.GaugeValue, h.RemoteUserNumInactive, labels}, - {u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes, labels}, - {u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes, labels}, - {u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets, labels}, - {u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets, labels}, + {u.Site.RemoteUserNumActive, gauge, h.RemoteUserNumActive, labels}, + {u.Site.RemoteUserNumInactive, gauge, h.RemoteUserNumInactive, labels}, + {u.Site.RemoteUserRxBytes, counter, h.RemoteUserRxBytes, labels}, + {u.Site.RemoteUserTxBytes, counter, h.RemoteUserTxBytes, labels}, + {u.Site.RemoteUserRxPackets, counter, h.RemoteUserRxPackets, labels}, + {u.Site.RemoteUserTxPackets, counter, h.RemoteUserTxPackets, labels}, }) } } diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index 1faf9203..e010c86d 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -161,88 +161,62 @@ func descUAP(ns string) *uap { func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} - - // Wireless System Data. - r.send([]*metric{ - {u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)}, - {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, - {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, - {u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels}, - {u.Device.BytesD, prometheus.CounterValue, d.BytesD, labels}, // not sure if these 3 Ds are counters or gauges. - {u.Device.TxBytesD, prometheus.CounterValue, d.TxBytesD, labels}, // not sure if these 3 Ds are counters or gauges. - {u.Device.RxBytesD, prometheus.CounterValue, d.RxBytesD, labels}, // not sure if these 3 Ds are counters or gauges. - {u.Device.BytesR, prometheus.GaugeValue, d.BytesR, labels}, - {u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, append(labels, "user")}, - {u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, append(labels, "guest")}, - {u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels}, - {u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels}, - {u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels}, - {u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels}, - {u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels}, - {u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels}, - {u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels}, - {u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels}, - }) - - u.exportUAPstats(r, labels, d.Stat.Ap) + u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR) u.exportVAPtable(r, labels, d.VapTable) - u.exportRadtable(r, labels, d.RadioTable, d.RadioTableStats) + u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) + u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) + u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta) + u.exportRADtable(r, labels, d.RadioTable, d.RadioTableStats) + r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) } -func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap) { - // labelA := append([]string{"all"}, labels[2:]...) +func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap, bytes ...unifi.FlexInt) { labelU := []string{"user", labels[1], labels[2]} labelG := []string{"guest", labels[1], labels[2]} + if len(bytes) > 0 { + r.send([]*metric{ + // ap only stuff. + {u.Device.BytesD, counter, bytes[0], labels}, // not sure if these 3 Ds are counters or gauges. + {u.Device.TxBytesD, counter, bytes[1], labels}, // not sure if these 3 Ds are counters or gauges. + {u.Device.RxBytesD, counter, bytes[2], labels}, // not sure if these 3 Ds are counters or gauges. + {u.Device.BytesR, gauge, bytes[3], labels}, // only UAP has this one, and those ^ weird. + }) + } r.send([]*metric{ - /* // all - {u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.WifiTxDropped, labelA}, - {u.UAP.ApRxErrors, prometheus.CounterValue, ap.RxErrors, labelA}, - {u.UAP.ApRxDropped, prometheus.CounterValue, ap.RxDropped, labelA}, - {u.UAP.ApRxFrags, prometheus.CounterValue, ap.RxFrags, labelA}, - {u.UAP.ApRxCrypts, prometheus.CounterValue, ap.RxCrypts, labelA}, - {u.UAP.ApTxPackets, prometheus.CounterValue, ap.TxPackets, labelA}, - {u.UAP.ApTxBytes, prometheus.CounterValue, ap.TxBytes, labelA}, - {u.UAP.ApTxErrors, prometheus.CounterValue, ap.TxErrors, labelA}, - {u.UAP.ApTxDropped, prometheus.CounterValue, ap.TxDropped, labelA}, - {u.UAP.ApTxRetries, prometheus.CounterValue, ap.TxRetries, labelA}, - {u.UAP.ApRxPackets, prometheus.CounterValue, ap.RxPackets, labelA}, - {u.UAP.ApRxBytes, prometheus.CounterValue, ap.RxBytes, labelA}, - {u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.WifiTxAttempts, labelA}, - {u.UAP.MacFilterRejections, prometheus.CounterValue, ap.MacFilterRejections, labelA}, - */ // user - {u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.UserWifiTxDropped, labelU}, - {u.UAP.ApRxErrors, prometheus.CounterValue, ap.UserRxErrors, labelU}, - {u.UAP.ApRxDropped, prometheus.CounterValue, ap.UserRxDropped, labelU}, - {u.UAP.ApRxFrags, prometheus.CounterValue, ap.UserRxFrags, labelU}, - {u.UAP.ApRxCrypts, prometheus.CounterValue, ap.UserRxCrypts, labelU}, - {u.UAP.ApTxPackets, prometheus.CounterValue, ap.UserTxPackets, labelU}, - {u.UAP.ApTxBytes, prometheus.CounterValue, ap.UserTxBytes, labelU}, - {u.UAP.ApTxErrors, prometheus.CounterValue, ap.UserTxErrors, labelU}, - {u.UAP.ApTxDropped, prometheus.CounterValue, ap.UserTxDropped, labelU}, - {u.UAP.ApTxRetries, prometheus.CounterValue, ap.UserTxRetries, labelU}, - {u.UAP.ApRxPackets, prometheus.CounterValue, ap.UserRxPackets, labelU}, - {u.UAP.ApRxBytes, prometheus.CounterValue, ap.UserRxBytes, labelU}, - {u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.UserWifiTxAttempts, labelU}, - {u.UAP.MacFilterRejections, prometheus.CounterValue, ap.UserMacFilterRejections, labelU}, + {u.UAP.ApWifiTxDropped, counter, ap.UserWifiTxDropped, labelU}, + {u.UAP.ApRxErrors, counter, ap.UserRxErrors, labelU}, + {u.UAP.ApRxDropped, counter, ap.UserRxDropped, labelU}, + {u.UAP.ApRxFrags, counter, ap.UserRxFrags, labelU}, + {u.UAP.ApRxCrypts, counter, ap.UserRxCrypts, labelU}, + {u.UAP.ApTxPackets, counter, ap.UserTxPackets, labelU}, + {u.UAP.ApTxBytes, counter, ap.UserTxBytes, labelU}, + {u.UAP.ApTxErrors, counter, ap.UserTxErrors, labelU}, + {u.UAP.ApTxDropped, counter, ap.UserTxDropped, labelU}, + {u.UAP.ApTxRetries, counter, ap.UserTxRetries, labelU}, + {u.UAP.ApRxPackets, counter, ap.UserRxPackets, labelU}, + {u.UAP.ApRxBytes, counter, ap.UserRxBytes, labelU}, + {u.UAP.WifiTxAttempts, counter, ap.UserWifiTxAttempts, labelU}, + {u.UAP.MacFilterRejections, counter, ap.UserMacFilterRejections, labelU}, // guest - {u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.GuestWifiTxDropped, labelG}, - {u.UAP.ApRxErrors, prometheus.CounterValue, ap.GuestRxErrors, labelG}, - {u.UAP.ApRxDropped, prometheus.CounterValue, ap.GuestRxDropped, labelG}, - {u.UAP.ApRxFrags, prometheus.CounterValue, ap.GuestRxFrags, labelG}, - {u.UAP.ApRxCrypts, prometheus.CounterValue, ap.GuestRxCrypts, labelG}, - {u.UAP.ApTxPackets, prometheus.CounterValue, ap.GuestTxPackets, labelG}, - {u.UAP.ApTxBytes, prometheus.CounterValue, ap.GuestTxBytes, labelG}, - {u.UAP.ApTxErrors, prometheus.CounterValue, ap.GuestTxErrors, labelG}, - {u.UAP.ApTxDropped, prometheus.CounterValue, ap.GuestTxDropped, labelG}, - {u.UAP.ApTxRetries, prometheus.CounterValue, ap.GuestTxRetries, labelG}, - {u.UAP.ApRxPackets, prometheus.CounterValue, ap.GuestRxPackets, labelG}, - {u.UAP.ApRxBytes, prometheus.CounterValue, ap.GuestRxBytes, labelG}, - {u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.GuestWifiTxAttempts, labelG}, - {u.UAP.MacFilterRejections, prometheus.CounterValue, ap.GuestMacFilterRejections, labelG}, + {u.UAP.ApWifiTxDropped, counter, ap.GuestWifiTxDropped, labelG}, + {u.UAP.ApRxErrors, counter, ap.GuestRxErrors, labelG}, + {u.UAP.ApRxDropped, counter, ap.GuestRxDropped, labelG}, + {u.UAP.ApRxFrags, counter, ap.GuestRxFrags, labelG}, + {u.UAP.ApRxCrypts, counter, ap.GuestRxCrypts, labelG}, + {u.UAP.ApTxPackets, counter, ap.GuestTxPackets, labelG}, + {u.UAP.ApTxBytes, counter, ap.GuestTxBytes, labelG}, + {u.UAP.ApTxErrors, counter, ap.GuestTxErrors, labelG}, + {u.UAP.ApTxDropped, counter, ap.GuestTxDropped, labelG}, + {u.UAP.ApTxRetries, counter, ap.GuestTxRetries, labelG}, + {u.UAP.ApRxPackets, counter, ap.GuestRxPackets, labelG}, + {u.UAP.ApRxBytes, counter, ap.GuestRxBytes, labelG}, + {u.UAP.WifiTxAttempts, counter, ap.GuestWifiTxAttempts, labelG}, + {u.UAP.MacFilterRejections, counter, ap.GuestMacFilterRejections, labelG}, }) } +// UAP VAP Table func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) { // vap table stats for _, v := range vt { @@ -252,60 +226,61 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) labelV := []string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage, labels[1], labels[2]} r.send([]*metric{ - {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, 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}, - {u.UAP.VAPRxBytes, prometheus.CounterValue, v.RxBytes, labelV}, - {u.UAP.VAPRxCrypts, prometheus.CounterValue, v.RxCrypts, labelV}, - {u.UAP.VAPRxDropped, prometheus.CounterValue, v.RxDropped, labelV}, - {u.UAP.VAPRxErrors, prometheus.CounterValue, v.RxErrors, labelV}, - {u.UAP.VAPRxFrags, prometheus.CounterValue, v.RxFrags, labelV}, - {u.UAP.VAPRxNwids, prometheus.CounterValue, v.RxNwids, labelV}, - {u.UAP.VAPRxPackets, prometheus.CounterValue, v.RxPackets, labelV}, - {u.UAP.VAPTxBytes, prometheus.CounterValue, v.TxBytes, labelV}, - {u.UAP.VAPTxDropped, prometheus.CounterValue, v.TxDropped, labelV}, - {u.UAP.VAPTxErrors, prometheus.CounterValue, v.TxErrors, labelV}, - {u.UAP.VAPTxPackets, prometheus.CounterValue, v.TxPackets, labelV}, - {u.UAP.VAPTxPower, prometheus.GaugeValue, v.TxPower, labelV}, - {u.UAP.VAPTxRetries, prometheus.CounterValue, v.TxRetries, labelV}, - {u.UAP.VAPTxCombinedRetries, prometheus.CounterValue, v.TxCombinedRetries, labelV}, - {u.UAP.VAPTxDataMpduBytes, prometheus.CounterValue, v.TxDataMpduBytes, labelV}, - {u.UAP.VAPTxRtsRetries, prometheus.CounterValue, v.TxRtsRetries, labelV}, - {u.UAP.VAPTxTotal, prometheus.CounterValue, v.TxTotal, labelV}, - {u.UAP.VAPTxGoodbytes, prometheus.CounterValue, v.TxTCPStats.Goodbytes, labelV}, - {u.UAP.VAPTxLatAvg, prometheus.GaugeValue, v.TxTCPStats.LatAvg.Val / 1000, labelV}, - {u.UAP.VAPTxLatMax, prometheus.GaugeValue, v.TxTCPStats.LatMax.Val / 1000, labelV}, - {u.UAP.VAPTxLatMin, prometheus.GaugeValue, v.TxTCPStats.LatMin.Val / 1000, labelV}, - {u.UAP.VAPRxGoodbytes, prometheus.CounterValue, v.RxTCPStats.Goodbytes, labelV}, - {u.UAP.VAPRxLatAvg, prometheus.GaugeValue, v.RxTCPStats.LatAvg.Val / 1000, labelV}, - {u.UAP.VAPRxLatMax, prometheus.GaugeValue, v.RxTCPStats.LatMax.Val / 1000, labelV}, - {u.UAP.VAPRxLatMin, prometheus.GaugeValue, v.RxTCPStats.LatMin.Val / 1000, labelV}, - {u.UAP.VAPWifiTxLatencyMovAvg, prometheus.GaugeValue, v.WifiTxLatencyMov.Avg.Val / 1000, labelV}, - {u.UAP.VAPWifiTxLatencyMovMax, prometheus.GaugeValue, v.WifiTxLatencyMov.Max.Val / 1000, labelV}, - {u.UAP.VAPWifiTxLatencyMovMin, prometheus.GaugeValue, v.WifiTxLatencyMov.Min.Val / 1000, labelV}, - {u.UAP.VAPWifiTxLatencyMovTotal, prometheus.CounterValue, v.WifiTxLatencyMov.Total, labelV}, // not sure if gauge or counter. - {u.UAP.VAPWifiTxLatencyMovCount, prometheus.CounterValue, v.WifiTxLatencyMov.TotalCount, labelV}, // not sure if gauge or counter. + {u.UAP.VAPCcq, gauge, float64(v.Ccq) / 1000.0, labelV}, + {u.UAP.VAPMacFilterRejections, counter, v.MacFilterRejections, labelV}, + {u.UAP.VAPNumSatisfactionSta, gauge, v.NumSatisfactionSta, labelV}, + {u.UAP.VAPAvgClientSignal, gauge, v.AvgClientSignal.Val, labelV}, + {u.UAP.VAPSatisfaction, gauge, v.Satisfaction.Val / 100.0, labelV}, + {u.UAP.VAPSatisfactionNow, gauge, v.SatisfactionNow.Val / 100.0, labelV}, + {u.UAP.VAPDNSAvgLatency, gauge, v.DNSAvgLatency.Val / 1000, labelV}, + {u.UAP.VAPRxBytes, counter, v.RxBytes, labelV}, + {u.UAP.VAPRxCrypts, counter, v.RxCrypts, labelV}, + {u.UAP.VAPRxDropped, counter, v.RxDropped, labelV}, + {u.UAP.VAPRxErrors, counter, v.RxErrors, labelV}, + {u.UAP.VAPRxFrags, counter, v.RxFrags, labelV}, + {u.UAP.VAPRxNwids, counter, v.RxNwids, labelV}, + {u.UAP.VAPRxPackets, counter, v.RxPackets, labelV}, + {u.UAP.VAPTxBytes, counter, v.TxBytes, labelV}, + {u.UAP.VAPTxDropped, counter, v.TxDropped, labelV}, + {u.UAP.VAPTxErrors, counter, v.TxErrors, labelV}, + {u.UAP.VAPTxPackets, counter, v.TxPackets, labelV}, + {u.UAP.VAPTxPower, gauge, v.TxPower, labelV}, + {u.UAP.VAPTxRetries, counter, v.TxRetries, labelV}, + {u.UAP.VAPTxCombinedRetries, counter, v.TxCombinedRetries, labelV}, + {u.UAP.VAPTxDataMpduBytes, counter, v.TxDataMpduBytes, labelV}, + {u.UAP.VAPTxRtsRetries, counter, v.TxRtsRetries, labelV}, + {u.UAP.VAPTxTotal, counter, v.TxTotal, labelV}, + {u.UAP.VAPTxGoodbytes, counter, v.TxTCPStats.Goodbytes, labelV}, + {u.UAP.VAPTxLatAvg, gauge, v.TxTCPStats.LatAvg.Val / 1000, labelV}, + {u.UAP.VAPTxLatMax, gauge, v.TxTCPStats.LatMax.Val / 1000, labelV}, + {u.UAP.VAPTxLatMin, gauge, v.TxTCPStats.LatMin.Val / 1000, labelV}, + {u.UAP.VAPRxGoodbytes, counter, v.RxTCPStats.Goodbytes, labelV}, + {u.UAP.VAPRxLatAvg, gauge, v.RxTCPStats.LatAvg.Val / 1000, labelV}, + {u.UAP.VAPRxLatMax, gauge, v.RxTCPStats.LatMax.Val / 1000, labelV}, + {u.UAP.VAPRxLatMin, gauge, v.RxTCPStats.LatMin.Val / 1000, labelV}, + {u.UAP.VAPWifiTxLatencyMovAvg, gauge, v.WifiTxLatencyMov.Avg.Val / 1000, labelV}, + {u.UAP.VAPWifiTxLatencyMovMax, gauge, v.WifiTxLatencyMov.Max.Val / 1000, labelV}, + {u.UAP.VAPWifiTxLatencyMovMin, gauge, v.WifiTxLatencyMov.Min.Val / 1000, labelV}, + {u.UAP.VAPWifiTxLatencyMovTotal, counter, v.WifiTxLatencyMov.Total, labelV}, // not sure if gauge or counter. + {u.UAP.VAPWifiTxLatencyMovCount, counter, v.WifiTxLatencyMov.TotalCount, labelV}, // not sure if gauge or counter. }) } } -func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) { +// UAP Radio Table +func (u *promUnifi) exportRADtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) { // radio table for _, p := range rt { labelR := []string{p.Name, p.Radio, labels[1], labels[2]} labelRUser := append(labelR, "user") labelRGuest := append(labelR, "guest") r.send([]*metric{ - {u.UAP.RadioCurrentAntennaGain, prometheus.GaugeValue, p.CurrentAntennaGain, labelR}, - {u.UAP.RadioHt, prometheus.GaugeValue, p.Ht, labelR}, - {u.UAP.RadioMaxTxpower, prometheus.GaugeValue, p.MaxTxpower, labelR}, - {u.UAP.RadioMinTxpower, prometheus.GaugeValue, p.MinTxpower, labelR}, - {u.UAP.RadioNss, prometheus.GaugeValue, p.Nss, labelR}, - {u.UAP.RadioRadioCaps, prometheus.GaugeValue, p.RadioCaps, labelR}, + {u.UAP.RadioCurrentAntennaGain, gauge, p.CurrentAntennaGain, labelR}, + {u.UAP.RadioHt, gauge, p.Ht, labelR}, + {u.UAP.RadioMaxTxpower, gauge, p.MaxTxpower, labelR}, + {u.UAP.RadioMinTxpower, gauge, p.MinTxpower, labelR}, + {u.UAP.RadioNss, gauge, p.Nss, labelR}, + {u.UAP.RadioRadioCaps, gauge, p.RadioCaps, labelR}, }) // combine radio table with radio stats table. @@ -314,18 +289,19 @@ func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTabl continue } r.send([]*metric{ - {u.UAP.RadioTxPower, prometheus.GaugeValue, t.TxPower, labelR}, - {u.UAP.RadioAstBeXmit, prometheus.GaugeValue, t.AstBeXmit, labelR}, - {u.UAP.RadioChannel, prometheus.GaugeValue, t.Channel, labelR}, - {u.UAP.RadioCuSelfRx, prometheus.GaugeValue, t.CuSelfRx.Val / 100.0, labelR}, - {u.UAP.RadioCuSelfTx, prometheus.GaugeValue, t.CuSelfTx.Val / 100.0, labelR}, - {u.UAP.RadioExtchannel, prometheus.GaugeValue, t.Extchannel, labelR}, - {u.UAP.RadioGain, prometheus.GaugeValue, t.Gain, labelR}, - {u.UAP.RadioNumSta, prometheus.GaugeValue, t.GuestNumSta, labelRGuest}, - {u.UAP.RadioNumSta, prometheus.GaugeValue, t.UserNumSta, labelRUser}, - {u.UAP.RadioTxPackets, prometheus.GaugeValue, t.TxPackets, labelR}, - {u.UAP.RadioTxRetries, prometheus.GaugeValue, t.TxRetries, labelR}, + {u.UAP.RadioTxPower, gauge, t.TxPower, labelR}, + {u.UAP.RadioAstBeXmit, gauge, t.AstBeXmit, labelR}, + {u.UAP.RadioChannel, gauge, t.Channel, labelR}, + {u.UAP.RadioCuSelfRx, gauge, t.CuSelfRx.Val / 100.0, labelR}, + {u.UAP.RadioCuSelfTx, gauge, t.CuSelfTx.Val / 100.0, labelR}, + {u.UAP.RadioExtchannel, gauge, t.Extchannel, labelR}, + {u.UAP.RadioGain, gauge, t.Gain, labelR}, + {u.UAP.RadioNumSta, gauge, t.GuestNumSta, labelRGuest}, + {u.UAP.RadioNumSta, gauge, t.UserNumSta, labelRUser}, + {u.UAP.RadioTxPackets, gauge, t.TxPackets, labelR}, + {u.UAP.RadioTxRetries, gauge, t.TxRetries, labelR}, }) + break } } } diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index d1fdb761..83205852 100644 --- a/pkg/promunifi/udm.go +++ b/pkg/promunifi/udm.go @@ -16,13 +16,9 @@ type unifiDevice struct { TotalBytes *prometheus.Desc BytesR *prometheus.Desc // ap only BytesD *prometheus.Desc // ap only - Bytes *prometheus.Desc // ap only TxBytesD *prometheus.Desc // ap only RxBytesD *prometheus.Desc // ap only Counter *prometheus.Desc - NumDesktop *prometheus.Desc // gw only - NumMobile *prometheus.Desc // gw only - NumHandheld *prometheus.Desc // gw only Loadavg1 *prometheus.Desc Loadavg5 *prometheus.Desc Loadavg15 *prometheus.Desc @@ -46,7 +42,6 @@ func descDevice(ns string) *unifiDevice { TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil), BytesR: prometheus.NewDesc(ns+"rate_bytes", "Transfer Rate", labels, nil), BytesD: prometheus.NewDesc(ns+"d_bytes", "Total Bytes D???", labels, nil), - Bytes: prometheus.NewDesc(ns+"transferred_bytes_total", "Bytes Transferred", labels, nil), TxBytesD: prometheus.NewDesc(ns+"d_tranmsit_bytes", "Transmit Bytes D???", labels, nil), RxBytesD: prometheus.NewDesc(ns+"d_receive_bytes", "Receive Bytes D???", labels, nil), Counter: prometheus.NewDesc(ns+"stations", "Number of Stations", append(labels, "station_type"), nil), @@ -65,37 +60,61 @@ func descDevice(ns string) *unifiDevice { func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} - // Dream Machine System Data. - r.send([]*metric{ - {u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)}, - {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, - {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, - {u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels}, - {u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, append(labels, "user")}, - {u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, append(labels, "guest")}, - {u.Device.Counter, prometheus.GaugeValue, d.NumDesktop, append(labels, "desktop")}, - {u.Device.Counter, prometheus.GaugeValue, d.NumMobile, append(labels, "mobile")}, - {u.Device.Counter, prometheus.GaugeValue, d.NumHandheld, append(labels, "handheld")}, - {u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels}, - {u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels}, - {u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels}, - {u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels}, - {u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels}, - {u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels}, - {u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels}, - {u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels}, - }) - + // Shared data (all devices do this). + u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) + u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) + u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.NumMobile, d.NumHandheld) // Switch Data u.exportUSWstats(r, labels, d.Stat.Sw) - u.exportPortTable(r, labels, d.PortTable) + u.exportPRTtable(r, labels, d.PortTable) // Gateway Data - u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) u.exportWANPorts(r, labels, d.Wan1, d.Wan2) + u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) + // Dream Machine System Data. + r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) // Wireless Data - UDM (non-pro) only if d.Stat.Ap != nil && d.VapTable != nil { u.exportUAPstats(r, labels, d.Stat.Ap) + // u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR) u.exportVAPtable(r, labels, *d.VapTable) - u.exportRadtable(r, labels, *d.RadioTable, *d.RadioTableStats) + u.exportRADtable(r, labels, *d.RadioTable, *d.RadioTableStats) } } + +// shared by all +func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexInt) { + r.send([]*metric{ + {u.Device.TotalTxBytes, counter, tx, labels}, + {u.Device.TotalRxBytes, counter, rx, labels}, + {u.Device.TotalBytes, counter, tx.Val + rx.Val, labels}, + }) +} + +// shared by all +func (u *promUnifi) exportSTAcount(r report, labels []string, stas ...unifi.FlexInt) { + r.send([]*metric{ + {u.Device.Counter, gauge, stas[0], append(labels, "user")}, + {u.Device.Counter, gauge, stas[1], append(labels, "guest")}, + }) + if len(stas) > 2 { + r.send([]*metric{ + {u.Device.Counter, gauge, stas[2], append(labels, "desktop")}, + {u.Device.Counter, gauge, stas[3], append(labels, "mobile")}, + {u.Device.Counter, gauge, stas[4], append(labels, "handheld")}, + }) + } +} + +// shared by all +func (u *promUnifi) exportSYSstats(r report, labels []string, s unifi.SysStats, ss unifi.SystemStats) { + r.send([]*metric{ + {u.Device.Loadavg1, gauge, s.Loadavg1, labels}, + {u.Device.Loadavg5, gauge, s.Loadavg5, labels}, + {u.Device.Loadavg15, gauge, s.Loadavg15, labels}, + {u.Device.MemUsed, gauge, s.MemUsed, labels}, + {u.Device.MemTotal, gauge, s.MemTotal, labels}, + {u.Device.MemBuffer, gauge, s.MemBuffer, labels}, + {u.Device.CPU, gauge, ss.CPU.Val / 100.0, labels}, + {u.Device.Mem, gauge, ss.Mem.Val / 100.0, labels}, + }) +} diff --git a/pkg/promunifi/usg.go b/pkg/promunifi/usg.go index 2682e94a..62ed93e2 100644 --- a/pkg/promunifi/usg.go +++ b/pkg/promunifi/usg.go @@ -72,56 +72,35 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) { labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} // Gateway System Data. - r.send([]*metric{ - {u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)}, - {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, - {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, - {u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels}, - {u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, append(labels, "user")}, - {u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, append(labels, "guest")}, - {u.Device.Counter, prometheus.GaugeValue, d.NumDesktop, append(labels, "desktop")}, - {u.Device.Counter, prometheus.GaugeValue, d.NumMobile, append(labels, "mobile")}, - {u.Device.Counter, prometheus.GaugeValue, d.NumHandheld, append(labels, "handheld")}, - {u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels}, - {u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels}, - {u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels}, - {u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels}, - {u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels}, - {u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels}, - {u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels}, - {u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels}, - }) u.exportWANPorts(r, labels, d.Wan1, d.Wan2) + u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) + u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) + u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.UserNumSta, d.GuestNumSta) + r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) } +// Gateway States func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) { labelLan := []string{"lan", labels[1], labels[2]} labelWan := []string{"all", labels[1], labels[2]} r.send([]*metric{ - /* // Combined Port Stats - not really needed. sum() the others instead. - {u.USG.WanRxPackets, prometheus.CounterValue, gw.WanRxPackets, labelWan}, - {u.USG.WanRxBytes, prometheus.CounterValue, gw.WanRxBytes, labelWan}, - {u.USG.WanRxDropped, prometheus.CounterValue, gw.WanRxDropped, labelWan}, - {u.USG.WanTxPackets, prometheus.CounterValue, gw.WanTxPackets, labelWan}, - {u.USG.WanTxBytes, prometheus.CounterValue, gw.WanTxBytes, labelWan}, - {u.USG.WanRxErrors, prometheus.CounterValue, gw.WanRxErrors, labelWan}, - */ - {u.USG.LanRxPackets, prometheus.CounterValue, gw.LanRxPackets, labelLan}, - {u.USG.LanRxBytes, prometheus.CounterValue, gw.LanRxBytes, labelLan}, - {u.USG.LanTxPackets, prometheus.CounterValue, gw.LanTxPackets, labelLan}, - {u.USG.LanTxBytes, prometheus.CounterValue, gw.LanTxBytes, labelLan}, - {u.USG.LanRxDropped, prometheus.CounterValue, gw.LanRxDropped, labelLan}, - {u.USG.UplinkLatency, prometheus.GaugeValue, ul.Latency.Val / 1000, labelWan}, - {u.USG.UplinkSpeed, prometheus.GaugeValue, ul.Speed, labelWan}, + {u.USG.LanRxPackets, counter, gw.LanRxPackets, labelLan}, + {u.USG.LanRxBytes, counter, gw.LanRxBytes, labelLan}, + {u.USG.LanTxPackets, counter, gw.LanTxPackets, labelLan}, + {u.USG.LanTxBytes, counter, gw.LanTxBytes, labelLan}, + {u.USG.LanRxDropped, counter, gw.LanRxDropped, labelLan}, + {u.USG.UplinkLatency, gauge, ul.Latency.Val / 1000, labelWan}, + {u.USG.UplinkSpeed, gauge, ul.Speed, labelWan}, // Speed Test Stats - {u.USG.Latency, prometheus.GaugeValue, st.Latency.Val / 1000, labelWan}, - {u.USG.Runtime, prometheus.GaugeValue, st.Runtime, labelWan}, - {u.USG.XputDownload, prometheus.GaugeValue, st.XputDownload, labelWan}, - {u.USG.XputUpload, prometheus.GaugeValue, st.XputUpload, labelWan}, + {u.USG.Latency, gauge, st.Latency.Val / 1000, labelWan}, + {u.USG.Runtime, gauge, st.Runtime, labelWan}, + {u.USG.XputDownload, gauge, st.XputDownload, labelWan}, + {u.USG.XputUpload, gauge, st.XputUpload, labelWan}, }) } +// WAN Stats func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) { for _, wan := range wans { if !wan.Up.Val { @@ -129,21 +108,21 @@ func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) } labelWan := []string{wan.Name, labels[1], labels[2]} r.send([]*metric{ - {u.USG.WanRxPackets, prometheus.CounterValue, wan.RxPackets, labelWan}, - {u.USG.WanRxBytes, prometheus.CounterValue, wan.RxBytes, labelWan}, - {u.USG.WanRxDropped, prometheus.CounterValue, wan.RxDropped, labelWan}, - {u.USG.WanRxErrors, prometheus.CounterValue, wan.RxErrors, labelWan}, - {u.USG.WanTxPackets, prometheus.CounterValue, wan.TxPackets, labelWan}, - {u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, labelWan}, - {u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, labelWan}, - {u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, labelWan}, - {u.USG.WanSpeed, prometheus.CounterValue, wan.Speed.Val * 1000000, labelWan}, - {u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, labelWan}, - {u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, labelWan}, - {u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, labelWan}, - {u.USG.WanTxErrors, prometheus.CounterValue, wan.TxErrors, labelWan}, - {u.USG.WanTxMulticast, prometheus.CounterValue, wan.TxMulticast, labelWan}, - {u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, labelWan}, + {u.USG.WanRxPackets, counter, wan.RxPackets, labelWan}, + {u.USG.WanRxBytes, counter, wan.RxBytes, labelWan}, + {u.USG.WanRxDropped, counter, wan.RxDropped, labelWan}, + {u.USG.WanRxErrors, counter, wan.RxErrors, labelWan}, + {u.USG.WanTxPackets, counter, wan.TxPackets, labelWan}, + {u.USG.WanTxBytes, counter, wan.TxBytes, labelWan}, + {u.USG.WanRxBroadcast, counter, wan.RxBroadcast, labelWan}, + {u.USG.WanRxMulticast, counter, wan.RxMulticast, labelWan}, + {u.USG.WanSpeed, counter, wan.Speed.Val * 1000000, labelWan}, + {u.USG.WanTxBroadcast, counter, wan.TxBroadcast, labelWan}, + {u.USG.WanTxBytesR, counter, wan.TxBytesR, labelWan}, + {u.USG.WanTxDropped, counter, wan.TxDropped, labelWan}, + {u.USG.WanTxErrors, counter, wan.TxErrors, labelWan}, + {u.USG.WanTxMulticast, counter, wan.TxMulticast, labelWan}, + {u.USG.WanBytesR, gauge, wan.BytesR, labelWan}, }) } } diff --git a/pkg/promunifi/usw.go b/pkg/promunifi/usw.go index cd5508c0..29f4bc87 100644 --- a/pkg/promunifi/usw.go +++ b/pkg/promunifi/usw.go @@ -50,6 +50,7 @@ func descUSW(ns string) *usw { labelS := []string{"site_name", "name"} labelP := []string{"port_id", "port_num", "port_name", "port_mac", "port_ip", "site_name", "name"} return &usw{ + // This data may be derivable by sum()ing the port data. SwRxPackets: prometheus.NewDesc(ns+"switch_receive_packets_total", "Switch Packets Received Total", labelS, nil), SwRxBytes: prometheus.NewDesc(ns+"switch_receive_bytes_total", "Switch Bytes Received Total", labelS, nil), SwRxErrors: prometheus.NewDesc(ns+"switch_receive_errors_total", "Switch Errors Received Total", labelS, nil), @@ -92,60 +93,49 @@ func descUSW(ns string) *usw { func (u *promUnifi) exportUSW(r report, d *unifi.USW) { labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} - labelsGuest := append(labels, "guest") - labelsUser := append(labels, "user") + u.exportUSWstats(r, labels, d.Stat.Sw) + u.exportPRTtable(r, labels, d.PortTable) + u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) + u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) + u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta) + r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) + // Switch System Data. if d.HasTemperature.Val { - r.send([]*metric{{u.Device.Temperature, prometheus.GaugeValue, d.GeneralTemperature, labels}}) + r.sendone(u.Device.Temperature, gauge, d.GeneralTemperature, labels) } if d.HasFan.Val { - r.send([]*metric{{u.Device.FanLevel, prometheus.GaugeValue, d.FanLevel, labels}}) + r.sendone(u.Device.FanLevel, gauge, d.FanLevel, labels) + } + if d.TotalMaxPower.Txt != "" { + r.sendone(u.Device.TotalMaxPower, gauge, d.TotalMaxPower, labels) } - - // Switch System Data. - r.send([]*metric{ - {u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)}, - {u.Device.TotalMaxPower, prometheus.GaugeValue, d.TotalMaxPower, labels}, - {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, - {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, - {u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels}, - {u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, labelsUser}, - {u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, labelsGuest}, - {u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels}, - {u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels}, - {u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels}, - {u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels}, - {u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels}, - {u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels}, - {u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels}, - {u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels}, - }) - u.exportPortTable(r, labels, d.PortTable) - u.exportUSWstats(r, labels, d.Stat.Sw) } +// Switch Stats func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) { labelS := labels[1:] r.send([]*metric{ - {u.USW.SwRxPackets, prometheus.CounterValue, sw.RxPackets, labelS}, - {u.USW.SwRxBytes, prometheus.CounterValue, sw.RxBytes, labelS}, - {u.USW.SwRxErrors, prometheus.CounterValue, sw.RxErrors, labelS}, - {u.USW.SwRxDropped, prometheus.CounterValue, sw.RxDropped, labelS}, - {u.USW.SwRxCrypts, prometheus.CounterValue, sw.RxCrypts, labelS}, - {u.USW.SwRxFrags, prometheus.CounterValue, sw.RxFrags, labelS}, - {u.USW.SwTxPackets, prometheus.CounterValue, sw.TxPackets, labelS}, - {u.USW.SwTxBytes, prometheus.CounterValue, sw.TxBytes, labelS}, - {u.USW.SwTxErrors, prometheus.CounterValue, sw.TxErrors, labelS}, - {u.USW.SwTxDropped, prometheus.CounterValue, sw.TxDropped, labelS}, - {u.USW.SwTxRetries, prometheus.CounterValue, sw.TxRetries, labelS}, - {u.USW.SwRxMulticast, prometheus.CounterValue, sw.RxMulticast, labelS}, - {u.USW.SwRxBroadcast, prometheus.CounterValue, sw.RxBroadcast, labelS}, - {u.USW.SwTxMulticast, prometheus.CounterValue, sw.TxMulticast, labelS}, - {u.USW.SwTxBroadcast, prometheus.CounterValue, sw.TxBroadcast, labelS}, - {u.USW.SwBytes, prometheus.CounterValue, sw.Bytes, labelS}, + {u.USW.SwRxPackets, counter, sw.RxPackets, labelS}, + {u.USW.SwRxBytes, counter, sw.RxBytes, labelS}, + {u.USW.SwRxErrors, counter, sw.RxErrors, labelS}, + {u.USW.SwRxDropped, counter, sw.RxDropped, labelS}, + {u.USW.SwRxCrypts, counter, sw.RxCrypts, labelS}, + {u.USW.SwRxFrags, counter, sw.RxFrags, labelS}, + {u.USW.SwTxPackets, counter, sw.TxPackets, labelS}, + {u.USW.SwTxBytes, counter, sw.TxBytes, labelS}, + {u.USW.SwTxErrors, counter, sw.TxErrors, labelS}, + {u.USW.SwTxDropped, counter, sw.TxDropped, labelS}, + {u.USW.SwTxRetries, counter, sw.TxRetries, labelS}, + {u.USW.SwRxMulticast, counter, sw.RxMulticast, labelS}, + {u.USW.SwRxBroadcast, counter, sw.RxBroadcast, labelS}, + {u.USW.SwTxMulticast, counter, sw.TxMulticast, labelS}, + {u.USW.SwTxBroadcast, counter, sw.TxBroadcast, labelS}, + {u.USW.SwBytes, counter, sw.Bytes, labelS}, }) } -func (u *promUnifi) exportPortTable(r report, labels []string, pt []unifi.Port) { +// Switch Port Table +func (u *promUnifi) exportPRTtable(r report, labels []string, pt []unifi.Port) { // Per-port data on a switch for _, p := range pt { if !p.Up.Val || !p.Enable.Val { @@ -155,29 +145,29 @@ func (u *promUnifi) exportPortTable(r report, labels []string, pt []unifi.Port) labelP := []string{labels[2] + " Port " + p.PortIdx.Txt, p.PortIdx.Txt, p.Name, p.Mac, p.IP, labels[1], labels[2]} if p.PoeEnable.Val && p.PortPoe.Val { r.send([]*metric{ - {u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, labelP}, - {u.USW.PoePower, prometheus.GaugeValue, p.PoePower, labelP}, - {u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, labelP}, + {u.USW.PoeCurrent, gauge, p.PoeCurrent, labelP}, + {u.USW.PoePower, gauge, p.PoePower, labelP}, + {u.USW.PoeVoltage, gauge, p.PoeVoltage, labelP}, }) } r.send([]*metric{ - {u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, labelP}, - {u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, labelP}, - {u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, labelP}, - {u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, labelP}, - {u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, labelP}, - {u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, labelP}, - {u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, labelP}, - {u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction.Val / 100.0, labelP}, - {u.USW.Speed, prometheus.GaugeValue, p.Speed.Val * 1000000, labelP}, - {u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, labelP}, - {u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, labelP}, - {u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, labelP}, - {u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, labelP}, - {u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, labelP}, - {u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, labelP}, - {u.USW.TxPackets, prometheus.CounterValue, p.TxPackets, labelP}, + {u.USW.RxBroadcast, counter, p.RxBroadcast, labelP}, + {u.USW.RxBytes, counter, p.RxBytes, labelP}, + {u.USW.RxBytesR, gauge, p.RxBytesR, labelP}, + {u.USW.RxDropped, counter, p.RxDropped, labelP}, + {u.USW.RxErrors, counter, p.RxErrors, labelP}, + {u.USW.RxMulticast, counter, p.RxMulticast, labelP}, + {u.USW.RxPackets, counter, p.RxPackets, labelP}, + {u.USW.Satisfaction, gauge, p.Satisfaction.Val / 100.0, labelP}, + {u.USW.Speed, gauge, p.Speed.Val * 1000000, labelP}, + {u.USW.TxBroadcast, counter, p.TxBroadcast, labelP}, + {u.USW.TxBytes, counter, p.TxBytes, labelP}, + {u.USW.TxBytesR, gauge, p.TxBytesR, labelP}, + {u.USW.TxDropped, counter, p.TxDropped, labelP}, + {u.USW.TxErrors, counter, p.TxErrors, labelP}, + {u.USW.TxMulticast, counter, p.TxMulticast, labelP}, + {u.USW.TxPackets, counter, p.TxPackets, labelP}, }) } } From dbe0a6bc94c208df7a6e0b3541f90007ebcfc13c Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 00:24:16 -0800 Subject: [PATCH 02/14] comments --- pkg/promunifi/collector.go | 7 ++++--- pkg/promunifi/report.go | 9 ++------- pkg/promunifi/uap.go | 1 + pkg/promunifi/udm.go | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 3116c2db..aa14b1a8 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -121,16 +121,17 @@ func (u *promUnifi) Collect(ch chan<- prometheus.Metric) { } // Pass Report interface into our collecting and reporting methods. - go u.exportMetrics(r, ch) + go u.exportMetrics(r, ch, r.ch) u.loopExports(r) } // This is closely tied to the method above with a sync.WaitGroup. // This method runs in a go routine and exits when the channel closes. -func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) { +// This is where our channels connects to the prometheus channel. +func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric, ourChan chan []*metric) { descs := make(map[*prometheus.Desc]bool) // used as a counter defer r.report(descs) - for newMetrics := range r.channel() { + for newMetrics := range ourChan { for _, m := range newMetrics { descs[m.Desc] = true switch v := m.Value.(type) { diff --git a/pkg/promunifi/report.go b/pkg/promunifi/report.go index 3fc36466..690f2256 100644 --- a/pkg/promunifi/report.go +++ b/pkg/promunifi/report.go @@ -18,7 +18,6 @@ type report interface { send([]*metric) sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string) metrics() *metrics.Metrics - channel() chan []*metric report(descs map[*prometheus.Desc]bool) export(m *metric, v float64) prometheus.Metric error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{}) @@ -35,9 +34,9 @@ func (r *Report) done() { r.wg.Add(-one) } -func (r *Report) sendone(d *prometheus.Desc, tv prometheus.ValueType, i interface{}, s []string) { +func (r *Report) sendone(desc *prometheus.Desc, valType prometheus.ValueType, val interface{}, labels []string) { r.wg.Add(one) - r.ch <- []*metric{{d, tv, i, s}} + r.ch <- []*metric{{desc, valType, val, labels}} } func (r *Report) send(m []*metric) { @@ -49,10 +48,6 @@ func (r *Report) metrics() *metrics.Metrics { return r.Metrics } -func (r *Report) channel() chan []*metric { - return r.ch -} - func (r *Report) report(descs map[*prometheus.Desc]bool) { if r.cf.LoggingFn == nil { return diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index e010c86d..8cec4507 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -170,6 +170,7 @@ func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) } +// udm doesn't have these stats exposed yet, so pass 2 or 6 metrics. func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap, bytes ...unifi.FlexInt) { labelU := []string{"user", labels[1], labels[2]} labelG := []string{"guest", labels[1], labels[2]} diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index 83205852..b4812f56 100644 --- a/pkg/promunifi/udm.go +++ b/pkg/promunifi/udm.go @@ -90,7 +90,7 @@ func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexI }) } -// shared by all +// shared by all, pass 2 or 5 stats. func (u *promUnifi) exportSTAcount(r report, labels []string, stas ...unifi.FlexInt) { r.send([]*metric{ {u.Device.Counter, gauge, stas[0], append(labels, "user")}, From 9a48c771eb686bbbabec7ccf3b114fa67c2c0b3a Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:18:32 -0800 Subject: [PATCH 03/14] fixes --- .metadata.sh | 2 +- .travis.yml | 5 +++++ Makefile | 17 ----------------- pkg/promunifi/uap.go | 4 ++-- pkg/promunifi/udm.go | 6 +++--- pkg/promunifi/usg.go | 4 ++-- pkg/promunifi/usw.go | 4 ++-- 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/.metadata.sh b/.metadata.sh index 98a2d415..0a12ce22 100755 --- a/.metadata.sh +++ b/.metadata.sh @@ -11,7 +11,7 @@ HBREPO="golift/homebrew-mugs" MAINT="David Newhall II " VENDOR="Go Lift " DESC="Polls a UniFi controller and exports metrics to InfluxDB" -GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -D funlen -D wsl -e G402" +GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -D funlen -D wsl -e G402 -D gomnd" # Example must exist at examples/$CONFIG_FILE.example CONFIG_FILE="up.conf" LICENSE="MIT" diff --git a/.travis.yml b/.travis.yml index d0827d55..1c2f9528 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ install: - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest - rvm install 2.0.0 - rvm 2.0.0 do gem install --no-document fpm + - rvm 2.0.0 gem install --no-document package_cloud before_script: # Create your own deploy key, tar it, and encrypt the file to make this work. Optionally add a bitly_token file to the archive. - openssl aes-256-cbc -K $encrypted_e3d3b4b2abab_key -iv $encrypted_e3d3b4b2abab_iv -in .secret-files.tar.enc -out .secret-files.tar -d @@ -70,3 +71,7 @@ deploy: script: scripts/formula-deploy.sh on: tags: true + - provider: script + script: scripts/package-deploy.sh + on: + tags: true diff --git a/Makefile b/Makefile index 672f8ff1..cfcba88b 100644 --- a/Makefile +++ b/Makefile @@ -276,20 +276,3 @@ install: man readme $(BINARY) /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/ [ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE) /usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/ - -# If you installed with `make install` run `make uninstall` before installing a binary package. (even on Linux!!!) -# This will remove the package install from macOS, it will not remove a package install from Linux. -uninstall: - @echo " ==> You must run make uninstall as root on Linux. Recommend not running as root on macOS." - [ -x /bin/systemctl ] && /bin/systemctl disable $(BINARY) || true - [ -x /bin/systemctl ] && /bin/systemctl stop $(BINARY) || true - [ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist ] \ - && /bin/launchctl unload ~/Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist || true - [ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist ] \ - && /bin/launchctl unload /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist || true - rm -rf /usr/local/{etc,bin,share/doc}/$(BINARY) - rm -f ~/Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist - rm -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist || true - rm -f /etc/systemd/system/$(BINARY).service /usr/local/share/man/man1/$(BINARY).1.gz - [ -x /bin/systemctl ] && /bin/systemctl --system daemon-reload || true - @[ -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist ] && echo " ==> Unload and delete this file manually:" && echo " sudo launchctl unload /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist" && echo " sudo rm -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist" || true diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index 8cec4507..cedce816 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -160,14 +160,14 @@ func descUAP(ns string) *uap { func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { labels := []string{d.Type, d.SiteName, d.Name} - infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR) u.exportVAPtable(r, labels, d.VapTable) u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta) u.exportRADtable(r, labels, d.RadioTable, d.RadioTableStats) - r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) + r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) } // udm doesn't have these stats exposed yet, so pass 2 or 6 metrics. diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index b4812f56..4cfb0c79 100644 --- a/pkg/promunifi/udm.go +++ b/pkg/promunifi/udm.go @@ -31,7 +31,7 @@ type unifiDevice struct { func descDevice(ns string) *unifiDevice { labels := []string{"type", "site_name", "name"} - infoLabels := []string{"version", "model", "serial", "mac", "ip", "id", "bytes"} + infoLabels := []string{"version", "model", "serial", "mac", "ip", "id", "bytes", "uptime"} return &unifiDevice{ Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil), Temperature: prometheus.NewDesc(ns+"temperature_celsius", "Temperature", labels, nil), @@ -59,7 +59,7 @@ func descDevice(ns string) *unifiDevice { // UDM is a collection of stats from USG, USW and UAP. It has no unique stats. func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { labels := []string{d.Type, d.SiteName, d.Name} - infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} // Shared data (all devices do this). u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) @@ -71,7 +71,7 @@ func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { u.exportWANPorts(r, labels, d.Wan1, d.Wan2) u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) // Dream Machine System Data. - r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) + r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) // Wireless Data - UDM (non-pro) only if d.Stat.Ap != nil && d.VapTable != nil { u.exportUAPstats(r, labels, d.Stat.Ap) diff --git a/pkg/promunifi/usg.go b/pkg/promunifi/usg.go index 62ed93e2..7ed8d7f9 100644 --- a/pkg/promunifi/usg.go +++ b/pkg/promunifi/usg.go @@ -70,14 +70,14 @@ func descUSG(ns string) *usg { func (u *promUnifi) exportUSG(r report, d *unifi.USG) { labels := []string{d.Type, d.SiteName, d.Name} - infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} // Gateway System Data. u.exportWANPorts(r, labels, d.Wan1, d.Wan2) u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.UserNumSta, d.GuestNumSta) - r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) + r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) } // Gateway States diff --git a/pkg/promunifi/usw.go b/pkg/promunifi/usw.go index 29f4bc87..325f8cec 100644 --- a/pkg/promunifi/usw.go +++ b/pkg/promunifi/usw.go @@ -92,13 +92,13 @@ func descUSW(ns string) *usw { func (u *promUnifi) exportUSW(r report, d *unifi.USW) { labels := []string{d.Type, d.SiteName, d.Name} - infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} u.exportUSWstats(r, labels, d.Stat.Sw) u.exportPRTtable(r, labels, d.PortTable) u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta) - r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...)) + r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) // Switch System Data. if d.HasTemperature.Val { r.sendone(u.Device.Temperature, gauge, d.GeneralTemperature, labels) From a7259bf3f0c1a7363a11f3aa3fd08f646b4f532d Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:26:27 -0800 Subject: [PATCH 04/14] add uptime back --- pkg/promunifi/clients.go | 2 +- pkg/promunifi/report.go | 6 ------ pkg/promunifi/uap.go | 5 ++++- pkg/promunifi/udm.go | 9 +++++++-- pkg/promunifi/usg.go | 5 ++++- pkg/promunifi/usw.go | 11 +++++++---- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pkg/promunifi/clients.go b/pkg/promunifi/clients.go index c5477ac3..4c7ae481 100644 --- a/pkg/promunifi/clients.go +++ b/pkg/promunifi/clients.go @@ -115,7 +115,7 @@ func (u *promUnifi) exportClient(r report, c *unifi.Client) { {u.Client.BytesR, gauge, c.BytesR, labelW}, }) } - r.sendone(u.Client.Info, gauge, c.Uptime, labelW) + r.send([]*metric{{u.Client.Info, gauge, c.Uptime, labelW}}) /* needs more "looking into" {u.Client.DpiStatsApp, gauge, c.DpiStats.App, labels}, {u.Client.DpiStatsCat, gauge, c.DpiStats.Cat, labels}, diff --git a/pkg/promunifi/report.go b/pkg/promunifi/report.go index 690f2256..7d40ea31 100644 --- a/pkg/promunifi/report.go +++ b/pkg/promunifi/report.go @@ -16,7 +16,6 @@ type report interface { add() done() send([]*metric) - sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string) metrics() *metrics.Metrics report(descs map[*prometheus.Desc]bool) export(m *metric, v float64) prometheus.Metric @@ -34,11 +33,6 @@ func (r *Report) done() { r.wg.Add(-one) } -func (r *Report) sendone(desc *prometheus.Desc, valType prometheus.ValueType, val interface{}, labels []string) { - r.wg.Add(one) - r.ch <- []*metric{{desc, valType, val, labels}} -} - func (r *Report) send(m []*metric) { r.wg.Add(one) r.ch <- m diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index cedce816..0a47ecec 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -167,7 +167,10 @@ func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta) u.exportRADtable(r, labels, d.RadioTable, d.RadioTableStats) - r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) + r.send([]*metric{ + {u.Device.Info, gauge, 1.0, append(labels, infoLabels...)}, + {u.Device.Uptime, gauge, d.Uptime, labels}, + }) } // udm doesn't have these stats exposed yet, so pass 2 or 6 metrics. diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index 4cfb0c79..524c9908 100644 --- a/pkg/promunifi/udm.go +++ b/pkg/promunifi/udm.go @@ -7,7 +7,8 @@ import ( // These are shared by all four device types: UDM, UAP, USG, USW type unifiDevice struct { - Info *prometheus.Desc // uptime + Info *prometheus.Desc + Uptime *prometheus.Desc Temperature *prometheus.Desc // sw only TotalMaxPower *prometheus.Desc // sw only FanLevel *prometheus.Desc // sw only @@ -34,6 +35,7 @@ func descDevice(ns string) *unifiDevice { infoLabels := []string{"version", "model", "serial", "mac", "ip", "id", "bytes", "uptime"} return &unifiDevice{ Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil), + Uptime: prometheus.NewDesc(ns+"uptime", "Device Uptime", labels, nil), Temperature: prometheus.NewDesc(ns+"temperature_celsius", "Temperature", labels, nil), TotalMaxPower: prometheus.NewDesc(ns+"max_power_total", "Total Max Power", labels, nil), FanLevel: prometheus.NewDesc(ns+"fan_level", "Fan Level", labels, nil), @@ -71,7 +73,10 @@ func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { u.exportWANPorts(r, labels, d.Wan1, d.Wan2) u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) // Dream Machine System Data. - r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) + r.send([]*metric{ + {u.Device.Info, gauge, 1.0, append(labels, infoLabels...)}, + {u.Device.Uptime, gauge, d.Uptime, labels}, + }) // Wireless Data - UDM (non-pro) only if d.Stat.Ap != nil && d.VapTable != nil { u.exportUAPstats(r, labels, d.Stat.Ap) diff --git a/pkg/promunifi/usg.go b/pkg/promunifi/usg.go index 7ed8d7f9..6c2ffd01 100644 --- a/pkg/promunifi/usg.go +++ b/pkg/promunifi/usg.go @@ -77,7 +77,10 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) { u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink) u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.UserNumSta, d.GuestNumSta) - r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) + r.send([]*metric{ + {u.Device.Info, gauge, 1.0, append(labels, infoLabels...)}, + {u.Device.Uptime, gauge, d.Uptime, labels}, + }) } // Gateway States diff --git a/pkg/promunifi/usw.go b/pkg/promunifi/usw.go index 325f8cec..831e71ee 100644 --- a/pkg/promunifi/usw.go +++ b/pkg/promunifi/usw.go @@ -98,16 +98,19 @@ func (u *promUnifi) exportUSW(r report, d *unifi.USW) { u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes) u.exportSYSstats(r, labels, d.SysStats, d.SystemStats) u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta) - r.sendone(u.Device.Info, gauge, 1.0, append(labels, infoLabels...)) + r.send([]*metric{ + {u.Device.Info, gauge, 1.0, append(labels, infoLabels...)}, + {u.Device.Uptime, gauge, d.Uptime, labels}, + }) // Switch System Data. if d.HasTemperature.Val { - r.sendone(u.Device.Temperature, gauge, d.GeneralTemperature, labels) + r.send([]*metric{{u.Device.Temperature, gauge, d.GeneralTemperature, labels}}) } if d.HasFan.Val { - r.sendone(u.Device.FanLevel, gauge, d.FanLevel, labels) + r.send([]*metric{{u.Device.FanLevel, gauge, d.FanLevel, labels}}) } if d.TotalMaxPower.Txt != "" { - r.sendone(u.Device.TotalMaxPower, gauge, d.TotalMaxPower, labels) + r.send([]*metric{{u.Device.TotalMaxPower, gauge, d.TotalMaxPower, labels}}) } } From dcec953ecc81e375043bf03c41b056688d292d83 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:30:22 -0800 Subject: [PATCH 05/14] fix script --- scripts/package-deploy.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 scripts/package-deploy.sh diff --git a/scripts/package-deploy.sh b/scripts/package-deploy.sh new file mode 100755 index 00000000..96ca731e --- /dev/null +++ b/scripts/package-deploy.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Deploy our built packages to packagecloud. + +REPO=dev +[ "$SOURCE_BRANCH" != "master" ] || REPO=big +echo "deploy source branch: $SOURCE_BRANCH" + +source .metadata.sh +# deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.arm64.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.amd64.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.armhf.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.i386.deb +# rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.arm64.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.amd64.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.armhf.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.i386.rpm From c03a08317abf58fd34ce4d96e2e7dc3d54bfdc16 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:32:19 -0800 Subject: [PATCH 06/14] rename this back --- pkg/promunifi/clients.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/promunifi/clients.go b/pkg/promunifi/clients.go index 4c7ae481..3b48616a 100644 --- a/pkg/promunifi/clients.go +++ b/pkg/promunifi/clients.go @@ -24,7 +24,7 @@ type uclient struct { TxRetries *prometheus.Desc TxPower *prometheus.Desc TxRate *prometheus.Desc - Info *prometheus.Desc + Uptime *prometheus.Desc WifiTxAttempts *prometheus.Desc WiredRxBytes *prometheus.Desc WiredRxBytesR *prometheus.Desc @@ -63,7 +63,7 @@ func descClient(ns string) *uclient { TxPower: prometheus.NewDesc(ns+"radio_transmit_power_dbm", "Client Transmit Power", labelW, nil), TxRate: prometheus.NewDesc(ns+"radio_transmit_rate_bps", "Client Transmit Rate", labelW, nil), WifiTxAttempts: prometheus.NewDesc(ns+"wifi_attempts_transmit_total", "Client Wifi Transmit Attempts", labelW, nil), - Info: prometheus.NewDesc(ns+"uptime_seconds", "Client Uptime", labelW, nil), // XXX: re-purpose for info tags. + Uptime: prometheus.NewDesc(ns+"uptime_seconds", "Client Uptime", labelW, nil), // XXX: re-purpose for info tags. /* needs more "looking into" DpiStatsApp: prometheus.NewDesc(ns+"dpi_stats_app", "Client DPI Stats App", labels, nil), DpiStatsCat: prometheus.NewDesc(ns+"dpi_stats_cat", "Client DPI Stats Cat", labels, nil), @@ -115,7 +115,7 @@ func (u *promUnifi) exportClient(r report, c *unifi.Client) { {u.Client.BytesR, gauge, c.BytesR, labelW}, }) } - r.send([]*metric{{u.Client.Info, gauge, c.Uptime, labelW}}) + r.send([]*metric{{u.Client.Uptime, gauge, c.Uptime, labelW}}) /* needs more "looking into" {u.Client.DpiStatsApp, gauge, c.DpiStats.App, labels}, {u.Client.DpiStatsCat, gauge, c.DpiStats.Cat, labels}, From d92feee33d7078ecbca2df7945918d2e47bb7aef Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:33:00 -0800 Subject: [PATCH 07/14] fix build script --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1c2f9528..d33a1d32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ install: - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest - rvm install 2.0.0 - rvm 2.0.0 do gem install --no-document fpm - - rvm 2.0.0 gem install --no-document package_cloud + - rvm 2.0.0 do gem install --no-document package_cloud before_script: # Create your own deploy key, tar it, and encrypt the file to make this work. Optionally add a bitly_token file to the archive. - openssl aes-256-cbc -K $encrypted_e3d3b4b2abab_key -iv $encrypted_e3d3b4b2abab_iv -in .secret-files.tar.enc -out .secret-files.tar -d @@ -43,6 +43,7 @@ script: after_success: # Display Release Folder - ls -l release/ + - scripts/package-deploy.sh # Setup the ssh client so we can clone and push to the homebrew formula repo. # You must put github_deploy_file into .secret_files.tar.enc # This is an ssh key added to your homebrew forumla repo. From b13281e71b7415039ec132155ec01700fed742cf Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:35:49 -0800 Subject: [PATCH 08/14] fix build --- .metadata.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.metadata.sh b/.metadata.sh index 0a12ce22..98a2d415 100755 --- a/.metadata.sh +++ b/.metadata.sh @@ -11,7 +11,7 @@ HBREPO="golift/homebrew-mugs" MAINT="David Newhall II " VENDOR="Go Lift " DESC="Polls a UniFi controller and exports metrics to InfluxDB" -GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -D funlen -D wsl -e G402 -D gomnd" +GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -D funlen -D wsl -e G402" # Example must exist at examples/$CONFIG_FILE.example CONFIG_FILE="up.conf" LICENSE="MIT" From f0847c8e11b30b952d9558579b1aa05c77390558 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:44:14 -0800 Subject: [PATCH 09/14] still testing --- .travis.yml | 2 +- scripts/package-deploy.sh | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index d33a1d32..42385ca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,8 +24,8 @@ install: # download super-linter: golangci-lint - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest - rvm install 2.0.0 - - rvm 2.0.0 do gem install --no-document fpm - rvm 2.0.0 do gem install --no-document package_cloud + - rvm 2.0.0 do gem install --no-document fpm before_script: # Create your own deploy key, tar it, and encrypt the file to make this work. Optionally add a bitly_token file to the archive. - openssl aes-256-cbc -K $encrypted_e3d3b4b2abab_key -iv $encrypted_e3d3b4b2abab_iv -in .secret-files.tar.enc -out .secret-files.tar -d diff --git a/scripts/package-deploy.sh b/scripts/package-deploy.sh index 96ca731e..ed275aa0 100755 --- a/scripts/package-deploy.sh +++ b/scripts/package-deploy.sh @@ -8,12 +8,12 @@ echo "deploy source branch: $SOURCE_BRANCH" source .metadata.sh # deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.arm64.deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.amd64.deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.armhf.deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}.i386.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.arm64.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.amd64.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.armhf.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.i386.deb # rpm -package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.arm64.rpm -package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.amd64.rpm -package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.armhf.rpm -package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}.i386.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.arm64.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.amd64.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.armhf.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.i386.rpm From 7f961de5b94a79bbe5af10427da536925acd82f9 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:46:33 -0800 Subject: [PATCH 10/14] fix --- scripts/package-deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/package-deploy.sh b/scripts/package-deploy.sh index ed275aa0..6e06b850 100755 --- a/scripts/package-deploy.sh +++ b/scripts/package-deploy.sh @@ -3,8 +3,8 @@ # Deploy our built packages to packagecloud. REPO=dev -[ "$SOURCE_BRANCH" != "master" ] || REPO=big -echo "deploy source branch: $SOURCE_BRANCH" +[ "$TRAVIS_BRANCH" != "$TRAVIS_TAG" ] || REPO=big +echo "deploying packages from branch: $SOURCE_BRANCH, tag: $TRAVIS_TAG to repo: $REPO" source .metadata.sh # deb From 5a318610826e8e753ea2ffa66b987088878da1a7 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:53:41 -0800 Subject: [PATCH 11/14] go again --- scripts/package-deploy.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/package-deploy.sh b/scripts/package-deploy.sh index 6e06b850..9ded9225 100755 --- a/scripts/package-deploy.sh +++ b/scripts/package-deploy.sh @@ -8,12 +8,12 @@ echo "deploying packages from branch: $SOURCE_BRANCH, tag: $TRAVIS_TAG to repo: source .metadata.sh # deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.arm64.deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.amd64.deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.armhf.deb -package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}.i386.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_arm64.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_amd64.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_armhf.deb +package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_i386.deb # rpm package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.arm64.rpm -package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.amd64.rpm +package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.x86_64.rpm package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.armhf.rpm package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.i386.rpm From 1e39c961fdcc3a5a997f53d2cdb978e653ff25dc Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 02:54:35 -0800 Subject: [PATCH 12/14] last fix? --- scripts/package-deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package-deploy.sh b/scripts/package-deploy.sh index 9ded9225..0854a11f 100755 --- a/scripts/package-deploy.sh +++ b/scripts/package-deploy.sh @@ -4,7 +4,7 @@ REPO=dev [ "$TRAVIS_BRANCH" != "$TRAVIS_TAG" ] || REPO=big -echo "deploying packages from branch: $SOURCE_BRANCH, tag: $TRAVIS_TAG to repo: $REPO" +echo "deploying packages from branch: $TRAVIS_BRANCH, tag: $TRAVIS_TAG to repo: $REPO" source .metadata.sh # deb From 0be0de811c05784066061d6002d6a4c05657590e Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 03:13:49 -0800 Subject: [PATCH 13/14] remove test code --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 42385ca1..4cad6edf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,6 @@ script: after_success: # Display Release Folder - ls -l release/ - - scripts/package-deploy.sh # Setup the ssh client so we can clone and push to the homebrew formula repo. # You must put github_deploy_file into .secret_files.tar.enc # This is an ssh key added to your homebrew forumla repo. @@ -75,4 +74,5 @@ deploy: - provider: script script: scripts/package-deploy.sh on: - tags: true + all_branches: true + condition: $TRAVIS_BRANCH =~ ^(master|v[0-9.])$ From 8a67972b7d4c118215663aadba37856b6bb629c8 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 3 Dec 2019 03:14:15 -0800 Subject: [PATCH 14/14] fix this name --- pkg/promunifi/udm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index 524c9908..515ed62d 100644 --- a/pkg/promunifi/udm.go +++ b/pkg/promunifi/udm.go @@ -35,7 +35,7 @@ func descDevice(ns string) *unifiDevice { infoLabels := []string{"version", "model", "serial", "mac", "ip", "id", "bytes", "uptime"} return &unifiDevice{ Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil), - Uptime: prometheus.NewDesc(ns+"uptime", "Device Uptime", labels, nil), + Uptime: prometheus.NewDesc(ns+"uptime_seconds", "Device Uptime", labels, nil), Temperature: prometheus.NewDesc(ns+"temperature_celsius", "Temperature", labels, nil), TotalMaxPower: prometheus.NewDesc(ns+"max_power_total", "Total Max Power", labels, nil), FanLevel: prometheus.NewDesc(ns+"fan_level", "Fan Level", labels, nil),