From 6016c74a993d33bf801461b7b4c502d40064a2c7 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Mon, 18 Nov 2019 00:01:33 -0800 Subject: [PATCH] less appendage --- promunifi/site.go | 52 +++++++++++++++++++++++++---------------------- promunifi/usg.go | 43 ++++++++++++++++++++++----------------- promunifi/usw.go | 41 +++++++++++++++++++------------------ 3 files changed, 73 insertions(+), 63 deletions(-) diff --git a/promunifi/site.go b/promunifi/site.go index 5186cf91..f3364616 100644 --- a/promunifi/site.go +++ b/promunifi/site.go @@ -74,31 +74,35 @@ func (u *unifiCollector) exportSite(s *unifi.Site) []*metricExports { var m []*metricExports for _, h := range s.Health { l := append(labels, h.Subsystem, h.Status, h.GwVersion) - m = append(m, &metricExports{u.Site.NumUser, prometheus.CounterValue, h.NumUser.Val, l}) - m = append(m, &metricExports{u.Site.NumGuest, prometheus.CounterValue, h.NumGuest.Val, l}) - m = append(m, &metricExports{u.Site.NumIot, prometheus.CounterValue, h.NumIot.Val, l}) - m = append(m, &metricExports{u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR.Val, l}) - m = append(m, &metricExports{u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR.Val, l}) - m = append(m, &metricExports{u.Site.NumAp, prometheus.CounterValue, h.NumAp.Val, l}) - m = append(m, &metricExports{u.Site.NumAdopted, prometheus.CounterValue, h.NumAdopted.Val, l}) - m = append(m, &metricExports{u.Site.NumDisabled, prometheus.CounterValue, h.NumDisabled.Val, l}) - m = append(m, &metricExports{u.Site.NumDisconnected, prometheus.CounterValue, h.NumDisconnected.Val, l}) - m = append(m, &metricExports{u.Site.NumPending, prometheus.CounterValue, h.NumPending.Val, l}) - m = append(m, &metricExports{u.Site.NumGw, prometheus.CounterValue, h.NumGw.Val, l}) - m = append(m, &metricExports{u.Site.NumSw, prometheus.CounterValue, h.NumSw.Val, l}) - m = append(m, &metricExports{u.Site.NumSta, prometheus.CounterValue, h.NumSta.Val, l}) - m = append(m, &metricExports{u.Site.Latency, prometheus.GaugeValue, h.Latency.Val, l}) - m = append(m, &metricExports{u.Site.Drops, prometheus.CounterValue, h.Drops.Val, l}) - m = append(m, &metricExports{u.Site.XputUp, prometheus.GaugeValue, h.XputUp.Val, l}) - m = append(m, &metricExports{u.Site.XputDown, prometheus.GaugeValue, h.XputDown.Val, l}) - m = append(m, &metricExports{u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing.Val, l}) + m = append(m, []*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" { - m = append(m, &metricExports{u.Site.RemoteUserNumActive, prometheus.CounterValue, h.RemoteUserNumActive.Val, l}) - m = append(m, &metricExports{u.Site.RemoteUserNumInactive, prometheus.CounterValue, h.RemoteUserNumInactive.Val, l}) - m = append(m, &metricExports{u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes.Val, l}) - m = append(m, &metricExports{u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes.Val, l}) - m = append(m, &metricExports{u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets.Val, l}) - m = append(m, &metricExports{u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets.Val, l}) + m = append(m, []*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}, + }...) } } return m diff --git a/promunifi/usg.go b/promunifi/usg.go index e756281d..6e87ff0e 100644 --- a/promunifi/usg.go +++ b/promunifi/usg.go @@ -47,6 +47,7 @@ type usg struct { WanTxDropped *prometheus.Desc WanTxErrors *prometheus.Desc WanTxMulticast *prometheus.Desc + WanBytesR *prometheus.Desc } func descUSG(ns string) *usg { @@ -75,7 +76,7 @@ func descUSG(ns string) *usg { MemTotal: prometheus.NewDesc(ns+"memory_installed", "System Installed Memory", labels, nil), MemBuffer: prometheus.NewDesc(ns+"memory_buffer", "System Memory Buffer", labels, nil), CPU: prometheus.NewDesc(ns+"cpu_utilization", "System CPU % Utilized", labels, nil), - Mem: prometheus.NewDesc(ns+"memory", "System Memory % Utilized", labels, nil), // this may not be %. + Mem: prometheus.NewDesc(ns+"memory_utilization", "System Memory % Utilized", labels, nil), // this may not be %. WanRxPackets: prometheus.NewDesc(ns+"wan_rx_packets_total", "WAN Receive Packets Total", labelWan, nil), WanRxBytes: prometheus.NewDesc(ns+"wan_rx_bytes_total", "WAN Receive Bytes Total", labelWan, nil), WanRxDropped: prometheus.NewDesc(ns+"wan_rx_dropped_total", "WAN Receive Dropped Total", labelWan, nil), @@ -91,6 +92,7 @@ func descUSG(ns string) *usg { WanTxDropped: prometheus.NewDesc(ns+"wan_tx_dropped_total", "WAN Transmit Dropped Total", labelWan, nil), WanTxErrors: prometheus.NewDesc(ns+"wan_tx_errors_total", "WAN Transmit Errors Total", labelWan, nil), WanTxMulticast: prometheus.NewDesc(ns+"wan_tx_multicast_total", "WAN Transmit Multicast Total", labelWan, nil), + WanBytesR: prometheus.NewDesc(ns+"wan_bytes_rate", "WAN Transfer Rate", labelWan, nil), LanRxPackets: prometheus.NewDesc(ns+"lan_rx_packets_total", "LAN Receive Packets Total", labels, nil), LanRxBytes: prometheus.NewDesc(ns+"lan_rx_bytes_total", "LAN Receive Bytes Total", labels, nil), LanRxDropped: prometheus.NewDesc(ns+"lan_rx_dropped_total", "LAN Receive Dropped Total", labels, nil), @@ -137,30 +139,33 @@ func (u *unifiCollector) exportUSG(s *unifi.USG) []*metricExports { {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 status in a struct too, get that. + // speed test status in a struct too, get that? } - for _, j := range []unifi.Wan{s.Wan1, s.Wan2} { - if !j.Up.Val { + for _, wan := range []unifi.Wan{s.Wan1, s.Wan2} { + if !wan.Up.Val { continue // only record UP interfaces. } - labelWan := append([]string{j.Name}, labels...) + labelWan := append([]string{wan.Name}, labels...) + m = append(m, []*metricExports{ - {u.USG.WanRxPackets, prometheus.CounterValue, j.RxPackets, labelWan}, - {u.USG.WanRxBytes, prometheus.CounterValue, j.RxBytes, labelWan}, - {u.USG.WanRxDropped, prometheus.CounterValue, j.RxDropped, labelWan}, - {u.USG.WanRxErrors, prometheus.CounterValue, j.RxErrors, labelWan}, - {u.USG.WanTxPackets, prometheus.CounterValue, j.TxPackets, labelWan}, - {u.USG.WanTxBytes, prometheus.CounterValue, j.TxBytes, labelWan}, - {u.USG.WanRxBroadcast, prometheus.CounterValue, j.RxBroadcast, labelWan}, - {u.USG.WanRxMulticast, prometheus.CounterValue, j.RxMulticast, labelWan}, - {u.USG.WanSpeed, prometheus.CounterValue, j.Speed, labelWan}, - {u.USG.WanTxBroadcast, prometheus.CounterValue, j.TxBroadcast, labelWan}, - {u.USG.WanTxBytesR, prometheus.CounterValue, j.TxBytesR, labelWan}, - {u.USG.WanTxDropped, prometheus.CounterValue, j.TxDropped, labelWan}, - {u.USG.WanTxErrors, prometheus.CounterValue, j.TxErrors, labelWan}, - {u.USG.WanTxMulticast, prometheus.CounterValue, j.TxMulticast, labelWan}, + {u.USG.WanRxPackets, prometheus.CounterValue, wan.RxPackets, labelWan}, + {u.USG.WanRxBytes, prometheus.CounterValue, wan.RxBytes, labelWan}, + {u.USG.WanRxDropped, prometheus.CounterValue, wan.RxDropped, labelWan}, + {u.USG.WanRxErrors, prometheus.CounterValue, wan.RxErrors, labelWan}, + {u.USG.WanTxPackets, prometheus.CounterValue, wan.TxPackets, labelWan}, + {u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, labelWan}, + {u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, labelWan}, + {u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, labelWan}, + {u.USG.WanSpeed, prometheus.CounterValue, wan.Speed, labelWan}, + {u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, labelWan}, + {u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, labelWan}, + {u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, labelWan}, + {u.USG.WanTxErrors, prometheus.CounterValue, wan.TxErrors, labelWan}, + {u.USG.WanTxMulticast, prometheus.CounterValue, wan.TxMulticast, labelWan}, + {u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, labelWan}, }...) } + return m } diff --git a/promunifi/usw.go b/promunifi/usw.go index 892cfba0..7f6613a7 100644 --- a/promunifi/usw.go +++ b/promunifi/usw.go @@ -74,7 +74,7 @@ func descUSW(ns string) *usw { 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), - MemUsed: prometheus.NewDesc(ns+"memory_used", "System Memory Used", labels, nil), + MemUsed: prometheus.NewDesc(ns+"memory_utilization", "System Memory Used", labels, nil), MemTotal: prometheus.NewDesc(ns+"memory_installed", "System Installed Memory", labels, nil), MemBuffer: prometheus.NewDesc(ns+"memory_buffer", "System Memory Buffer", labels, nil), CPU: prometheus.NewDesc(ns+"cpu_utilization", "System CPU % Utilized", labels, nil), @@ -133,25 +133,26 @@ func (u *unifiCollector) exportUSW(s *unifi.USW) []*metricExports { for _, p := range s.PortTable { // Copy labels, and replace last four with different data. l := append(append([]string{}, labels[:6]...), p.PortIdx.Txt, p.Name, p.Mac, p.IP) - m = append(m, &metricExports{u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, l}) - m = append(m, &metricExports{u.USW.PoePower, prometheus.GaugeValue, p.PoePower, l}) - m = append(m, &metricExports{u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, l}) - m = append(m, &metricExports{u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, l}) - m = append(m, &metricExports{u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, l}) - m = append(m, &metricExports{u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, l}) - m = append(m, &metricExports{u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, l}) - m = append(m, &metricExports{u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, l}) - m = append(m, &metricExports{u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, l}) - m = append(m, &metricExports{u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, l}) - m = append(m, &metricExports{u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction, l}) - m = append(m, &metricExports{u.USW.Speed, prometheus.GaugeValue, p.Speed, l}) - m = append(m, &metricExports{u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, l}) - m = append(m, &metricExports{u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, l}) - m = append(m, &metricExports{u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, l}) - m = append(m, &metricExports{u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, l}) - m = append(m, &metricExports{u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, l}) - m = append(m, &metricExports{u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, l}) + m = append(m, []*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}, + {u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, l}, + {u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, l}, + {u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, l}, + {u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, l}, + {u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, l}, + {u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, l}, + {u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, l}, + {u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction, l}, + {u.USW.Speed, prometheus.GaugeValue, p.Speed, l}, + {u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, l}, + {u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, l}, + {u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, l}, + {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 m }