This commit is contained in:
davidnewhall2 2019-12-03 00:24:16 -08:00
parent 4d485769d6
commit dbe0a6bc94
4 changed files with 8 additions and 11 deletions

View File

@ -121,16 +121,17 @@ func (u *promUnifi) Collect(ch chan<- prometheus.Metric) {
}
// Pass Report interface into our collecting and reporting methods.
go u.exportMetrics(r, ch)
go u.exportMetrics(r, ch, r.ch)
u.loopExports(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 *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) {
// This is where our channels connects to the prometheus channel.
func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric, ourChan chan []*metric) {
descs := make(map[*prometheus.Desc]bool) // used as a counter
defer r.report(descs)
for newMetrics := range r.channel() {
for newMetrics := range ourChan {
for _, m := range newMetrics {
descs[m.Desc] = true
switch v := m.Value.(type) {

View File

@ -18,7 +18,6 @@ type report interface {
send([]*metric)
sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string)
metrics() *metrics.Metrics
channel() chan []*metric
report(descs map[*prometheus.Desc]bool)
export(m *metric, v float64) prometheus.Metric
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
@ -35,9 +34,9 @@ func (r *Report) done() {
r.wg.Add(-one)
}
func (r *Report) sendone(d *prometheus.Desc, tv prometheus.ValueType, i interface{}, s []string) {
func (r *Report) sendone(desc *prometheus.Desc, valType prometheus.ValueType, val interface{}, labels []string) {
r.wg.Add(one)
r.ch <- []*metric{{d, tv, i, s}}
r.ch <- []*metric{{desc, valType, val, labels}}
}
func (r *Report) send(m []*metric) {
@ -49,10 +48,6 @@ func (r *Report) metrics() *metrics.Metrics {
return r.Metrics
}
func (r *Report) channel() chan []*metric {
return r.ch
}
func (r *Report) report(descs map[*prometheus.Desc]bool) {
if r.cf.LoggingFn == nil {
return

View File

@ -170,6 +170,7 @@ func (u *promUnifi) exportUAP(r report, d *unifi.UAP) {
r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...))
}
// udm doesn't have these stats exposed yet, so pass 2 or 6 metrics.
func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap, bytes ...unifi.FlexInt) {
labelU := []string{"user", labels[1], labels[2]}
labelG := []string{"guest", labels[1], labels[2]}

View File

@ -90,7 +90,7 @@ func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexI
})
}
// shared by all
// shared by all, pass 2 or 5 stats.
func (u *promUnifi) exportSTAcount(r report, labels []string, stas ...unifi.FlexInt) {
r.send([]*metric{
{u.Device.Counter, gauge, stas[0], append(labels, "user")},