From 722504c58ab714da47cd87c3246f14b3d0824867 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Thu, 28 Nov 2019 16:02:13 -0800 Subject: [PATCH] add UDM support --- integrations/promunifi/promunifi/collector.go | 3 -- integrations/promunifi/promunifi/uap.go | 6 +-- integrations/promunifi/promunifi/udm.go | 46 +++++++++++++++---- integrations/promunifi/promunifi/usg.go | 46 +++++++++++-------- integrations/promunifi/promunifi/usw.go | 46 +++++++++++-------- 5 files changed, 91 insertions(+), 56 deletions(-) diff --git a/integrations/promunifi/promunifi/collector.go b/integrations/promunifi/promunifi/collector.go index 96da4aa8..960779eb 100644 --- a/integrations/promunifi/promunifi/collector.go +++ b/integrations/promunifi/promunifi/collector.go @@ -41,7 +41,6 @@ type unifiCollector struct { UAP *uap USG *usg USW *usw - UDM *udm Site *site } @@ -78,7 +77,6 @@ func NewUnifiCollector(opts UnifiCollectorCnfg) prometheus.Collector { UAP: descUAP(opts.Namespace), USG: descUSG(opts.Namespace), USW: descUSW(opts.Namespace), - UDM: descUDM(opts.Namespace), Site: descSite(opts.Namespace), } } @@ -102,7 +100,6 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) { describe(u.UAP) describe(u.USG) describe(u.USW) - describe(u.UDM) describe(u.Site) } diff --git a/integrations/promunifi/promunifi/uap.go b/integrations/promunifi/promunifi/uap.go index 2f52e1c3..90cac939 100644 --- a/integrations/promunifi/promunifi/uap.go +++ b/integrations/promunifi/promunifi/uap.go @@ -227,7 +227,7 @@ func (u *unifiCollector) exportUAPs(r *Report) { } func (u *unifiCollector) exportUAP(r *Report, a *unifi.UAP) { - labels := []string{a.IP, a.SiteName, a.Mac, a.Model, a.Name, a.Serial, a.Type, a.Version} + labels := []string{a.IP, a.Type, a.Version, a.SiteName, a.Mac, a.Model, a.Name, a.Serial} // AP data. r.send([]*metricExports{ @@ -251,11 +251,11 @@ func (u *unifiCollector) exportUAP(r *Report, a *unifi.UAP) { {u.UAP.CPU, prometheus.GaugeValue, a.SystemStats.CPU, labels}, {u.UAP.Mem, prometheus.GaugeValue, a.SystemStats.Mem, labels}, }) - u.exportUAPstat(r, labels[2:], a.Stat.Ap) + u.exportUAPstats(r, labels[2:], a.Stat.Ap) u.exportVAPtable(r, labels[2:], a.VapTable, a.RadioTable, a.RadioTableStats) } -func (u *unifiCollector) exportUAPstat(r *Report, labels []string, a *unifi.Ap) { +func (u *unifiCollector) exportUAPstats(r *Report, labels []string, a *unifi.Ap) { labelA := append([]string{"all"}, labels...) labelU := append([]string{"user"}, labels...) labelG := append([]string{"guest"}, labels...) diff --git a/integrations/promunifi/promunifi/udm.go b/integrations/promunifi/promunifi/udm.go index 5cc4142a..bcfdcc73 100644 --- a/integrations/promunifi/promunifi/udm.go +++ b/integrations/promunifi/promunifi/udm.go @@ -1,13 +1,9 @@ package promunifi -import "golift.io/unifi" - -type udm struct { -} - -func descUDM(ns string) *udm { - return &udm{} -} +import ( + "github.com/prometheus/client_golang/prometheus" + "golift.io/unifi" +) func (u *unifiCollector) exportUDMs(r *Report) { if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.UDMs) < 1 { @@ -22,6 +18,36 @@ func (u *unifiCollector) exportUDMs(r *Report) { }() } -func (u *unifiCollector) exportUDM(r *Report, d *unifi.UDM) { - // for _, d := range r.Metrics.Devices.UDMs { +// UDM is a collection of stats from USG, USW and UAP. It has no unique stats. +func (u *unifiCollector) exportUDM(r *Report, s *unifi.UDM) { + labels := []string{s.IP, s.Type, s.Version, s.SiteName, s.Mac, s.Model, s.Name, s.Serial} + // Gateway System Data. + r.send([]*metricExports{ + {u.USG.Uptime, prometheus.GaugeValue, s.Uptime, labels}, + {u.USG.TotalTxBytes, prometheus.CounterValue, s.TxBytes, labels}, + {u.USG.TotalRxBytes, prometheus.CounterValue, s.RxBytes, labels}, + {u.USG.TotalBytes, prometheus.CounterValue, s.Bytes, labels}, + {u.USG.NumSta, prometheus.GaugeValue, s.NumSta, labels}, + {u.USG.UserNumSta, prometheus.GaugeValue, s.UserNumSta, labels}, + {u.USG.GuestNumSta, prometheus.GaugeValue, s.GuestNumSta, labels}, + {u.USG.NumDesktop, prometheus.GaugeValue, s.NumDesktop, labels}, + {u.USG.NumMobile, prometheus.GaugeValue, s.NumMobile, labels}, + {u.USG.NumHandheld, prometheus.GaugeValue, s.NumHandheld, labels}, + {u.USG.Loadavg1, prometheus.GaugeValue, s.SysStats.Loadavg1, labels}, + {u.USG.Loadavg5, prometheus.GaugeValue, s.SysStats.Loadavg5, labels}, + {u.USG.Loadavg15, prometheus.GaugeValue, s.SysStats.Loadavg15, labels}, + {u.USG.MemUsed, prometheus.GaugeValue, s.SysStats.MemUsed, labels}, + {u.USG.MemTotal, prometheus.GaugeValue, s.SysStats.MemTotal, labels}, + {u.USG.MemBuffer, prometheus.GaugeValue, s.SysStats.MemBuffer, labels}, + {u.USG.CPU, prometheus.GaugeValue, s.SystemStats.CPU, labels}, + {u.USG.Mem, prometheus.GaugeValue, s.SystemStats.Mem, labels}, + }) + u.exportUSWstats(r, s.Stat.Sw, labels) + u.exportUSGstats(r, s.Stat.Gw, s.SpeedtestStatus, labels) + u.exportWANPorts(r, labels, s.Wan1, s.Wan2) + u.exportPortTable(r, s.PortTable, labels[4:]) + if s.Stat.Ap != nil && s.VapTable != nil { + u.exportUAPstats(r, labels[2:], s.Stat.Ap) + u.exportVAPtable(r, labels[2:], *s.VapTable, *s.RadioTable, *s.RadioTableStats) + } } diff --git a/integrations/promunifi/promunifi/usg.go b/integrations/promunifi/promunifi/usg.go index 094cc2fb..6146b819 100644 --- a/integrations/promunifi/promunifi/usg.go +++ b/integrations/promunifi/promunifi/usg.go @@ -57,7 +57,7 @@ func descUSG(ns string) *usg { if ns += "_usg_"; ns == "_usg_" { ns = "usg_" } - labels := []string{"site_name", "mac", "model", "name", "serial", "type", "version", "ip"} + labels := []string{"ip", "type", "version", "site_name", "mac", "model", "name", "serial"} labelWan := append([]string{"port"}, labels...) return &usg{ @@ -121,8 +121,7 @@ func (u *unifiCollector) exportUSGs(r *Report) { } func (u *unifiCollector) exportUSG(r *Report, s *unifi.USG) { - labels := []string{s.SiteName, s.Mac, s.Model, s.Name, s.Serial, s.Type, s.Version, s.IP} - labelWan := append([]string{"all"}, labels...) + labels := []string{s.IP, s.Type, s.Version, s.SiteName, s.Mac, s.Model, s.Name, s.Serial} // Gateway System Data. r.send([]*metricExports{ {u.USG.Uptime, prometheus.GaugeValue, s.Uptime, labels}, @@ -143,25 +142,32 @@ func (u *unifiCollector) exportUSG(r *Report, s *unifi.USG) { {u.USG.MemBuffer, prometheus.GaugeValue, s.SysStats.MemBuffer, labels}, {u.USG.CPU, prometheus.GaugeValue, s.SystemStats.CPU, labels}, {u.USG.Mem, prometheus.GaugeValue, s.SystemStats.Mem, labels}, - // Combined Port Stats - {u.USG.WanRxPackets, prometheus.CounterValue, s.Stat.Gw.WanRxPackets, labelWan}, - {u.USG.WanRxBytes, prometheus.CounterValue, s.Stat.Gw.WanRxBytes, labelWan}, - {u.USG.WanRxDropped, prometheus.CounterValue, s.Stat.Gw.WanRxDropped, labelWan}, - {u.USG.WanTxPackets, prometheus.CounterValue, s.Stat.Gw.WanTxPackets, labelWan}, - {u.USG.WanTxBytes, prometheus.CounterValue, s.Stat.Gw.WanTxBytes, labelWan}, - {u.USG.WanRxErrors, prometheus.CounterValue, s.Stat.Gw.WanRxErrors, labelWan}, - {u.USG.LanRxPackets, prometheus.CounterValue, s.Stat.Gw.LanRxPackets, labels}, - {u.USG.LanRxBytes, prometheus.CounterValue, s.Stat.Gw.LanRxBytes, labels}, - {u.USG.LanTxPackets, prometheus.CounterValue, s.Stat.Gw.LanTxPackets, labels}, - {u.USG.LanTxBytes, prometheus.CounterValue, s.Stat.Gw.LanTxBytes, labels}, - {u.USG.LanRxDropped, prometheus.CounterValue, s.Stat.Gw.LanRxDropped, labels}, - // Speed Test Stats - {u.USG.Latency, prometheus.GaugeValue, s.SpeedtestStatus.Latency.Val / 1000, labels}, - {u.USG.Runtime, prometheus.GaugeValue, s.SpeedtestStatus.Runtime, labels}, - {u.USG.XputDownload, prometheus.GaugeValue, s.SpeedtestStatus.XputDownload, labels}, - {u.USG.XputUpload, prometheus.GaugeValue, s.SpeedtestStatus.XputUpload, labels}, }) u.exportWANPorts(r, labels, s.Wan1, s.Wan2) + u.exportUSGstats(r, s.Stat.Gw, s.SpeedtestStatus, labels) +} + +func (u *unifiCollector) exportUSGstats(r *Report, s *unifi.Gw, st unifi.SpeedtestStatus, labels []string) { + labelWan := append([]string{"all"}, labels...) + r.send([]*metricExports{ + // Combined Port Stats + {u.USG.WanRxPackets, prometheus.CounterValue, s.WanRxPackets, labelWan}, + {u.USG.WanRxBytes, prometheus.CounterValue, s.WanRxBytes, labelWan}, + {u.USG.WanRxDropped, prometheus.CounterValue, s.WanRxDropped, labelWan}, + {u.USG.WanTxPackets, prometheus.CounterValue, s.WanTxPackets, labelWan}, + {u.USG.WanTxBytes, prometheus.CounterValue, s.WanTxBytes, labelWan}, + {u.USG.WanRxErrors, prometheus.CounterValue, s.WanRxErrors, labelWan}, + {u.USG.LanRxPackets, prometheus.CounterValue, s.LanRxPackets, labels}, + {u.USG.LanRxBytes, prometheus.CounterValue, s.LanRxBytes, labels}, + {u.USG.LanTxPackets, prometheus.CounterValue, s.LanTxPackets, labels}, + {u.USG.LanTxBytes, prometheus.CounterValue, s.LanTxBytes, labels}, + {u.USG.LanRxDropped, prometheus.CounterValue, s.LanRxDropped, labels}, + // Speed Test Stats + {u.USG.Latency, prometheus.GaugeValue, st.Latency.Val / 1000, labels}, + {u.USG.Runtime, prometheus.GaugeValue, st.Runtime, labels}, + {u.USG.XputDownload, prometheus.GaugeValue, st.XputDownload, labels}, + {u.USG.XputUpload, prometheus.GaugeValue, st.XputUpload, labels}, + }) } func (u *unifiCollector) exportWANPorts(r *Report, labels []string, wans ...unifi.Wan) { diff --git a/integrations/promunifi/promunifi/usw.go b/integrations/promunifi/promunifi/usw.go index 29f77544..dd7dd660 100644 --- a/integrations/promunifi/promunifi/usw.go +++ b/integrations/promunifi/promunifi/usw.go @@ -70,9 +70,9 @@ func descUSW(ns string) *usw { } pns := ns + "port_" // The first five labels for switch are shared with (the same as) switch ports. - labels := []string{"type", "version", "ip", "site_name", "mac", "model", "name", "serial"} + labels := []string{"ip", "type", "version", "site_name", "mac", "model", "name", "serial"} // Copy labels, and replace first four with different names. - labelP := append([]string{"port_num", "port_name", "port_mac", "port_ip"}, labels[5:]...) + labelP := append([]string{"port_num", "port_name", "port_mac", "port_ip"}, labels[4:]...) return &usw{ // switch data @@ -149,7 +149,7 @@ func (u *unifiCollector) exportUSWs(r *Report) { } func (u *unifiCollector) exportUSW(r *Report, s *unifi.USW) { - labels := []string{s.Type, s.Version, s.IP, s.SiteName, s.Mac, s.Model, s.Name, s.Serial} + labels := []string{s.IP, s.Type, s.Version, s.SiteName, s.Mac, s.Model, s.Name, s.Serial} if s.HasTemperature.Val { r.send([]*metricExports{{u.USW.Temperature, prometheus.GaugeValue, s.GeneralTemperature, labels}}) @@ -176,24 +176,30 @@ func (u *unifiCollector) exportUSW(r *Report, s *unifi.USW) { {u.USW.MemBuffer, prometheus.GaugeValue, s.SysStats.MemBuffer, labels}, {u.USW.CPU, prometheus.GaugeValue, s.SystemStats.CPU, labels}, {u.USW.Mem, prometheus.GaugeValue, s.SystemStats.Mem, labels}, - {u.USW.SwRxPackets, prometheus.CounterValue, s.Stat.Sw.RxPackets, labels}, - {u.USW.SwRxBytes, prometheus.CounterValue, s.Stat.Sw.RxBytes, labels}, - {u.USW.SwRxErrors, prometheus.CounterValue, s.Stat.Sw.RxErrors, labels}, - {u.USW.SwRxDropped, prometheus.CounterValue, s.Stat.Sw.RxDropped, labels}, - {u.USW.SwRxCrypts, prometheus.CounterValue, s.Stat.Sw.RxCrypts, labels}, - {u.USW.SwRxFrags, prometheus.CounterValue, s.Stat.Sw.RxFrags, labels}, - {u.USW.SwTxPackets, prometheus.CounterValue, s.Stat.Sw.TxPackets, labels}, - {u.USW.SwTxBytes, prometheus.CounterValue, s.Stat.Sw.TxBytes, labels}, - {u.USW.SwTxErrors, prometheus.CounterValue, s.Stat.Sw.TxErrors, labels}, - {u.USW.SwTxDropped, prometheus.CounterValue, s.Stat.Sw.TxDropped, labels}, - {u.USW.SwTxRetries, prometheus.CounterValue, s.Stat.Sw.TxRetries, labels}, - {u.USW.SwRxMulticast, prometheus.CounterValue, s.Stat.Sw.RxMulticast, labels}, - {u.USW.SwRxBroadcast, prometheus.CounterValue, s.Stat.Sw.RxBroadcast, labels}, - {u.USW.SwTxMulticast, prometheus.CounterValue, s.Stat.Sw.TxMulticast, labels}, - {u.USW.SwTxBroadcast, prometheus.CounterValue, s.Stat.Sw.TxBroadcast, labels}, - {u.USW.SwBytes, prometheus.CounterValue, s.Stat.Sw.Bytes, labels}, }) - u.exportPortTable(r, s.PortTable, labels[5:]) + u.exportPortTable(r, s.PortTable, labels[4:]) + u.exportUSWstats(r, s.Stat.Sw, labels) +} + +func (u *unifiCollector) exportUSWstats(r *Report, s *unifi.Sw, labels []string) { + r.send([]*metricExports{ + {u.USW.SwRxPackets, prometheus.CounterValue, s.RxPackets, labels}, + {u.USW.SwRxBytes, prometheus.CounterValue, s.RxBytes, labels}, + {u.USW.SwRxErrors, prometheus.CounterValue, s.RxErrors, labels}, + {u.USW.SwRxDropped, prometheus.CounterValue, s.RxDropped, labels}, + {u.USW.SwRxCrypts, prometheus.CounterValue, s.RxCrypts, labels}, + {u.USW.SwRxFrags, prometheus.CounterValue, s.RxFrags, labels}, + {u.USW.SwTxPackets, prometheus.CounterValue, s.TxPackets, labels}, + {u.USW.SwTxBytes, prometheus.CounterValue, s.TxBytes, labels}, + {u.USW.SwTxErrors, prometheus.CounterValue, s.TxErrors, labels}, + {u.USW.SwTxDropped, prometheus.CounterValue, s.TxDropped, labels}, + {u.USW.SwTxRetries, prometheus.CounterValue, s.TxRetries, labels}, + {u.USW.SwRxMulticast, prometheus.CounterValue, s.RxMulticast, labels}, + {u.USW.SwRxBroadcast, prometheus.CounterValue, s.RxBroadcast, labels}, + {u.USW.SwTxMulticast, prometheus.CounterValue, s.TxMulticast, labels}, + {u.USW.SwTxBroadcast, prometheus.CounterValue, s.TxBroadcast, labels}, + {u.USW.SwBytes, prometheus.CounterValue, s.Bytes, labels}, + }) } func (u *unifiCollector) exportPortTable(r *Report, pt []unifi.Port, labels []string) {