From 02999a53a15242bead3b8bb50db51ae51a77e51a Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Thu, 28 Nov 2019 02:25:33 -0800 Subject: [PATCH] more fixes --- integrations/inputunifi/promunifi/clients.go | 94 +++++----- .../inputunifi/promunifi/collector.go | 31 ++-- integrations/inputunifi/promunifi/site.go | 173 +++++++++--------- integrations/inputunifi/promunifi/uap.go | 161 ++++++++-------- integrations/inputunifi/promunifi/udm.go | 21 ++- integrations/inputunifi/promunifi/usg.go | 131 ++++++------- integrations/inputunifi/promunifi/usw.go | 134 +++++++------- 7 files changed, 401 insertions(+), 344 deletions(-) diff --git a/integrations/inputunifi/promunifi/clients.go b/integrations/inputunifi/promunifi/clients.go index 5ad0e2ea..b6cbb54e 100644 --- a/integrations/inputunifi/promunifi/clients.go +++ b/integrations/inputunifi/promunifi/clients.go @@ -59,13 +59,13 @@ func descClient(ns string) *uclient { RxBytes: prometheus.NewDesc(ns+"receive_bytes_total", "Client Receive Bytes", labelWireless, wireless), RxBytesR: prometheus.NewDesc(ns+"receive_rate_bytes", "Client Receive Data Rate", labelWireless, wireless), RxPackets: prometheus.NewDesc(ns+"receive_packets_total", "Client Receive Packets", labelWireless, wireless), - RxRate: prometheus.NewDesc(ns+"radio_receive_rate", "Client Receive Rate", labelWireless, wireless), - Signal: prometheus.NewDesc(ns+"radio_signal", "Client Signal Strength", labelWireless, wireless), + RxRate: prometheus.NewDesc(ns+"radio_receive_rate_mbps", "Client Receive Rate", labelWireless, wireless), + Signal: prometheus.NewDesc(ns+"radio_signal_db", "Client Signal Strength", labelWireless, wireless), TxBytes: prometheus.NewDesc(ns+"transmit_bytes_total", "Client Transmit Bytes", labelWireless, wireless), TxBytesR: prometheus.NewDesc(ns+"transmit_rate_bytes", "Client Transmit Data Rate", labelWireless, wireless), TxPackets: prometheus.NewDesc(ns+"transmit_packets_total", "Client Transmit Packets", labelWireless, wireless), TxPower: prometheus.NewDesc(ns+"radio_transmit_power", "Client Transmit Power", labelWireless, wireless), - TxRate: prometheus.NewDesc(ns+"radio_transmit_rate", "Client Transmit Rate", labelWireless, wireless), + TxRate: prometheus.NewDesc(ns+"radio_transmit_rate_mbps", "Client Transmit Rate", labelWireless, wireless), WifiTxAttempts: prometheus.NewDesc(ns+"wifi_attempts_transmit_total", "Client Wifi Transmit Attempts", labelWireless, wireless), WiredRxBytes: prometheus.NewDesc(ns+"wired_receive_bytes_total", "Client Wired Receive Bytes", labelWired, wired), @@ -87,44 +87,56 @@ func descClient(ns string) *uclient { } } -func (u *unifiCollector) exportClients(clients []*unifi.Client, r *Report) { - for _, c := range clients { - labels := []string{c.Name, c.Mac, c.SiteName, c.GwMac, c.GwName, c.SwMac, c.SwName, c.Vlan.Txt, c.IP, c.Oui, c.Network} - labelWired := append([]string{c.SwPort.Txt}, labels...) - labelWireless := append([]string{c.ApMac, c.ApName, c.RadioName, c.Radio, c.RadioProto, c.Channel.Txt, c.Essid, c.Bssid, c.RadioDescription}, labels...) - - if c.IsWired.Val { - r.ch <- []*metricExports{ - {u.Client.WiredRxBytes, prometheus.CounterValue, c.WiredRxBytes, labelWired}, - {u.Client.WiredRxBytesR, prometheus.GaugeValue, c.WiredRxBytesR, labelWired}, - {u.Client.WiredRxPackets, prometheus.CounterValue, c.WiredRxPackets, labelWired}, - {u.Client.WiredTxBytes, prometheus.CounterValue, c.WiredTxBytes, labelWired}, - {u.Client.WiredTxBytesR, prometheus.GaugeValue, c.WiredTxBytesR, labelWired}, - {u.Client.WiredTxPackets, prometheus.CounterValue, c.WiredTxPackets, labelWired}, - {u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labels}, - } - } else { - r.ch <- []*metricExports{ - {u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, labelWireless}, - {u.Client.CCQ, prometheus.GaugeValue, c.Ccq, labelWireless}, - {u.Client.Noise, prometheus.GaugeValue, c.Noise, labelWireless}, - {u.Client.RoamCount, prometheus.CounterValue, c.RoamCount, labelWireless}, - {u.Client.RSSI, prometheus.GaugeValue, c.Rssi, labelWireless}, - {u.Client.Signal, prometheus.GaugeValue, c.Signal, labelWireless}, - {u.Client.TxPower, prometheus.GaugeValue, c.TxPower, labelWireless}, - {u.Client.TxRate, prometheus.GaugeValue, c.TxRate, labelWireless}, - {u.Client.WifiTxAttempts, prometheus.CounterValue, c.WifiTxAttempts, labelWireless}, - {u.Client.RxRate, prometheus.GaugeValue, c.RxRate, labelWireless}, - {u.Client.TxBytes, prometheus.CounterValue, c.TxBytes, labelWireless}, - {u.Client.TxBytesR, prometheus.GaugeValue, c.TxBytesR, labelWireless}, - {u.Client.TxPackets, prometheus.CounterValue, c.TxPackets, labelWireless}, - {u.Client.RxBytes, prometheus.CounterValue, c.RxBytes, labelWireless}, - {u.Client.RxBytesR, prometheus.GaugeValue, c.RxBytesR, labelWireless}, - {u.Client.RxPackets, prometheus.CounterValue, c.RxPackets, labelWireless}, - {u.Client.BytesR, prometheus.GaugeValue, c.BytesR, labelWireless}, - {u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labels}, - } +func (u *unifiCollector) exportClients(r *Report) { + if r.Metrics == nil || len(r.Metrics.Clients) < 1 { + return + } + r.wg.Add(1) + go func() { + defer r.wg.Done() + for _, c := range r.Metrics.Clients { + u.exportClient(r, c) } + }() +} + +func (u *unifiCollector) exportClient(r *Report, c *unifi.Client) { + labels := []string{c.Name, c.Mac, c.SiteName, c.GwMac, c.GwName, c.SwMac, c.SwName, c.Vlan.Txt, c.IP, c.Oui, c.Network} + labelWired := append([]string{c.SwPort.Txt}, labels...) + labelWireless := append([]string{c.ApMac, c.ApName, c.RadioName, c.Radio, c.RadioProto, c.Channel.Txt, c.Essid, c.Bssid, c.RadioDescription}, labels...) + + if c.IsWired.Val { + r.send([]*metricExports{ + {u.Client.WiredRxBytes, prometheus.CounterValue, c.WiredRxBytes, labelWired}, + {u.Client.WiredRxBytesR, prometheus.GaugeValue, c.WiredRxBytesR, labelWired}, + {u.Client.WiredRxPackets, prometheus.CounterValue, c.WiredRxPackets, labelWired}, + {u.Client.WiredTxBytes, prometheus.CounterValue, c.WiredTxBytes, labelWired}, + {u.Client.WiredTxBytesR, prometheus.GaugeValue, c.WiredTxBytesR, labelWired}, + {u.Client.WiredTxPackets, prometheus.CounterValue, c.WiredTxPackets, labelWired}, + }) + } else { + r.send([]*metricExports{ + {u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, labelWireless}, + {u.Client.CCQ, prometheus.GaugeValue, c.Ccq, labelWireless}, + {u.Client.Noise, prometheus.GaugeValue, c.Noise, labelWireless}, + {u.Client.RoamCount, prometheus.CounterValue, c.RoamCount, labelWireless}, + {u.Client.RSSI, prometheus.GaugeValue, c.Rssi, labelWireless}, + {u.Client.Signal, prometheus.GaugeValue, c.Signal, labelWireless}, + {u.Client.TxPower, prometheus.GaugeValue, c.TxPower, labelWireless}, + {u.Client.TxRate, prometheus.GaugeValue, c.TxRate / 1000, labelWireless}, + {u.Client.WifiTxAttempts, prometheus.CounterValue, c.WifiTxAttempts, labelWireless}, + {u.Client.RxRate, prometheus.GaugeValue, c.RxRate / 1000, labelWireless}, + {u.Client.TxBytes, prometheus.CounterValue, c.TxBytes, labelWireless}, + {u.Client.TxBytesR, prometheus.GaugeValue, c.TxBytesR, labelWireless}, + {u.Client.TxPackets, prometheus.CounterValue, c.TxPackets, labelWireless}, + {u.Client.RxBytes, prometheus.CounterValue, c.RxBytes, labelWireless}, + {u.Client.RxBytesR, prometheus.GaugeValue, c.RxBytesR, labelWireless}, + {u.Client.RxPackets, prometheus.CounterValue, c.RxPackets, labelWireless}, + {u.Client.BytesR, prometheus.GaugeValue, c.BytesR, labelWireless}, + }) + } + r.send([]*metricExports{ + {u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labels}, /* needs more "looking into" {u.Client.DpiStatsApp, prometheus.GaugeValue, c.DpiStats.App, labels}, {u.Client.DpiStatsCat, prometheus.GaugeValue, c.DpiStats.Cat, labels}, @@ -133,5 +145,5 @@ func (u *unifiCollector) exportClients(clients []*unifi.Client, r *Report) { {u.Client.DpiStatsTxBytes, prometheus.CounterValue, c.DpiStats.TxBytes, labels}, {u.Client.DpiStatsTxPackets, prometheus.CounterValue, c.DpiStats.TxPackets, labels}, */ - } + }) } diff --git a/integrations/inputunifi/promunifi/collector.go b/integrations/inputunifi/promunifi/collector.go index 0ea3e588..9bdbdd29 100644 --- a/integrations/inputunifi/promunifi/collector.go +++ b/integrations/inputunifi/promunifi/collector.go @@ -104,7 +104,7 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) { // the current metrics (from another package) then exports them for prometheus. func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { var err error - r := &Report{Start: time.Now(), ch: make(chan []*metricExports)} + r := &Report{Start: time.Now(), ch: make(chan []*metricExports, 50)} defer func() { r.wg.Wait() close(r.ch) @@ -116,26 +116,18 @@ func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { return } - go u.exportMetrics(ch, r) - - r.wg.Add(len(r.Metrics.Clients) + len(r.Metrics.Sites)) - go u.exportClients(r.Metrics.Clients, r) - go u.exportSites(r.Metrics.Sites, r) - - if r.Metrics.Devices == nil { - return - } - - r.wg.Add(len(r.Metrics.UAPs) + len(r.Metrics.USWs) + len(r.Metrics.USGs) + len(r.Metrics.UDMs)) - go u.exportUAPs(r.Metrics.UAPs, r) - go u.exportUSWs(r.Metrics.USWs, r) - go u.exportUSGs(r.Metrics.USGs, r) - u.exportUDMs(r.Metrics.UDMs, r) + go u.exportMetrics(r, ch) + u.exportClients(r) + u.exportSites(r) + u.exportUAPs(r) + u.exportUSWs(r) + u.exportUSGs(r) + u.exportUDMs(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 *unifiCollector) exportMetrics(ch chan<- prometheus.Metric, r *Report) { +func (u *unifiCollector) exportMetrics(r *Report, ch chan<- prometheus.Metric) { descs := make(map[*prometheus.Desc]bool) // used as a counter for newMetrics := range r.ch { for _, m := range newMetrics { @@ -174,3 +166,8 @@ func (u *unifiCollector) exportMetrics(ch chan<- prometheus.Metric, r *Report) { r.Descs, r.Elapsed = len(descs), time.Since(r.Start) u.Config.LoggingFn(r) } + +func (r *Report) send(m []*metricExports) { + r.wg.Add(1) + r.ch <- m +} diff --git a/integrations/inputunifi/promunifi/site.go b/integrations/inputunifi/promunifi/site.go index 61ebbe05..731f844f 100644 --- a/integrations/inputunifi/promunifi/site.go +++ b/integrations/inputunifi/promunifi/site.go @@ -50,27 +50,27 @@ func descSite(ns string) *site { labels := []string{"subsystem", "status", "name", "desc", "site_name"} return &site{ - NumUser: prometheus.NewDesc(ns+"num_user_total", "Number of Users", labels, nil), - NumGuest: prometheus.NewDesc(ns+"num_guest_total", "Number of Guests", labels, nil), - NumIot: prometheus.NewDesc(ns+"num_iot_total", "Number of IoT Devices", labels, nil), + NumUser: prometheus.NewDesc(ns+"num_user", "Number of Users", labels, nil), + NumGuest: prometheus.NewDesc(ns+"num_guest", "Number of Guests", labels, nil), + NumIot: prometheus.NewDesc(ns+"num_iot", "Number of IoT Devices", labels, nil), TxBytesR: prometheus.NewDesc(ns+"transmit_rate_bytes", "Bytes Transmit Rate", labels, nil), RxBytesR: prometheus.NewDesc(ns+"receive_rate_bytes", "Bytes Receive Rate", labels, nil), - NumAp: prometheus.NewDesc(ns+"num_ap_total", "Access Point Count", labels, nil), - NumAdopted: prometheus.NewDesc(ns+"num_adopted_total", "Adoption Count", labels, nil), - NumDisabled: prometheus.NewDesc(ns+"num_disabled_total", "Disabled Count", labels, nil), - NumDisconnected: prometheus.NewDesc(ns+"num_disconnected_total", "Disconnected Count", labels, nil), - NumPending: prometheus.NewDesc(ns+"num_pending_total", "Pending Count", labels, nil), - NumGw: prometheus.NewDesc(ns+"num_gateways_total", "Gateway Count", labels, nil), - NumSw: prometheus.NewDesc(ns+"num_switches_total", "Switch Count", labels, nil), - NumSta: prometheus.NewDesc(ns+"num_stations_total", "Station Count", labels, nil), - Latency: prometheus.NewDesc(ns+"latency_ms", "Latency", labels, nil), + NumAp: prometheus.NewDesc(ns+"num_ap", "Access Point Count", labels, nil), + NumAdopted: prometheus.NewDesc(ns+"num_adopted", "Adoption Count", labels, nil), + NumDisabled: prometheus.NewDesc(ns+"num_disabled", "Disabled Count", labels, nil), + NumDisconnected: prometheus.NewDesc(ns+"num_disconnected", "Disconnected Count", labels, nil), + NumPending: prometheus.NewDesc(ns+"num_pending", "Pending Count", labels, nil), + NumGw: prometheus.NewDesc(ns+"num_gateways", "Gateway Count", labels, nil), + NumSw: prometheus.NewDesc(ns+"num_switches", "Switch Count", labels, nil), + NumSta: prometheus.NewDesc(ns+"num_stations", "Station Count", labels, nil), + Latency: prometheus.NewDesc(ns+"latency_seconds", "Latency", labels, nil), Uptime: prometheus.NewDesc(ns+"uptime_seconds", "Uptime", labels, nil), Drops: prometheus.NewDesc(ns+"intenet_drops_total", "Internet (WAN) Disconnections", labels, nil), XputUp: prometheus.NewDesc(ns+"xput_up_rate", "Speedtest Upload", labels, nil), XputDown: prometheus.NewDesc(ns+"xput_down_rate", "Speedtest Download", labels, nil), SpeedtestPing: prometheus.NewDesc(ns+"speedtest_ping", "Speedtest Ping", labels, nil), - RemoteUserNumActive: prometheus.NewDesc(ns+"num_remote_user_active_total", "Remote Users Active", labels, nil), - RemoteUserNumInactive: prometheus.NewDesc(ns+"num_remote_user_inactive_total", "Remote Users Inactive", labels, nil), + RemoteUserNumActive: prometheus.NewDesc(ns+"num_remote_user_active", "Remote Users Active", labels, nil), + RemoteUserNumInactive: prometheus.NewDesc(ns+"num_remote_user_inactive", "Remote Users Inactive", labels, nil), RemoteUserRxBytes: prometheus.NewDesc(ns+"remote_user_receive_bytes_total", "Remote Users Receive Bytes", labels, nil), RemoteUserTxBytes: prometheus.NewDesc(ns+"remote_user_transmit_bytes_total", "Remote Users Transmit Bytes", labels, nil), RemoteUserRxPackets: prometheus.NewDesc(ns+"remote_user_receive_packets_total", "Remote Users Receive Packets", labels, nil), @@ -78,78 +78,85 @@ func descSite(ns string) *site { } } -func (u *unifiCollector) exportSites(sites unifi.Sites, r *Report) { - for _, s := range sites { - metrics := []*metricExports{} - labels := []string{s.Name, s.Desc, s.SiteName} +func (u *unifiCollector) exportSites(r *Report) { + if r.Metrics == nil || len(r.Metrics.Sites) < 1 { + return + } + r.wg.Add(1) + go func() { + defer r.wg.Done() + for _, s := range r.Metrics.Sites { + u.exportSite(r, s) + } + }() +} - for _, h := range s.Health { - l := append([]string{h.Subsystem, h.Status}, labels...) +func (u *unifiCollector) exportSite(r *Report, s *unifi.Site) { + labels := []string{s.Name, s.Desc, s.SiteName} + for _, h := range s.Health { + l := append([]string{h.Subsystem, h.Status}, labels...) - if h.Subsystem != subsystemVPN { - metrics = append(metrics, []*metricExports{ - {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR.Val, l}, - {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR.Val, l}, - }...) - } else { - metrics = append(metrics, []*metricExports{ - {u.Site.RemoteUserNumActive, prometheus.CounterValue, h.RemoteUserNumActive.Val, l}, - {u.Site.RemoteUserNumInactive, prometheus.CounterValue, h.RemoteUserNumInactive.Val, l}, - {u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes.Val, l}, - {u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes.Val, l}, - {u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets.Val, l}, - {u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets.Val, l}, - }...) - } - - if h.Subsystem == subsystemWWW { - metrics = append(metrics, []*metricExports{ - {u.Site.Uptime, prometheus.GaugeValue, h.Latency.Val, l}, - {u.Site.Latency, prometheus.GaugeValue, h.Latency.Val, l}, - {u.Site.XputUp, prometheus.GaugeValue, h.XputUp.Val, l}, - {u.Site.XputDown, prometheus.GaugeValue, h.XputDown.Val, l}, - {u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing.Val, l}, - {u.Site.Drops, prometheus.CounterValue, h.Drops.Val, l}, - }...) - } - - if h.Subsystem == subsystemLAN || h.Subsystem == subsystemWLAN || h.Subsystem == subsystemWAN { - metrics = append(metrics, []*metricExports{ - {u.Site.NumAdopted, prometheus.CounterValue, h.NumAdopted.Val, l}, - {u.Site.NumDisconnected, prometheus.CounterValue, h.NumDisconnected.Val, l}, - {u.Site.NumPending, prometheus.CounterValue, h.NumPending.Val, l}, - }...) - - if h.Subsystem == subsystemLAN || h.Subsystem == subsystemWLAN { - metrics = append(metrics, []*metricExports{ - {u.Site.NumUser, prometheus.CounterValue, h.NumUser.Val, l}, - {u.Site.NumGuest, prometheus.CounterValue, h.NumGuest.Val, l}, - {u.Site.NumIot, prometheus.CounterValue, h.NumIot.Val, l}, - }...) - } - - if h.Subsystem == subsystemWLAN { - metrics = append(metrics, []*metricExports{ - {u.Site.NumAp, prometheus.CounterValue, h.NumAp.Val, l}, - {u.Site.NumDisabled, prometheus.CounterValue, h.NumDisabled.Val, l}, - }...) - } - - if h.Subsystem == subsystemWAN { - metrics = append(metrics, []*metricExports{ - {u.Site.NumGw, prometheus.CounterValue, h.NumGw.Val, l}, - {u.Site.NumSta, prometheus.CounterValue, h.NumSta.Val, l}, - }...) - } - - if h.Subsystem == subsystemLAN { - metrics = append(metrics, []*metricExports{ - {u.Site.NumSw, prometheus.CounterValue, h.NumSw.Val, l}, - }...) - } - } + if h.Subsystem != subsystemVPN { + r.send([]*metricExports{ + {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, l}, + {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, l}, + }) + } else { + r.send([]*metricExports{ + {u.Site.RemoteUserNumActive, prometheus.GaugeValue, h.RemoteUserNumActive, l}, + {u.Site.RemoteUserNumInactive, prometheus.GaugeValue, h.RemoteUserNumInactive, l}, + {u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes, l}, + {u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes, l}, + {u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets, l}, + {u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets, l}, + }) } - r.ch <- metrics + if h.Subsystem == subsystemWWW { + r.send([]*metricExports{ + {u.Site.Uptime, prometheus.GaugeValue, h.Latency, l}, + {u.Site.Latency, prometheus.GaugeValue, h.Latency.Val / 1000, l}, + {u.Site.XputUp, prometheus.GaugeValue, h.XputUp, l}, + {u.Site.XputDown, prometheus.GaugeValue, h.XputDown, l}, + {u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing, l}, + {u.Site.Drops, prometheus.CounterValue, h.Drops, l}, + }) + } + + if h.Subsystem == subsystemLAN || h.Subsystem == subsystemWLAN || h.Subsystem == subsystemWAN { + r.send([]*metricExports{ + {u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, l}, + {u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, l}, + {u.Site.NumPending, prometheus.GaugeValue, h.NumPending, l}, + }) + + if h.Subsystem == subsystemLAN || h.Subsystem == subsystemWLAN { + r.send([]*metricExports{ + {u.Site.NumUser, prometheus.GaugeValue, h.NumUser, l}, + {u.Site.NumGuest, prometheus.GaugeValue, h.NumGuest, l}, + {u.Site.NumIot, prometheus.GaugeValue, h.NumIot, l}, + }) + } + + if h.Subsystem == subsystemWLAN { + r.send([]*metricExports{ + {u.Site.NumAp, prometheus.GaugeValue, h.NumAp, l}, + {u.Site.NumDisabled, prometheus.GaugeValue, h.NumDisabled, l}, + }) + } + + if h.Subsystem == subsystemWAN { + r.send([]*metricExports{ + {u.Site.NumGw, prometheus.GaugeValue, h.NumGw, l}, + {u.Site.NumSta, prometheus.GaugeValue, h.NumSta, l}, + }) + } + + if h.Subsystem == subsystemLAN { + r.send([]*metricExports{ + {u.Site.NumSw, prometheus.GaugeValue, h.NumSw, l}, + }) + } + } } } diff --git a/integrations/inputunifi/promunifi/uap.go b/integrations/inputunifi/promunifi/uap.go index 32c4195b..5c3ea2f3 100644 --- a/integrations/inputunifi/promunifi/uap.go +++ b/integrations/inputunifi/promunifi/uap.go @@ -49,6 +49,7 @@ type uap struct { VAPAvgClientSignal *prometheus.Desc VAPSatisfaction *prometheus.Desc VAPSatisfactionNow *prometheus.Desc + VAPDNSAvgLatency *prometheus.Desc VAPRxBytes *prometheus.Desc VAPRxCrypts *prometheus.Desc VAPRxDropped *prometheus.Desc @@ -106,11 +107,10 @@ func descUAP(ns string) *uap { if ns += "_uap_"; ns == "_uap_" { ns = "uap_" } - labels := []string{"ip", "site_name", "mac", "model", "name", "serial", "site_id", - "type", "version", "device_id"} + labels := []string{"ip", "site_name", "mac", "model", "name", "serial", "type", "version"} labelA := append([]string{"stat"}, labels[2:]...) - labelV := append([]string{"vap_name", "bssid", "radio_name", "essid"}, labels[2:]...) - labelR := append([]string{"radio_name", "radio", "wlan_group_id"}, labels[2:]...) + labelV := append([]string{"vap_name", "bssid", "radio_name", "essid", "usage"}, labels[2:]...) + labelR := append([]string{"radio_name", "radio"}, labels[2:]...) return &uap{ Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil), @@ -121,9 +121,9 @@ func descUAP(ns string) *uap { TxBytesD: prometheus.NewDesc(ns+"d_tranmsit_bytes", "Transmit Bytes D???", labels, nil), RxBytesD: prometheus.NewDesc(ns+"d_receive_bytes", "Receive Bytes D???", labels, nil), BytesR: prometheus.NewDesc(ns+"rate_bytes", "Transfer Rate", labels, nil), - NumSta: prometheus.NewDesc(ns+"num_stations_total", "Number of Stations", labels, nil), - UserNumSta: prometheus.NewDesc(ns+"num_stations_user_total", "Number of User Stations", labels, nil), - GuestNumSta: prometheus.NewDesc(ns+"num_stations_guest_total", "Number of Guest Stations", labels, nil), + NumSta: prometheus.NewDesc(ns+"num_stations", "Number of Stations", labels, nil), + UserNumSta: prometheus.NewDesc(ns+"num_stations_user", "Number of User Stations", labels, nil), + GuestNumSta: prometheus.NewDesc(ns+"num_stations_guest", "Number of Guest Stations", labels, nil), Loadavg1: prometheus.NewDesc(ns+"load_average_1", "System Load Average 1 Minute", labels, nil), Loadavg5: prometheus.NewDesc(ns+"load_average_5", "System Load Average 5 Minutes", labels, nil), Loadavg15: prometheus.NewDesc(ns+"load_average_15", "System Load Average 15 Minutes", labels, nil), @@ -155,8 +155,9 @@ func descUAP(ns string) *uap { VAPMacFilterRejections: prometheus.NewDesc(ns+"vap_mac_filter_rejects_total", "VAP MAC Filter Rejections", labelV, nil), VAPNumSatisfactionSta: prometheus.NewDesc(ns+"vap_num_satisfaction_stations", "VAP Number Satisifaction Stations", labelV, nil), VAPAvgClientSignal: prometheus.NewDesc(ns+"vap_average_client_signal", "VAP Average Client Signal", labelV, nil), - VAPSatisfaction: prometheus.NewDesc(ns+"vap_satisfaction", "VAP Satisfaction", labelV, nil), - VAPSatisfactionNow: prometheus.NewDesc(ns+"vap_satisfaction_now", "VAP Satisfaction Now", labelV, nil), + VAPSatisfaction: prometheus.NewDesc(ns+"vap_satisfaction_percent", "VAP Satisfaction", labelV, nil), + VAPSatisfactionNow: prometheus.NewDesc(ns+"vap_satisfaction_now_percent", "VAP Satisfaction Now", labelV, nil), + VAPDNSAvgLatency: prometheus.NewDesc(ns+"vap_dns_latency_average_seconds", "VAP DNS Latency Average", labelV, nil), VAPRxBytes: prometheus.NewDesc(ns+"vap_receive_bytes_total", "VAP Bytes Received", labelV, nil), VAPRxCrypts: prometheus.NewDesc(ns+"vap_receive_crypts_total", "VAP Crypts Received", labelV, nil), VAPRxDropped: prometheus.NewDesc(ns+"vap_receive_dropped_total", "VAP Dropped Received", labelV, nil), @@ -172,20 +173,20 @@ func descUAP(ns string) *uap { VAPTxRetries: prometheus.NewDesc(ns+"vap_transmit_retries_total", "VAP Retries Transmitted", labelV, nil), VAPTxCombinedRetries: prometheus.NewDesc(ns+"vap_transmit_retries_combined_total", "VAP Retries Combined Transmitted", labelV, nil), VAPTxDataMpduBytes: prometheus.NewDesc(ns+"vap_data_mpdu_transmit_bytes_total", "VAP Data MPDU Bytes Transmitted", labelV, nil), - VAPTxRtsRetries: prometheus.NewDesc(ns+"vap_trnamsit_rts_retries_total", "VAP RTS Retries Transmitted", labelV, nil), + VAPTxRtsRetries: prometheus.NewDesc(ns+"vap_transmit_rts_retries_total", "VAP RTS Retries Transmitted", labelV, nil), VAPTxSuccess: prometheus.NewDesc(ns+"vap_transmit_success_total", "VAP Success Transmits", labelV, nil), VAPTxTotal: prometheus.NewDesc(ns+"vap_transmit_total", "VAP Transmit Total", labelV, nil), VAPTxGoodbytes: prometheus.NewDesc(ns+"vap_transmit_goodbyes", "VAP Goodbyes Transmitted", labelV, nil), - VAPTxLatAvg: prometheus.NewDesc(ns+"vap_transmit_latency_average", "VAP Latency Average Transmit", labelV, nil), - VAPTxLatMax: prometheus.NewDesc(ns+"vap_transmit_latency_maximum", "VAP Latency Maximum Transmit", labelV, nil), - VAPTxLatMin: prometheus.NewDesc(ns+"vap_transmit_latency_minimum", "VAP Latency Minimum Transmit", labelV, nil), + VAPTxLatAvg: prometheus.NewDesc(ns+"vap_transmit_latency_average_seconds", "VAP Latency Average Transmit", labelV, nil), + VAPTxLatMax: prometheus.NewDesc(ns+"vap_transmit_latency_maximum_seconds", "VAP Latency Maximum Transmit", labelV, nil), + VAPTxLatMin: prometheus.NewDesc(ns+"vap_transmit_latency_minimum_seconds", "VAP Latency Minimum Transmit", labelV, nil), VAPRxGoodbytes: prometheus.NewDesc(ns+"vap_receive_goodbyes", "VAP Goodbyes Received", labelV, nil), - VAPRxLatAvg: prometheus.NewDesc(ns+"vap_receive_latency_average", "VAP Latency Average Receive", labelV, nil), - VAPRxLatMax: prometheus.NewDesc(ns+"vap_receive_latency_maximum", "VAP Latency Maximum Receive", labelV, nil), - VAPRxLatMin: prometheus.NewDesc(ns+"vap_receive_latency_minimum", "VAP Latency Minimum Receive", labelV, nil), - VAPWifiTxLatencyMovAvg: prometheus.NewDesc(ns+"vap_transmit_latency_moving_avg", "VAP Latency Moving Average Tramsit", labelV, nil), - VAPWifiTxLatencyMovMax: prometheus.NewDesc(ns+"vap_transmit_latency_moving_max", "VAP Latency Moving Maximum Tramsit", labelV, nil), - VAPWifiTxLatencyMovMin: prometheus.NewDesc(ns+"vap_transmit_latency_moving_min", "VAP Latency Moving Minimum Tramsit", labelV, nil), + VAPRxLatAvg: prometheus.NewDesc(ns+"vap_receive_latency_average_seconds", "VAP Latency Average Receive", labelV, nil), + VAPRxLatMax: prometheus.NewDesc(ns+"vap_receive_latency_maximum_seconds", "VAP Latency Maximum Receive", labelV, nil), + VAPRxLatMin: prometheus.NewDesc(ns+"vap_receive_latency_minimum_seconds", "VAP Latency Minimum Receive", labelV, nil), + VAPWifiTxLatencyMovAvg: prometheus.NewDesc(ns+"vap_transmit_latency_moving_avg_seconds", "VAP Latency Moving Average Tramsit", labelV, nil), + VAPWifiTxLatencyMovMax: prometheus.NewDesc(ns+"vap_transmit_latency_moving_max_seconds", "VAP Latency Moving Maximum Tramsit", labelV, nil), + VAPWifiTxLatencyMovMin: prometheus.NewDesc(ns+"vap_transmit_latency_moving_min_seconds", "VAP Latency Moving Minimum Tramsit", labelV, nil), VAPWifiTxLatencyMovTotal: prometheus.NewDesc(ns+"vap_transmit_latency_moving_total", "VAP Latency Moving Total Tramsit", labelV, nil), VAPWifiTxLatencyMovCount: prometheus.NewDesc(ns+"vap_transmit_latency_moving_count", "VAP Latency Moving Count Tramsit", labelV, nil), @@ -204,52 +205,62 @@ func descUAP(ns string) *uap { RadioCuTotal: prometheus.NewDesc(ns+"radio_channel_utilization_total", "Radio Channel Utilization", labelR, nil), RadioExtchannel: prometheus.NewDesc(ns+"radio_ext_channel", "Radio Ext Channel", labelR, nil), RadioGain: prometheus.NewDesc(ns+"radio_gain", "Radio Gain", labelR, nil), - RadioGuestNumSta: prometheus.NewDesc(ns+"radio_num_guest_stations_total", "Radio Guest Station Count", labelR, nil), - RadioNumSta: prometheus.NewDesc(ns+"radio_num_stations_total", "Radio Total Station Count", labelR, nil), - RadioUserNumSta: prometheus.NewDesc(ns+"radio_num_user_stations_total", "Radio User Station Count", labelR, nil), + RadioGuestNumSta: prometheus.NewDesc(ns+"radio_num_guest_stations", "Radio Guest Station Count", labelR, nil), + RadioNumSta: prometheus.NewDesc(ns+"radio_num_stations", "Radio Total Station Count", labelR, nil), + RadioUserNumSta: prometheus.NewDesc(ns+"radio_num_user_stations", "Radio User Station Count", labelR, nil), RadioTxPackets: prometheus.NewDesc(ns+"radio_transmit_packets_total", "Radio Transmitted Packets", labelR, nil), RadioTxRetries: prometheus.NewDesc(ns+"radio_transmit_retries_total", "Radio Transmit Retries", labelR, nil), } } -func (u *unifiCollector) exportUAPs(uaps []*unifi.UAP, r *Report) { - for _, a := range uaps { - labels := []string{a.IP, a.SiteName, a.Mac, a.Model, a.Name, a.Serial, a.SiteID, - a.Type, a.Version, a.DeviceID} - - // AP data. - r.ch <- append(append([]*metricExports{ - {u.UAP.Uptime, prometheus.GaugeValue, a.Uptime, labels}, - {u.UAP.TotalTxBytes, prometheus.CounterValue, a.TxBytes, labels}, - {u.UAP.TotalRxBytes, prometheus.CounterValue, a.RxBytes, labels}, - {u.UAP.TotalBytes, prometheus.CounterValue, a.Bytes, labels}, - {u.UAP.BytesD, prometheus.CounterValue, a.BytesD, labels}, // not sure if these 3 Ds are counters or gauges. - {u.UAP.TxBytesD, prometheus.CounterValue, a.TxBytesD, labels}, // not sure if these 3 Ds are counters or gauges. - {u.UAP.RxBytesD, prometheus.CounterValue, a.RxBytesD, labels}, // not sure if these 3 Ds are counters or gauges. - {u.UAP.BytesR, prometheus.GaugeValue, a.BytesR, labels}, - {u.UAP.NumSta, prometheus.GaugeValue, a.NumSta, labels}, - {u.UAP.UserNumSta, prometheus.GaugeValue, a.UserNumSta, labels}, - {u.UAP.GuestNumSta, prometheus.GaugeValue, a.GuestNumSta, labels}, - {u.UAP.Loadavg1, prometheus.GaugeValue, a.SysStats.Loadavg1, labels}, - {u.UAP.Loadavg5, prometheus.GaugeValue, a.SysStats.Loadavg5, labels}, - {u.UAP.Loadavg15, prometheus.GaugeValue, a.SysStats.Loadavg15, labels}, - {u.UAP.MemUsed, prometheus.GaugeValue, a.SysStats.MemUsed, labels}, - {u.UAP.MemTotal, prometheus.GaugeValue, a.SysStats.MemTotal, labels}, - {u.UAP.MemBuffer, prometheus.GaugeValue, a.SysStats.MemBuffer, labels}, - {u.UAP.CPU, prometheus.GaugeValue, a.SystemStats.CPU, labels}, - {u.UAP.Mem, prometheus.GaugeValue, a.SystemStats.Mem, labels}, - }, - u.exportUAPstat(labels[2:], a.Stat.Ap)...), - u.exportVAPtable(labels[2:], a.VapTable, a.RadioTable, a.RadioTableStats)...) +func (u *unifiCollector) exportUAPs(r *Report) { + if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.UAPs) < 1 { + return } + r.wg.Add(1) + go func() { + defer r.wg.Done() + for _, a := range r.Metrics.Devices.UAPs { + u.exportUAP(r, a) + } + }() } -func (u *unifiCollector) exportUAPstat(labels []string, a *unifi.Ap) []*metricExports { +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} + + // AP data. + r.send([]*metricExports{ + {u.UAP.Uptime, prometheus.GaugeValue, a.Uptime, labels}, + {u.UAP.TotalTxBytes, prometheus.CounterValue, a.TxBytes, labels}, + {u.UAP.TotalRxBytes, prometheus.CounterValue, a.RxBytes, labels}, + {u.UAP.TotalBytes, prometheus.CounterValue, a.Bytes, labels}, + {u.UAP.BytesD, prometheus.CounterValue, a.BytesD, labels}, // not sure if these 3 Ds are counters or gauges. + {u.UAP.TxBytesD, prometheus.CounterValue, a.TxBytesD, labels}, // not sure if these 3 Ds are counters or gauges. + {u.UAP.RxBytesD, prometheus.CounterValue, a.RxBytesD, labels}, // not sure if these 3 Ds are counters or gauges. + {u.UAP.BytesR, prometheus.GaugeValue, a.BytesR, labels}, + {u.UAP.NumSta, prometheus.GaugeValue, a.NumSta, labels}, + {u.UAP.UserNumSta, prometheus.GaugeValue, a.UserNumSta, labels}, + {u.UAP.GuestNumSta, prometheus.GaugeValue, a.GuestNumSta, labels}, + {u.UAP.Loadavg1, prometheus.GaugeValue, a.SysStats.Loadavg1, labels}, + {u.UAP.Loadavg5, prometheus.GaugeValue, a.SysStats.Loadavg5, labels}, + {u.UAP.Loadavg15, prometheus.GaugeValue, a.SysStats.Loadavg15, labels}, + {u.UAP.MemUsed, prometheus.GaugeValue, a.SysStats.MemUsed, labels}, + {u.UAP.MemTotal, prometheus.GaugeValue, a.SysStats.MemTotal, labels}, + {u.UAP.MemBuffer, prometheus.GaugeValue, a.SysStats.MemBuffer, labels}, + {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.exportVAPtable(r, labels[2:], a.VapTable, a.RadioTable, a.RadioTableStats) +} + +func (u *unifiCollector) exportUAPstat(r *Report, labels []string, a *unifi.Ap) { labelA := append([]string{"all"}, labels...) labelU := append([]string{"user"}, labels...) labelG := append([]string{"guest"}, labels...) - return []*metricExports{ + r.send([]*metricExports{ // all {u.UAP.ApWifiTxDropped, prometheus.CounterValue, a.WifiTxDropped, labelA}, {u.UAP.ApRxErrors, prometheus.CounterValue, a.RxErrors, labelA}, @@ -295,22 +306,25 @@ func (u *unifiCollector) exportUAPstat(labels []string, a *unifi.Ap) []*metricEx {u.UAP.ApRxBytes, prometheus.CounterValue, a.GuestRxBytes, labelG}, {u.UAP.WifiTxAttempts, prometheus.CounterValue, a.GuestWifiTxAttempts, labelG}, {u.UAP.MacFilterRejections, prometheus.CounterValue, a.GuestMacFilterRejections, labelG}, - } + }) } -func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats) []*metricExports { - metrics := []*metricExports{} +func (u *unifiCollector) exportVAPtable(r *Report, labels []string, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats) { // vap table stats for _, v := range vt { - labelV := append([]string{v.Name, v.Bssid, v.RadioName, v.Essid}, labels...) - metrics = append(metrics, []*metricExports{ + if !v.Up.Val { + continue + } + labelV := append([]string{v.Name, v.Bssid, v.RadioName, v.Essid, v.Usage}, labels...) + r.send([]*metricExports{ {u.UAP.VAPCcq, prometheus.GaugeValue, v.Ccq, labelV}, {u.UAP.VAPMacFilterRejections, prometheus.CounterValue, v.MacFilterRejections, labelV}, {u.UAP.VAPNumSatisfactionSta, prometheus.GaugeValue, v.NumSatisfactionSta, labelV}, {u.UAP.VAPAvgClientSignal, prometheus.GaugeValue, v.AvgClientSignal, labelV}, {u.UAP.VAPSatisfaction, prometheus.GaugeValue, v.Satisfaction, labelV}, {u.UAP.VAPSatisfactionNow, prometheus.GaugeValue, v.SatisfactionNow, 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}, @@ -329,39 +343,39 @@ func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt u {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, labelV}, - {u.UAP.VAPTxLatMax, prometheus.GaugeValue, v.TxTCPStats.LatMax, labelV}, - {u.UAP.VAPTxLatMin, prometheus.GaugeValue, v.TxTCPStats.LatMin, 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, labelV}, - {u.UAP.VAPRxLatMax, prometheus.GaugeValue, v.RxTCPStats.LatMax, labelV}, - {u.UAP.VAPRxLatMin, prometheus.GaugeValue, v.RxTCPStats.LatMin, labelV}, - {u.UAP.VAPWifiTxLatencyMovAvg, prometheus.GaugeValue, v.WifiTxLatencyMov.Avg, labelV}, - {u.UAP.VAPWifiTxLatencyMovMax, prometheus.GaugeValue, v.WifiTxLatencyMov.Max, labelV}, - {u.UAP.VAPWifiTxLatencyMovMin, prometheus.GaugeValue, v.WifiTxLatencyMov.Min, 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. - }...) + }) } // radio table for _, p := range rt { - labelR := append([]string{p.Name, p.Radio, p.WlangroupID}, labels...) - metrics = append(metrics, []*metricExports{ + labelR := append([]string{p.Name, p.Radio}, labels...) + r.send([]*metricExports{ {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}, - }...) + }) // combine radio table with radio stats table. for _, t := range rts { if t.Name != p.Name { continue } - metrics = append(metrics, []*metricExports{ + r.send([]*metricExports{ {u.UAP.RadioTxPower, prometheus.GaugeValue, t.TxPower, labelR}, {u.UAP.RadioAstBeXmit, prometheus.GaugeValue, t.AstBeXmit, labelR}, {u.UAP.RadioChannel, prometheus.GaugeValue, t.Channel, labelR}, @@ -375,8 +389,7 @@ func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt u {u.UAP.RadioUserNumSta, prometheus.GaugeValue, t.UserNumSta, labelR}, {u.UAP.RadioTxPackets, prometheus.CounterValue, t.TxPackets, labelR}, {u.UAP.RadioTxRetries, prometheus.CounterValue, t.TxRetries, labelR}, - }...) + }) } } - return metrics } diff --git a/integrations/inputunifi/promunifi/udm.go b/integrations/inputunifi/promunifi/udm.go index 17c3ea96..1ebc5c27 100644 --- a/integrations/inputunifi/promunifi/udm.go +++ b/integrations/inputunifi/promunifi/udm.go @@ -1,8 +1,6 @@ package promunifi -import ( - "golift.io/unifi" -) +import "golift.io/unifi" type udm struct { } @@ -11,6 +9,19 @@ func descUDM(ns string) *udm { return &udm{} } -func (u *unifiCollector) exportUDMs(udms []*unifi.UDM, r *Report) { - // for _, d := range udms { +func (u *unifiCollector) exportUDMs(r *Report) { + if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.UDMs) < 1 { + return + } + r.wg.Add(1) + go func() { + defer r.wg.Done() + for _, d := range r.Metrics.Devices.UDMs { + u.exportUDM(r, d) + } + }() +} + +func (u *unifiCollector) exportUDM(r *Report, d *unifi.UDM) { + // for _, d := range r.Metrics.Devices.UDMs { } diff --git a/integrations/inputunifi/promunifi/usg.go b/integrations/inputunifi/promunifi/usg.go index 396f0f6a..f758fa25 100644 --- a/integrations/inputunifi/promunifi/usg.go +++ b/integrations/inputunifi/promunifi/usg.go @@ -58,8 +58,7 @@ func descUSG(ns string) *usg { if ns += "_usg_"; ns == "_usg_" { ns = "usg_" } - labels := []string{"site_name", "mac", "model", "name", "serial", "site_id", - "type", "version", "ip"} + labels := []string{"site_name", "mac", "model", "name", "serial", "type", "version", "ip"} labelWan := append([]string{"port"}, labels...) return &usg{ @@ -67,12 +66,12 @@ func descUSG(ns string) *usg { TotalTxBytes: prometheus.NewDesc(ns+"transmit_bytes_total", "Total Transmitted Bytes", labels, nil), TotalRxBytes: prometheus.NewDesc(ns+"receive_bytes_total", "Total Received Bytes", labels, nil), TotalBytes: prometheus.NewDesc(ns+"transferred_bytes_total", "Total Bytes Transferred", labels, nil), - NumSta: prometheus.NewDesc(ns+"num_stations_total", "Number of Stations", labels, nil), - UserNumSta: prometheus.NewDesc(ns+"num_stations_user_total", "Number of User Stations", labels, nil), - GuestNumSta: prometheus.NewDesc(ns+"num_stations_guest_total", "Number of Guest Stations", labels, nil), - NumDesktop: prometheus.NewDesc(ns+"num_desktops_total", "Number of Desktops", labels, nil), - NumMobile: prometheus.NewDesc(ns+"num_mobile_total", "Number of Mobiles", labels, nil), - NumHandheld: prometheus.NewDesc(ns+"num_handheld_total", "Number of Handhelds", labels, nil), + NumSta: prometheus.NewDesc(ns+"num_stations", "Number of Stations", labels, nil), + UserNumSta: prometheus.NewDesc(ns+"num_stations_user", "Number of User Stations", labels, nil), + GuestNumSta: prometheus.NewDesc(ns+"num_stations_guest", "Number of Guest Stations", labels, nil), + NumDesktop: prometheus.NewDesc(ns+"num_desktops", "Number of Desktops", labels, nil), + NumMobile: prometheus.NewDesc(ns+"num_mobile", "Number of Mobiles", labels, nil), + NumHandheld: prometheus.NewDesc(ns+"num_handheld", "Number of Handhelds", labels, nil), Loadavg1: prometheus.NewDesc(ns+"load_average_1", "System Load Average 1 Minute", labels, nil), Loadavg5: prometheus.NewDesc(ns+"load_average_5", "System Load Average 5 Minutes", labels, nil), Loadavg15: prometheus.NewDesc(ns+"load_average_15", "System Load Average 15 Minutes", labels, nil), @@ -90,7 +89,7 @@ func descUSG(ns string) *usg { WanRxBroadcast: prometheus.NewDesc(ns+"wan_receive_broadcast_total", "WAN Receive Broadcast Total", labelWan, nil), WanRxBytesR: prometheus.NewDesc(ns+"wan_receive_rate_bytes", "WAN Receive Bytes Rate", labelWan, nil), WanRxMulticast: prometheus.NewDesc(ns+"wan_receive_multicast_total", "WAN Receive Multicast Total", labelWan, nil), - WanSpeed: prometheus.NewDesc(ns+"wan_speed", "WAN Speed", labelWan, nil), + WanSpeed: prometheus.NewDesc(ns+"wan_speed_mbps", "WAN Speed", labelWan, nil), WanTxBroadcast: prometheus.NewDesc(ns+"wan_transmit_broadcast_total", "WAN Transmit Broadcast Total", labelWan, nil), WanTxBytesR: prometheus.NewDesc(ns+"wan_transmit_rate_bytes", "WAN Transmit Bytes Rate", labelWan, nil), WanTxDropped: prometheus.NewDesc(ns+"wan_transmit_dropped_total", "WAN Transmit Dropped Total", labelWan, nil), @@ -102,69 +101,78 @@ func descUSG(ns string) *usg { LanRxDropped: prometheus.NewDesc(ns+"lan_receive_dropped_total", "LAN Receive Dropped Total", labels, nil), LanTxPackets: prometheus.NewDesc(ns+"lan_transmit_packets_total", "LAN Transmit Packets Total", labels, nil), LanTxBytes: prometheus.NewDesc(ns+"lan_transmit_bytes_total", "LAN Transmit Bytes Total", labels, nil), - Latency: prometheus.NewDesc(ns+"speedtest_latency", "Speedtest Latency", labels, nil), + Latency: prometheus.NewDesc(ns+"speedtest_latency_seconds", "Speedtest Latency", labels, nil), Runtime: prometheus.NewDesc(ns+"speedtest_runtime", "Speedtest Run Time", labels, nil), - XputDownload: prometheus.NewDesc(ns+"speedtest_download_rate", "Speedtest Download Rate", labels, nil), - XputUpload: prometheus.NewDesc(ns+"speedtest_upload_rate", "Speedtest Upload Rate", labels, nil), + XputDownload: prometheus.NewDesc(ns+"speedtest_download", "Speedtest Download Rate", labels, nil), + XputUpload: prometheus.NewDesc(ns+"speedtest_upload", "Speedtest Upload Rate", labels, nil), } } -func (u *unifiCollector) exportUSGs(usgs []*unifi.USG, r *Report) { - for _, s := range usgs { - labels := []string{s.SiteName, s.Mac, s.Model, s.Name, s.Serial, s.SiteID, - s.Type, s.Version, s.IP} - labelWan := append([]string{"all"}, labels...) - - // Gateway System Data. - r.ch <- append([]*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.CounterValue, s.NumDesktop, labels}, - {u.USG.NumMobile, prometheus.CounterValue, s.NumMobile, labels}, - {u.USG.NumHandheld, prometheus.CounterValue, 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}, - // 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, 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(labels, s.Wan1, s.Wan2)...) +func (u *unifiCollector) exportUSGs(r *Report) { + if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.USGs) < 1 { + return } + r.wg.Add(1) + go func() { + defer r.wg.Done() + for _, s := range r.Metrics.Devices.USGs { + u.exportUSG(r, s) + } + }() } -func (u *unifiCollector) exportWANPorts(labels []string, wans ...unifi.Wan) []*metricExports { - metrics := []*metricExports{} +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...) + + // 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}, + // 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) +} + +func (u *unifiCollector) exportWANPorts(r *Report, labels []string, wans ...unifi.Wan) { for _, wan := range wans { if !wan.Up.Val { continue // only record UP interfaces. } l := append([]string{wan.Name}, labels...) - - metrics = append(metrics, []*metricExports{ + r.send([]*metricExports{ {u.USG.WanRxPackets, prometheus.CounterValue, wan.RxPackets, l}, {u.USG.WanRxBytes, prometheus.CounterValue, wan.RxBytes, l}, {u.USG.WanRxDropped, prometheus.CounterValue, wan.RxDropped, l}, @@ -180,7 +188,6 @@ func (u *unifiCollector) exportWANPorts(labels []string, wans ...unifi.Wan) []*m {u.USG.WanTxErrors, prometheus.CounterValue, wan.TxErrors, l}, {u.USG.WanTxMulticast, prometheus.CounterValue, wan.TxMulticast, l}, {u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, l}, - }...) + }) } - return metrics } diff --git a/integrations/inputunifi/promunifi/usw.go b/integrations/inputunifi/promunifi/usw.go index 27bed744..92dc7ec9 100644 --- a/integrations/inputunifi/promunifi/usw.go +++ b/integrations/inputunifi/promunifi/usw.go @@ -70,8 +70,7 @@ 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", "site_id"} + labels := []string{"type", "version", "ip", "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:]...) @@ -84,9 +83,9 @@ func descUSW(ns string) *usw { TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil), TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil), TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil), - NumSta: prometheus.NewDesc(ns+"num_stations_total", "Number of Stations", labels, nil), - UserNumSta: prometheus.NewDesc(ns+"num_stations_user_total", "Number of User Stations", labels, nil), - GuestNumSta: prometheus.NewDesc(ns+"num_stations_guest_total", "Number of Guest Stations", labels, nil), + NumSta: prometheus.NewDesc(ns+"num_stations", "Number of Stations", labels, nil), + UserNumSta: prometheus.NewDesc(ns+"num_stations_user", "Number of User Stations", labels, nil), + GuestNumSta: prometheus.NewDesc(ns+"num_stations_guest", "Number of Guest Stations", labels, nil), Loadavg1: prometheus.NewDesc(ns+"load_average_1", "System Load Average 1 Minute", labels, nil), Loadavg5: prometheus.NewDesc(ns+"load_average_5", "System Load Average 5 Minutes", labels, nil), Loadavg15: prometheus.NewDesc(ns+"load_average_15", "System Load Average 15 Minutes", labels, nil), @@ -124,8 +123,8 @@ func descUSW(ns string) *usw { RxErrors: prometheus.NewDesc(pns+"receive_errors_total", "Total Receive Errors", labelP, nil), RxMulticast: prometheus.NewDesc(pns+"receive_multicast_total", "Total Receive Multicast", labelP, nil), RxPackets: prometheus.NewDesc(pns+"receive_packets_total", "Total Receive Packets", labelP, nil), - Satisfaction: prometheus.NewDesc(pns+"satisfaction", "Satisfaction", labelP, nil), - Speed: prometheus.NewDesc(pns+"port_speed", "Speed", labelP, nil), + Satisfaction: prometheus.NewDesc(pns+"satisfaction_percent", "Satisfaction", labelP, nil), + Speed: prometheus.NewDesc(pns+"port_speed_mbps", "Speed", labelP, nil), TxBroadcast: prometheus.NewDesc(pns+"transmit_broadcast_total", "Total Transmit Broadcast", labelP, nil), TxBytes: prometheus.NewDesc(pns+"transmit_bytes_total", "Total Transmit Bytes", labelP, nil), TxBytesR: prometheus.NewDesc(pns+"transmit_rate_bytes", "Transmit Bytes Rate", labelP, nil), @@ -136,71 +135,83 @@ func descUSW(ns string) *usw { } } -func (u *unifiCollector) exportUSWs(usws []*unifi.USW, r *Report) { - for _, s := range usws { - labels := []string{s.Type, s.Version, s.IP, - s.SiteName, s.Mac, s.Model, s.Name, s.Serial, s.SiteID} - - metrics := []*metricExports{} - if s.HasTemperature.Val { - metrics = append(metrics, &metricExports{u.USW.Temperature, prometheus.GaugeValue, s.GeneralTemperature, labels}) - } - if s.HasFan.Val { - metrics = append(metrics, &metricExports{u.USW.FanLevel, prometheus.GaugeValue, s.FanLevel, labels}) - } - - // Switch data. - r.ch <- append(metrics, append([]*metricExports{ - {u.USW.Uptime, prometheus.GaugeValue, s.Uptime, labels}, - {u.USW.TotalMaxPower, prometheus.GaugeValue, s.TotalMaxPower, labels}, - {u.USW.TotalTxBytes, prometheus.CounterValue, s.TxBytes, labels}, - {u.USW.TotalRxBytes, prometheus.CounterValue, s.RxBytes, labels}, - {u.USW.TotalBytes, prometheus.CounterValue, s.Bytes, labels}, - {u.USW.NumSta, prometheus.GaugeValue, s.NumSta, labels}, - {u.USW.UserNumSta, prometheus.GaugeValue, s.UserNumSta, labels}, - {u.USW.GuestNumSta, prometheus.GaugeValue, s.GuestNumSta, labels}, - {u.USW.Loadavg1, prometheus.GaugeValue, s.SysStats.Loadavg1, labels}, - {u.USW.Loadavg5, prometheus.GaugeValue, s.SysStats.Loadavg5, labels}, - {u.USW.Loadavg15, prometheus.GaugeValue, s.SysStats.Loadavg15, labels}, - {u.USW.MemUsed, prometheus.GaugeValue, s.SysStats.MemUsed, labels}, - {u.USW.MemTotal, prometheus.GaugeValue, s.SysStats.MemTotal, labels}, - {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(s.PortTable, labels[5:])...)...) +func (u *unifiCollector) exportUSWs(r *Report) { + if r.Metrics == nil || r.Metrics.Devices == nil || len(r.Metrics.Devices.USWs) < 1 { + return } + r.wg.Add(1) + go func() { + defer r.wg.Done() + for _, s := range r.Metrics.Devices.USWs { + u.exportUSW(r, s) + } + }() } -func (u *unifiCollector) exportPortTable(pt []unifi.Port, labels []string) []*metricExports { - metrics := []*metricExports{} +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} + + if s.HasTemperature.Val { + r.send([]*metricExports{{u.USW.Temperature, prometheus.GaugeValue, s.GeneralTemperature, labels}}) + } + if s.HasFan.Val { + r.send([]*metricExports{{u.USW.FanLevel, prometheus.GaugeValue, s.FanLevel, labels}}) + } + + // Switch data. + r.send([]*metricExports{ + {u.USW.Uptime, prometheus.GaugeValue, s.Uptime, labels}, + {u.USW.TotalMaxPower, prometheus.GaugeValue, s.TotalMaxPower, labels}, + {u.USW.TotalTxBytes, prometheus.CounterValue, s.TxBytes, labels}, + {u.USW.TotalRxBytes, prometheus.CounterValue, s.RxBytes, labels}, + {u.USW.TotalBytes, prometheus.CounterValue, s.Bytes, labels}, + {u.USW.NumSta, prometheus.GaugeValue, s.NumSta, labels}, + {u.USW.UserNumSta, prometheus.GaugeValue, s.UserNumSta, labels}, + {u.USW.GuestNumSta, prometheus.GaugeValue, s.GuestNumSta, labels}, + {u.USW.Loadavg1, prometheus.GaugeValue, s.SysStats.Loadavg1, labels}, + {u.USW.Loadavg5, prometheus.GaugeValue, s.SysStats.Loadavg5, labels}, + {u.USW.Loadavg15, prometheus.GaugeValue, s.SysStats.Loadavg15, labels}, + {u.USW.MemUsed, prometheus.GaugeValue, s.SysStats.MemUsed, labels}, + {u.USW.MemTotal, prometheus.GaugeValue, s.SysStats.MemTotal, labels}, + {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:]) +} + +func (u *unifiCollector) exportPortTable(r *Report, pt []unifi.Port, labels []string) { // Per-port data on a switch for _, p := range pt { + if !p.Up.Val { + continue + } // Copy labels, and add four new ones. l := append([]string{p.PortIdx.Txt, p.Name, p.Mac, p.IP}, labels...) if p.PoeEnable.Val && p.PortPoe.Val { - metrics = append(metrics, []*metricExports{ + r.send([]*metricExports{ {u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, l}, {u.USW.PoePower, prometheus.GaugeValue, p.PoePower, l}, {u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, l}, - }...) + }) } - metrics = append(metrics, []*metricExports{ + r.send([]*metricExports{ {u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, l}, {u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, l}, {u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, l}, @@ -216,7 +227,6 @@ func (u *unifiCollector) exportPortTable(pt []unifi.Port, labels []string) []*me {u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, l}, {u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, l}, {u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, l}, - }...) + }) } - return metrics }