This commit is contained in:
davidnewhall2 2019-11-28 02:45:59 -08:00
parent b99253d092
commit 63bf858dea
7 changed files with 16 additions and 11 deletions

View File

@ -91,7 +91,7 @@ func (u *unifiCollector) exportClients(r *Report) {
if r.Metrics == nil || len(r.Metrics.Clients) < 1 {
return
}
r.wg.Add(1)
r.wg.Add(one)
go func() {
defer r.wg.Done()
for _, c := range r.Metrics.Clients {

View File

@ -12,6 +12,12 @@ import (
"golift.io/unifi"
)
// satisfy gomnd
const one = 1
// channel buffer, fits at least one batch.
const buffer = 50
// UnifiCollectorCnfg defines the data needed to collect and report UniFi Metrics.
type UnifiCollectorCnfg struct {
// If non-empty, each of the collected metrics is prefixed by the
@ -104,7 +110,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, 50)}
r := &Report{Start: time.Now(), ch: make(chan []*metricExports, buffer)}
defer func() {
r.wg.Wait()
close(r.ch)
@ -168,6 +174,6 @@ func (u *unifiCollector) exportMetrics(r *Report, ch chan<- prometheus.Metric) {
}
func (r *Report) send(m []*metricExports) {
r.wg.Add(1)
r.wg.Add(one)
r.ch <- m
}

View File

@ -82,7 +82,7 @@ func (u *unifiCollector) exportSites(r *Report) {
if r.Metrics == nil || len(r.Metrics.Sites) < 1 {
return
}
r.wg.Add(1)
r.wg.Add(one)
go func() {
defer r.wg.Done()
for _, s := range r.Metrics.Sites {

View File

@ -217,7 +217,7 @@ 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)
r.wg.Add(one)
go func() {
defer r.wg.Done()
for _, a := range r.Metrics.Devices.UAPs {
@ -310,7 +310,6 @@ func (u *unifiCollector) exportUAPstat(r *Report, labels []string, a *unifi.Ap)
}
func (u *unifiCollector) exportVAPtable(r *Report, labels []string, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats) {
// vap table stats
for _, v := range vt {
if !v.Up.Val {

View File

@ -13,7 +13,7 @@ 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)
r.wg.Add(one)
go func() {
defer r.wg.Done()
for _, d := range r.Metrics.Devices.UDMs {

View File

@ -111,7 +111,7 @@ 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)
r.wg.Add(one)
go func() {
defer r.wg.Done()
for _, s := range r.Metrics.Devices.USGs {
@ -179,7 +179,7 @@ func (u *unifiCollector) exportWANPorts(r *Report, labels []string, wans ...unif
{u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, l},
{u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, l},
{u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, l},
{u.USG.WanSpeed, prometheus.CounterValue, wan.Speed * 1000000, l},
{u.USG.WanSpeed, prometheus.CounterValue, wan.Speed.Val * 1000000, l},
{u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, l},
{u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, l},
{u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, l},

View File

@ -139,7 +139,7 @@ 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)
r.wg.Add(one)
go func() {
defer r.wg.Done()
for _, s := range r.Metrics.Devices.USWs {
@ -220,7 +220,7 @@ func (u *unifiCollector) exportPortTable(r *Report, pt []unifi.Port, labels []st
{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 * 1000000, l},
{u.USW.Speed, prometheus.GaugeValue, p.Speed.Val * 1000000, 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},