comments
This commit is contained in:
parent
4d485769d6
commit
dbe0a6bc94
|
|
@ -121,16 +121,17 @@ func (u *promUnifi) Collect(ch chan<- prometheus.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass Report interface into our collecting and reporting methods.
|
// Pass Report interface into our collecting and reporting methods.
|
||||||
go u.exportMetrics(r, ch)
|
go u.exportMetrics(r, ch, r.ch)
|
||||||
u.loopExports(r)
|
u.loopExports(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is closely tied to the method above with a sync.WaitGroup.
|
// 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.
|
// 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
|
descs := make(map[*prometheus.Desc]bool) // used as a counter
|
||||||
defer r.report(descs)
|
defer r.report(descs)
|
||||||
for newMetrics := range r.channel() {
|
for newMetrics := range ourChan {
|
||||||
for _, m := range newMetrics {
|
for _, m := range newMetrics {
|
||||||
descs[m.Desc] = true
|
descs[m.Desc] = true
|
||||||
switch v := m.Value.(type) {
|
switch v := m.Value.(type) {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ type report interface {
|
||||||
send([]*metric)
|
send([]*metric)
|
||||||
sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string)
|
sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string)
|
||||||
metrics() *metrics.Metrics
|
metrics() *metrics.Metrics
|
||||||
channel() chan []*metric
|
|
||||||
report(descs map[*prometheus.Desc]bool)
|
report(descs map[*prometheus.Desc]bool)
|
||||||
export(m *metric, v float64) prometheus.Metric
|
export(m *metric, v float64) prometheus.Metric
|
||||||
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
|
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
|
||||||
|
|
@ -35,9 +34,9 @@ func (r *Report) done() {
|
||||||
r.wg.Add(-one)
|
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.wg.Add(one)
|
||||||
r.ch <- []*metric{{d, tv, i, s}}
|
r.ch <- []*metric{{desc, valType, val, labels}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Report) send(m []*metric) {
|
func (r *Report) send(m []*metric) {
|
||||||
|
|
@ -49,10 +48,6 @@ func (r *Report) metrics() *metrics.Metrics {
|
||||||
return r.Metrics
|
return r.Metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Report) channel() chan []*metric {
|
|
||||||
return r.ch
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Report) report(descs map[*prometheus.Desc]bool) {
|
func (r *Report) report(descs map[*prometheus.Desc]bool) {
|
||||||
if r.cf.LoggingFn == nil {
|
if r.cf.LoggingFn == nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ func (u *promUnifi) exportUAP(r report, d *unifi.UAP) {
|
||||||
r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...))
|
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) {
|
func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap, bytes ...unifi.FlexInt) {
|
||||||
labelU := []string{"user", labels[1], labels[2]}
|
labelU := []string{"user", labels[1], labels[2]}
|
||||||
labelG := []string{"guest", labels[1], labels[2]}
|
labelG := []string{"guest", labels[1], labels[2]}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func (u *promUnifi) exportSTAcount(r report, labels []string, stas ...unifi.FlexInt) {
|
||||||
r.send([]*metric{
|
r.send([]*metric{
|
||||||
{u.Device.Counter, gauge, stas[0], append(labels, "user")},
|
{u.Device.Counter, gauge, stas[0], append(labels, "user")},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue