diff --git a/promunifi/clients.go b/promunifi/clients.go index 68e8118c..546cd27f 100644 --- a/promunifi/clients.go +++ b/promunifi/clients.go @@ -82,50 +82,45 @@ func descClient(ns string) *uclient { } } -func (u *unifiCollector) exportClients(clients []*unifi.Client, ch chan []*metricExports) { +func (u *unifiCollector) exportClients(clients []*unifi.Client, r *Report) { for _, c := range clients { - ch <- u.exportClient(c) - } -} - -// CollectClient exports Clients' Data -func (u *unifiCollector) exportClient(c *unifi.Client) []*metricExports { - labels := []string{c.ID, c.Mac, c.UserID, c.SiteID, c.SiteName, - c.NetworkID, c.ApMac, c.GwMac, c.SwMac, c.ApName, c.GwName, - c.SwName, c.RadioName, c.Radio, c.RadioProto, c.Name, c.Channel.Txt, - c.Vlan.Txt, c.IP, c.Essid, c.Bssid, c.RadioDescription, - } - - return []*metricExports{ - {u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, labels}, - {u.Client.BytesR, prometheus.GaugeValue, c.BytesR, labels}, - {u.Client.CCQ, prometheus.GaugeValue, c.Ccq, labels}, - {u.Client.Noise, prometheus.GaugeValue, c.Noise, labels}, - {u.Client.RoamCount, prometheus.CounterValue, c.RoamCount, labels}, - {u.Client.RSSI, prometheus.GaugeValue, c.Rssi, 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.RxRate, prometheus.GaugeValue, c.RxRate, labels}, - {u.Client.Signal, prometheus.GaugeValue, c.Signal, 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.TxPower, prometheus.GaugeValue, c.TxPower, labels}, - {u.Client.TxRate, prometheus.GaugeValue, c.TxRate, labels}, - {u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labels}, - {u.Client.WifiTxAttempts, prometheus.CounterValue, c.WifiTxAttempts, labels}, - {u.Client.WiredRxBytes, prometheus.CounterValue, c.WiredRxBytes, labels}, - {u.Client.WiredRxBytesR, prometheus.GaugeValue, c.WiredRxBytesR, labels}, - {u.Client.WiredRxPackets, prometheus.CounterValue, c.WiredRxPackets, labels}, - {u.Client.WiredTxBytes, prometheus.CounterValue, c.WiredTxBytes, labels}, - {u.Client.WiredTxBytesR, prometheus.GaugeValue, c.WiredTxBytesR, labels}, - {u.Client.WiredTxPackets, prometheus.CounterValue, c.WiredTxPackets, labels}, - {u.Client.DpiStatsApp, prometheus.GaugeValue, c.DpiStats.App.Val, labels}, - {u.Client.DpiStatsCat, prometheus.GaugeValue, c.DpiStats.Cat.Val, labels}, - {u.Client.DpiStatsRxBytes, prometheus.CounterValue, c.DpiStats.RxBytes.Val, labels}, - {u.Client.DpiStatsRxPackets, prometheus.CounterValue, c.DpiStats.RxPackets.Val, labels}, - {u.Client.DpiStatsTxBytes, prometheus.CounterValue, c.DpiStats.TxBytes.Val, labels}, - {u.Client.DpiStatsTxPackets, prometheus.CounterValue, c.DpiStats.TxPackets.Val, labels}, + labels := []string{c.ID, c.Mac, c.UserID, c.SiteID, c.SiteName, + c.NetworkID, c.ApMac, c.GwMac, c.SwMac, c.ApName, c.GwName, + c.SwName, c.RadioName, c.Radio, c.RadioProto, c.Name, c.Channel.Txt, + c.Vlan.Txt, c.IP, c.Essid, c.Bssid, c.RadioDescription, + } + + r.ch <- []*metricExports{ + {u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, labels}, + {u.Client.BytesR, prometheus.GaugeValue, c.BytesR, labels}, + {u.Client.CCQ, prometheus.GaugeValue, c.Ccq, labels}, + {u.Client.Noise, prometheus.GaugeValue, c.Noise, labels}, + {u.Client.RoamCount, prometheus.CounterValue, c.RoamCount, labels}, + {u.Client.RSSI, prometheus.GaugeValue, c.Rssi, 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.RxRate, prometheus.GaugeValue, c.RxRate, labels}, + {u.Client.Signal, prometheus.GaugeValue, c.Signal, 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.TxPower, prometheus.GaugeValue, c.TxPower, labels}, + {u.Client.TxRate, prometheus.GaugeValue, c.TxRate, labels}, + {u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labels}, + {u.Client.WifiTxAttempts, prometheus.CounterValue, c.WifiTxAttempts, labels}, + {u.Client.WiredRxBytes, prometheus.CounterValue, c.WiredRxBytes, labels}, + {u.Client.WiredRxBytesR, prometheus.GaugeValue, c.WiredRxBytesR, labels}, + {u.Client.WiredRxPackets, prometheus.CounterValue, c.WiredRxPackets, labels}, + {u.Client.WiredTxBytes, prometheus.CounterValue, c.WiredTxBytes, labels}, + {u.Client.WiredTxBytesR, prometheus.GaugeValue, c.WiredTxBytesR, labels}, + {u.Client.WiredTxPackets, prometheus.CounterValue, c.WiredTxPackets, labels}, + {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}, + } } } diff --git a/promunifi/collector.go b/promunifi/collector.go index 8f9e0281..f5b00a9b 100644 --- a/promunifi/collector.go +++ b/promunifi/collector.go @@ -1,3 +1,4 @@ +// Package promunifi provides the bridge between unifi metrics and prometheus. package promunifi import ( @@ -117,18 +118,18 @@ func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { go u.exportMetrics(ch, r) r.wg.Add(len(r.Metrics.Clients) + len(r.Metrics.Sites)) - go u.exportClients(r.Metrics.Clients, r.ch) - go u.exportSites(r.Metrics.Sites, r.ch) + 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.Devices.UAPs) + len(r.Metrics.Devices.USGs) + len(r.Metrics.Devices.USWs) + len(r.Metrics.Devices.UDMs)) - go u.exportUAPs(r.Metrics.Devices.UAPs, r.ch) - go u.exportUSGs(r.Metrics.Devices.USGs, r.ch) - go u.exportUSWs(r.Metrics.Devices.USWs, r.ch) - go u.exportUDMs(r.Metrics.Devices.UDMs, r.ch) + 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) } // This is closely tied to the method above with a sync.WaitGroup. @@ -140,14 +141,14 @@ func (u *unifiCollector) exportMetrics(ch chan<- prometheus.Metric, r *Report) { r.Total++ descs[m.Desc] = true switch v := m.Value.(type) { + case unifi.FlexInt: + ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, v.Val, m.Labels...) case float64: ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, v, m.Labels...) case int64: ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, float64(v), m.Labels...) case int: ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, float64(v), m.Labels...) - case unifi.FlexInt: - ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, v.Val, m.Labels...) default: r.Errors++ diff --git a/promunifi/site.go b/promunifi/site.go index 2ce333c2..f525a819 100644 --- a/promunifi/site.go +++ b/promunifi/site.go @@ -32,7 +32,6 @@ type site struct { RemoteUserTxPackets *prometheus.Desc } -// XXX: The help values can be more verbose. func descSite(ns string) *site { if ns += "_site_"; ns == "_site_" { ns = "site_" @@ -67,53 +66,46 @@ func descSite(ns string) *site { } } -func (u *unifiCollector) exportSites(sites unifi.Sites, ch chan []*metricExports) { +func (u *unifiCollector) exportSites(sites unifi.Sites, r *Report) { for _, s := range sites { - ch <- u.exportSite(s) - } -} + metrics := []*metricExports{} + labels := []string{s.Name, s.Desc, s.SiteName} + for _, h := range s.Health { + l := append([]string{h.Subsystem, h.Status, h.GwVersion}, labels...) -// exportSite exports Network Site Data -func (u *unifiCollector) exportSite(s *unifi.Site) []*metricExports { - labels := []string{s.Name, s.Desc, s.SiteName} - metrics := []*metricExports{} - - for _, h := range s.Health { - l := append([]string{h.Subsystem, h.Status, h.GwVersion}, labels...) - - // XXX: More of these are subsystem specific (like the vpn/remote user stuff below) - 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}, - {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR.Val, l}, - {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR.Val, l}, - {u.Site.NumAp, prometheus.CounterValue, h.NumAp.Val, l}, - {u.Site.NumAdopted, prometheus.CounterValue, h.NumAdopted.Val, l}, - {u.Site.NumDisabled, prometheus.CounterValue, h.NumDisabled.Val, l}, - {u.Site.NumDisconnected, prometheus.CounterValue, h.NumDisconnected.Val, l}, - {u.Site.NumPending, prometheus.CounterValue, h.NumPending.Val, l}, - {u.Site.NumGw, prometheus.CounterValue, h.NumGw.Val, l}, - {u.Site.NumSw, prometheus.CounterValue, h.NumSw.Val, l}, - {u.Site.NumSta, prometheus.CounterValue, h.NumSta.Val, l}, - {u.Site.Latency, prometheus.GaugeValue, h.Latency.Val, l}, - {u.Site.Drops, prometheus.CounterValue, h.Drops.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}, - }...) - - if h.Subsystem == "vpn" { + // XXX: More of these are subsystem specific (like the vpn/remote user stuff below) 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}, + {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}, + {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR.Val, l}, + {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR.Val, l}, + {u.Site.NumAp, prometheus.CounterValue, h.NumAp.Val, l}, + {u.Site.NumAdopted, prometheus.CounterValue, h.NumAdopted.Val, l}, + {u.Site.NumDisabled, prometheus.CounterValue, h.NumDisabled.Val, l}, + {u.Site.NumDisconnected, prometheus.CounterValue, h.NumDisconnected.Val, l}, + {u.Site.NumPending, prometheus.CounterValue, h.NumPending.Val, l}, + {u.Site.NumGw, prometheus.CounterValue, h.NumGw.Val, l}, + {u.Site.NumSw, prometheus.CounterValue, h.NumSw.Val, l}, + {u.Site.NumSta, prometheus.CounterValue, h.NumSta.Val, l}, + {u.Site.Latency, prometheus.GaugeValue, h.Latency.Val, l}, + {u.Site.Drops, prometheus.CounterValue, h.Drops.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}, }...) - } - } - return metrics + if h.Subsystem == "vpn" { + 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}, + }...) + } + } + r.ch <- metrics + } } diff --git a/promunifi/uap.go b/promunifi/uap.go index 792905d2..2aac5810 100644 --- a/promunifi/uap.go +++ b/promunifi/uap.go @@ -212,45 +212,43 @@ func descUAP(ns string) *uap { } } -func (u *unifiCollector) exportUAPs(uaps []*unifi.UAP, ch chan []*metricExports) { +func (u *unifiCollector) exportUAPs(uaps []*unifi.UAP, r *Report) { for _, a := range uaps { - ch <- u.exportUAP(a) + 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)...) } } -// exportUAP exports Access Point Data -func (u *unifiCollector) exportUAP(a *unifi.UAP) []*metricExports { - labels := []string{a.IP, a.SiteName, a.Mac, a.Model, a.Name, a.Serial, a.SiteID, - a.Type, a.Version, a.DeviceID} - - // Switch data. - return 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) exportUAPstat(labels []string, a *unifi.Ap) []*metricExports { labelA := append([]string{"all"}, labels...) labelU := append([]string{"user"}, labels...) labelG := append([]string{"guest"}, labels...) + return []*metricExports{ // all {u.UAP.ApWifiTxDropped, prometheus.CounterValue, a.WifiTxDropped, labelA}, @@ -301,11 +299,12 @@ func (u *unifiCollector) exportUAPstat(labels []string, a *unifi.Ap) []*metricEx } func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats) []*metricExports { - m := []*metricExports{} + metrics := []*metricExports{} + // vap table stats for _, v := range vt { labelV := append([]string{v.Name, v.Bssid, v.RadioName, v.Essid}, labels...) - m = append(m, []*metricExports{ + metrics = append(metrics, []*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}, @@ -345,9 +344,10 @@ func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt u }...) } + // radio table for _, p := range rt { labelR := append([]string{p.Name, p.Radio, p.WlangroupID}, labels...) - m = append(m, []*metricExports{ + metrics = append(metrics, []*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}, @@ -361,7 +361,7 @@ func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt u if t.Name != p.Name { continue } - m = append(m, []*metricExports{ + metrics = append(metrics, []*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}, @@ -376,8 +376,7 @@ func (u *unifiCollector) exportVAPtable(labels []string, vt unifi.VapTable, rt u {u.UAP.RadioTxPackets, prometheus.CounterValue, t.TxPackets, labelR}, {u.UAP.RadioTxRetries, prometheus.CounterValue, t.TxRetries, labelR}, }...) - } } - return m + return metrics } diff --git a/promunifi/udm.go b/promunifi/udm.go index 081c25c9..17c3ea96 100644 --- a/promunifi/udm.go +++ b/promunifi/udm.go @@ -11,13 +11,6 @@ func descUDM(ns string) *udm { return &udm{} } -func (u *unifiCollector) exportUDMs(udms []*unifi.UDM, ch chan []*metricExports) { - for _, d := range udms { - ch <- u.exportUDM(d) - } -} - -// exportUDM exports UniFi Dream Machine (and Pro) Data -func (u *unifiCollector) exportUDM(d *unifi.UDM) []*metricExports { - return nil +func (u *unifiCollector) exportUDMs(udms []*unifi.UDM, r *Report) { + // for _, d := range udms { } diff --git a/promunifi/usg.go b/promunifi/usg.go index 1fafd54e..ffa6ad0e 100644 --- a/promunifi/usg.go +++ b/promunifi/usg.go @@ -109,60 +109,53 @@ func descUSG(ns string) *usg { } } -func (u *unifiCollector) exportUSGs(usgs []*unifi.USG, ch chan []*metricExports) { - for _, sg := range usgs { - ch <- u.exportUSG(sg) +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.DeviceID, 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)...) } } -// exportUSG Exports Security Gateway Data -// uplink and port tables structs are ignored. that data should be in other exported fields. -func (u *unifiCollector) exportUSG(s *unifi.USG) []*metricExports { - labels := []string{s.SiteName, s.Mac, s.Model, s.Name, s.Serial, s.SiteID, - s.Type, s.Version, s.DeviceID, s.IP} - labelWan := append([]string{"all"}, labels...) - // r.wait.Add(1) // closed by channel receiver. - - // Gateway System Data. - return 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) exportWANPorts(labels []string, wans ...unifi.Wan) []*metricExports { metrics := []*metricExports{} for _, wan := range wans { @@ -189,6 +182,5 @@ func (u *unifiCollector) exportWANPorts(labels []string, wans ...unifi.Wan) []*m {u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, l}, }...) } - return metrics } diff --git a/promunifi/usw.go b/promunifi/usw.go index 54b4bc53..adae94eb 100644 --- a/promunifi/usw.go +++ b/promunifi/usw.go @@ -136,63 +136,57 @@ func descUSW(ns string) *usw { } } -func (u *unifiCollector) exportUSWs(usws []*unifi.USW, ch chan []*metricExports) { - for _, sw := range usws { - ch <- u.exportUSW(sw) +func (u *unifiCollector) exportUSWs(usws []*unifi.USW, r *Report) { + for _, s := range usws { + labels := []string{s.Type, s.Version, s.DeviceID, s.IP, + s.SiteName, s.Mac, s.Model, s.Name, s.Serial, s.SiteID} + + // Switch data. + r.ch <- append([]*metricExports{ + {u.USW.Uptime, prometheus.GaugeValue, s.Uptime, labels}, + {u.USW.Temperature, prometheus.GaugeValue, s.GeneralTemperature, labels}, + {u.USW.TotalMaxPower, prometheus.GaugeValue, s.TotalMaxPower, labels}, + {u.USW.FanLevel, prometheus.GaugeValue, s.FanLevel, 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:])...) } } -// exportUSW exports Network Switch Data -func (u *unifiCollector) exportUSW(s *unifi.USW) []*metricExports { - labels := []string{s.Type, s.Version, s.DeviceID, s.IP, - s.SiteName, s.Mac, s.Model, s.Name, s.Serial, s.SiteID} - - // Switch data. - return append([]*metricExports{ - {u.USW.Uptime, prometheus.GaugeValue, s.Uptime, labels}, - {u.USW.Temperature, prometheus.GaugeValue, s.GeneralTemperature, labels}, - {u.USW.TotalMaxPower, prometheus.GaugeValue, s.TotalMaxPower, labels}, - {u.USW.FanLevel, prometheus.GaugeValue, s.FanLevel, 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) exportPortTable(pt []unifi.Port, labels []string) []*metricExports { metrics := []*metricExports{} // Per-port data on a switch for _, p := range pt { // Copy labels, and add four new ones. l := append([]string{p.PortIdx.Txt, p.Name, p.Mac, p.IP}, labels...) - metrics = append(metrics, []*metricExports{ {u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, l}, {u.USW.PoePower, prometheus.GaugeValue, p.PoePower, l}, @@ -214,6 +208,5 @@ func (u *unifiCollector) exportPortTable(pt []unifi.Port, labels []string) []*me {u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, l}, }...) } - return metrics }