less appendage

This commit is contained in:
davidnewhall2 2019-11-18 00:01:33 -08:00
parent 0b5872c62e
commit 573ce9bdee
3 changed files with 73 additions and 63 deletions

View File

@ -74,31 +74,35 @@ func (u *unifiCollector) exportSite(s *unifi.Site) []*metricExports {
var m []*metricExports var m []*metricExports
for _, h := range s.Health { for _, h := range s.Health {
l := append(labels, h.Subsystem, h.Status, h.GwVersion) 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{
m = append(m, &metricExports{u.Site.NumGuest, prometheus.CounterValue, h.NumGuest.Val, l}) {u.Site.NumUser, prometheus.CounterValue, h.NumUser.Val, l},
m = append(m, &metricExports{u.Site.NumIot, prometheus.CounterValue, h.NumIot.Val, l}) {u.Site.NumGuest, prometheus.CounterValue, h.NumGuest.Val, l},
m = append(m, &metricExports{u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR.Val, l}) {u.Site.NumIot, prometheus.CounterValue, h.NumIot.Val, l},
m = append(m, &metricExports{u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR.Val, l}) {u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR.Val, l},
m = append(m, &metricExports{u.Site.NumAp, prometheus.CounterValue, h.NumAp.Val, l}) {u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR.Val, l},
m = append(m, &metricExports{u.Site.NumAdopted, prometheus.CounterValue, h.NumAdopted.Val, l}) {u.Site.NumAp, prometheus.CounterValue, h.NumAp.Val, l},
m = append(m, &metricExports{u.Site.NumDisabled, prometheus.CounterValue, h.NumDisabled.Val, l}) {u.Site.NumAdopted, prometheus.CounterValue, h.NumAdopted.Val, l},
m = append(m, &metricExports{u.Site.NumDisconnected, prometheus.CounterValue, h.NumDisconnected.Val, l}) {u.Site.NumDisabled, prometheus.CounterValue, h.NumDisabled.Val, l},
m = append(m, &metricExports{u.Site.NumPending, prometheus.CounterValue, h.NumPending.Val, l}) {u.Site.NumDisconnected, prometheus.CounterValue, h.NumDisconnected.Val, l},
m = append(m, &metricExports{u.Site.NumGw, prometheus.CounterValue, h.NumGw.Val, l}) {u.Site.NumPending, prometheus.CounterValue, h.NumPending.Val, l},
m = append(m, &metricExports{u.Site.NumSw, prometheus.CounterValue, h.NumSw.Val, l}) {u.Site.NumGw, prometheus.CounterValue, h.NumGw.Val, l},
m = append(m, &metricExports{u.Site.NumSta, prometheus.CounterValue, h.NumSta.Val, l}) {u.Site.NumSw, prometheus.CounterValue, h.NumSw.Val, l},
m = append(m, &metricExports{u.Site.Latency, prometheus.GaugeValue, h.Latency.Val, l}) {u.Site.NumSta, prometheus.CounterValue, h.NumSta.Val, l},
m = append(m, &metricExports{u.Site.Drops, prometheus.CounterValue, h.Drops.Val, l}) {u.Site.Latency, prometheus.GaugeValue, h.Latency.Val, l},
m = append(m, &metricExports{u.Site.XputUp, prometheus.GaugeValue, h.XputUp.Val, l}) {u.Site.Drops, prometheus.CounterValue, h.Drops.Val, l},
m = append(m, &metricExports{u.Site.XputDown, prometheus.GaugeValue, h.XputDown.Val, l}) {u.Site.XputUp, prometheus.GaugeValue, h.XputUp.Val, l},
m = append(m, &metricExports{u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing.Val, l}) {u.Site.XputDown, prometheus.GaugeValue, h.XputDown.Val, l},
{u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing.Val, l},
}...)
if h.Subsystem == "vpn" { if h.Subsystem == "vpn" {
m = append(m, &metricExports{u.Site.RemoteUserNumActive, prometheus.CounterValue, h.RemoteUserNumActive.Val, l}) m = append(m, []*metricExports{
m = append(m, &metricExports{u.Site.RemoteUserNumInactive, prometheus.CounterValue, h.RemoteUserNumInactive.Val, l}) {u.Site.RemoteUserNumActive, prometheus.CounterValue, h.RemoteUserNumActive.Val, l},
m = append(m, &metricExports{u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes.Val, l}) {u.Site.RemoteUserNumInactive, prometheus.CounterValue, h.RemoteUserNumInactive.Val, l},
m = append(m, &metricExports{u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes.Val, l}) {u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes.Val, l},
m = append(m, &metricExports{u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets.Val, l}) {u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes.Val, l},
m = append(m, &metricExports{u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets.Val, l}) {u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets.Val, l},
{u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets.Val, l},
}...)
} }
} }
return m return m

View File

@ -47,6 +47,7 @@ type usg struct {
WanTxDropped *prometheus.Desc WanTxDropped *prometheus.Desc
WanTxErrors *prometheus.Desc WanTxErrors *prometheus.Desc
WanTxMulticast *prometheus.Desc WanTxMulticast *prometheus.Desc
WanBytesR *prometheus.Desc
} }
func descUSG(ns string) *usg { 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), MemTotal: prometheus.NewDesc(ns+"memory_installed", "System Installed Memory", labels, nil),
MemBuffer: prometheus.NewDesc(ns+"memory_buffer", "System Memory Buffer", labels, nil), MemBuffer: prometheus.NewDesc(ns+"memory_buffer", "System Memory Buffer", labels, nil),
CPU: prometheus.NewDesc(ns+"cpu_utilization", "System CPU % Utilized", 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), 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), 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), 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), 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), 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), 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), 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), 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), 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.LanTxPackets, prometheus.CounterValue, s.Stat.Gw.LanTxPackets, labels},
{u.USG.LanTxBytes, prometheus.CounterValue, s.Stat.Gw.LanTxBytes, labels}, {u.USG.LanTxBytes, prometheus.CounterValue, s.Stat.Gw.LanTxBytes, labels},
{u.USG.LanRxDropped, prometheus.CounterValue, s.Stat.Gw.LanRxDropped, 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} { for _, wan := range []unifi.Wan{s.Wan1, s.Wan2} {
if !j.Up.Val { if !wan.Up.Val {
continue // only record UP interfaces. continue // only record UP interfaces.
} }
labelWan := append([]string{j.Name}, labels...) labelWan := append([]string{wan.Name}, labels...)
m = append(m, []*metricExports{ m = append(m, []*metricExports{
{u.USG.WanRxPackets, prometheus.CounterValue, j.RxPackets, labelWan}, {u.USG.WanRxPackets, prometheus.CounterValue, wan.RxPackets, labelWan},
{u.USG.WanRxBytes, prometheus.CounterValue, j.RxBytes, labelWan}, {u.USG.WanRxBytes, prometheus.CounterValue, wan.RxBytes, labelWan},
{u.USG.WanRxDropped, prometheus.CounterValue, j.RxDropped, labelWan}, {u.USG.WanRxDropped, prometheus.CounterValue, wan.RxDropped, labelWan},
{u.USG.WanRxErrors, prometheus.CounterValue, j.RxErrors, labelWan}, {u.USG.WanRxErrors, prometheus.CounterValue, wan.RxErrors, labelWan},
{u.USG.WanTxPackets, prometheus.CounterValue, j.TxPackets, labelWan}, {u.USG.WanTxPackets, prometheus.CounterValue, wan.TxPackets, labelWan},
{u.USG.WanTxBytes, prometheus.CounterValue, j.TxBytes, labelWan}, {u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, labelWan},
{u.USG.WanRxBroadcast, prometheus.CounterValue, j.RxBroadcast, labelWan}, {u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, labelWan},
{u.USG.WanRxMulticast, prometheus.CounterValue, j.RxMulticast, labelWan}, {u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, labelWan},
{u.USG.WanSpeed, prometheus.CounterValue, j.Speed, labelWan}, {u.USG.WanSpeed, prometheus.CounterValue, wan.Speed, labelWan},
{u.USG.WanTxBroadcast, prometheus.CounterValue, j.TxBroadcast, labelWan}, {u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, labelWan},
{u.USG.WanTxBytesR, prometheus.CounterValue, j.TxBytesR, labelWan}, {u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, labelWan},
{u.USG.WanTxDropped, prometheus.CounterValue, j.TxDropped, labelWan}, {u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, labelWan},
{u.USG.WanTxErrors, prometheus.CounterValue, j.TxErrors, labelWan}, {u.USG.WanTxErrors, prometheus.CounterValue, wan.TxErrors, labelWan},
{u.USG.WanTxMulticast, prometheus.CounterValue, j.TxMulticast, labelWan}, {u.USG.WanTxMulticast, prometheus.CounterValue, wan.TxMulticast, labelWan},
{u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, labelWan},
}...) }...)
} }
return m return m
} }

View File

@ -74,7 +74,7 @@ func descUSW(ns string) *usw {
Loadavg1: prometheus.NewDesc(ns+"load_average_1", "System Load Average 1 Minute", 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), 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), 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), MemTotal: prometheus.NewDesc(ns+"memory_installed", "System Installed Memory", labels, nil),
MemBuffer: prometheus.NewDesc(ns+"memory_buffer", "System Memory Buffer", labels, nil), MemBuffer: prometheus.NewDesc(ns+"memory_buffer", "System Memory Buffer", labels, nil),
CPU: prometheus.NewDesc(ns+"cpu_utilization", "System CPU % Utilized", 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 { for _, p := range s.PortTable {
// Copy labels, and replace last four with different data. // Copy labels, and replace last four with different data.
l := append(append([]string{}, labels[:6]...), p.PortIdx.Txt, p.Name, p.Mac, p.IP) 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{
m = append(m, &metricExports{u.USW.PoePower, prometheus.GaugeValue, p.PoePower, l}) {u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, l},
m = append(m, &metricExports{u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, l}) {u.USW.PoePower, prometheus.GaugeValue, p.PoePower, l},
m = append(m, &metricExports{u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, l}) {u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, l},
m = append(m, &metricExports{u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, l}) {u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, l},
m = append(m, &metricExports{u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, l}) {u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, l},
m = append(m, &metricExports{u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, l}) {u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, l},
m = append(m, &metricExports{u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, l}) {u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, l},
m = append(m, &metricExports{u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, l}) {u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, l},
m = append(m, &metricExports{u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, l}) {u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, l},
m = append(m, &metricExports{u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction, l}) {u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, l},
m = append(m, &metricExports{u.USW.Speed, prometheus.GaugeValue, p.Speed, l}) {u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction, l},
m = append(m, &metricExports{u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, l}) {u.USW.Speed, prometheus.GaugeValue, p.Speed, l},
m = append(m, &metricExports{u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, l}) {u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, l},
m = append(m, &metricExports{u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, l}) {u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, l},
m = append(m, &metricExports{u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, l}) {u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, l},
m = append(m, &metricExports{u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, l}) {u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, l},
m = append(m, &metricExports{u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, l}) {u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, l},
{u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, l},
}...)
} }
return m return m
} }