satisfy new interface
This commit is contained in:
		
							parent
							
								
									d80398b7a5
								
							
						
					
					
						commit
						979a625e6e
					
				| 
						 | 
					@ -72,7 +72,13 @@ func descClient(ns string) *uclient {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (u *promUnifi) exportClientDPI(r report, s *unifi.DPITable, appTotal, catTotal totalsDPImap) {
 | 
					func (u *promUnifi) exportClientDPI(r report, v interface{}, appTotal, catTotal totalsDPImap) {
 | 
				
			||||||
 | 
						s, ok := v.(*unifi.DPITable)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							u.Collector.LogErrorf("invalid type given to ClientsDPI: %T", v)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, dpi := range s.ByApp {
 | 
						for _, dpi := range s.ByApp {
 | 
				
			||||||
		labelDPI := []string{s.Name, s.MAC, s.SiteName, s.SourceName,
 | 
							labelDPI := []string{s.Name, s.MAC, s.SiteName, s.SourceName,
 | 
				
			||||||
			unifi.DPICats.Get(dpi.Cat), unifi.DPIApps.GetApp(dpi.Cat, dpi.App)}
 | 
								unifi.DPICats.Get(dpi.Cat), unifi.DPIApps.GetApp(dpi.Cat, dpi.App)}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,6 +72,10 @@ type Report struct {
 | 
				
			||||||
	Total   int             // Total count of metrics recorded.
 | 
						Total   int             // Total count of metrics recorded.
 | 
				
			||||||
	Errors  int             // Total count of errors recording metrics.
 | 
						Errors  int             // Total count of errors recording metrics.
 | 
				
			||||||
	Zeros   int             // Total count of metrics equal to zero.
 | 
						Zeros   int             // Total count of metrics equal to zero.
 | 
				
			||||||
 | 
						USG     int             // Total count of USG devices.
 | 
				
			||||||
 | 
						USW     int             // Total count of USW devices.
 | 
				
			||||||
 | 
						UAP     int             // Total count of UAP devices.
 | 
				
			||||||
 | 
						UDM     int             // Total count of UDM devices.
 | 
				
			||||||
	Metrics *poller.Metrics // Metrics collected and recorded.
 | 
						Metrics *poller.Metrics // Metrics collected and recorded.
 | 
				
			||||||
	Elapsed time.Duration   // Duration elapsed collecting and exporting.
 | 
						Elapsed time.Duration   // Duration elapsed collecting and exporting.
 | 
				
			||||||
	Fetch   time.Duration   // Duration elapsed making controller requests.
 | 
						Fetch   time.Duration   // Duration elapsed making controller requests.
 | 
				
			||||||
| 
						 | 
					@ -240,10 +244,6 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if r.Metrics.Devices == nil {
 | 
					 | 
				
			||||||
		r.Metrics.Devices = &unifi.Devices{}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Pass Report interface into our collecting and reporting methods.
 | 
						// Pass Report interface into our collecting and reporting methods.
 | 
				
			||||||
	go u.exportMetrics(r, ch, r.ch)
 | 
						go u.exportMetrics(r, ch, r.ch)
 | 
				
			||||||
	u.loopExports(r)
 | 
						u.loopExports(r)
 | 
				
			||||||
| 
						 | 
					@ -282,7 +282,7 @@ func (u *promUnifi) loopExports(r report) {
 | 
				
			||||||
	m := r.metrics()
 | 
						m := r.metrics()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, s := range m.Sites {
 | 
						for _, s := range m.Sites {
 | 
				
			||||||
		u.exportSite(r, s)
 | 
							u.switchExport(r, s)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, s := range m.SitesDPI {
 | 
						for _, s := range m.SitesDPI {
 | 
				
			||||||
| 
						 | 
					@ -290,7 +290,11 @@ func (u *promUnifi) loopExports(r report) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, c := range m.Clients {
 | 
						for _, c := range m.Clients {
 | 
				
			||||||
		u.exportClient(r, c)
 | 
							u.switchExport(r, c)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, d := range m.Devices {
 | 
				
			||||||
 | 
							u.switchExport(r, d)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	appTotal := make(totalsDPImap)
 | 
						appTotal := make(totalsDPImap)
 | 
				
			||||||
| 
						 | 
					@ -301,20 +305,27 @@ func (u *promUnifi) loopExports(r report) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u.exportClientDPItotals(r, appTotal, catTotal)
 | 
						u.exportClientDPItotals(r, appTotal, catTotal)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, d := range m.UAPs {
 | 
					func (u *promUnifi) switchExport(r report, v interface{}) {
 | 
				
			||||||
		u.exportUAP(r, d)
 | 
						switch v := v.(type) {
 | 
				
			||||||
	}
 | 
						case *unifi.UAP:
 | 
				
			||||||
 | 
							r.addUAP()
 | 
				
			||||||
	for _, d := range m.UDMs {
 | 
							u.exportUAP(r, v)
 | 
				
			||||||
		u.exportUDM(r, d)
 | 
						case *unifi.USW:
 | 
				
			||||||
	}
 | 
							r.addUSW()
 | 
				
			||||||
 | 
							u.exportUSW(r, v)
 | 
				
			||||||
	for _, d := range m.USGs {
 | 
						case *unifi.USG:
 | 
				
			||||||
		u.exportUSG(r, d)
 | 
							r.addUSG()
 | 
				
			||||||
	}
 | 
							u.exportUSG(r, v)
 | 
				
			||||||
 | 
						case *unifi.UDM:
 | 
				
			||||||
	for _, d := range m.USWs {
 | 
							r.addUDM()
 | 
				
			||||||
		u.exportUSW(r, d)
 | 
							u.exportUDM(r, v)
 | 
				
			||||||
 | 
						case *unifi.Site:
 | 
				
			||||||
 | 
							u.exportSite(r, v)
 | 
				
			||||||
 | 
						case *unifi.Client:
 | 
				
			||||||
 | 
							u.exportClient(r, v)
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							u.Collector.LogErrorf("invalid type: %T", v)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,6 @@ require (
 | 
				
			||||||
	github.com/prometheus/client_golang v1.6.0
 | 
						github.com/prometheus/client_golang v1.6.0
 | 
				
			||||||
	github.com/prometheus/common v0.10.0
 | 
						github.com/prometheus/common v0.10.0
 | 
				
			||||||
	github.com/prometheus/procfs v0.1.2 // indirect
 | 
						github.com/prometheus/procfs v0.1.2 // indirect
 | 
				
			||||||
	github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10
 | 
						github.com/unifi-poller/poller v0.0.8-0.20200621214016-5d1ed3324a46
 | 
				
			||||||
	github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd
 | 
						github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,6 +97,8 @@ github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece h1:EsyR6cKuw
 | 
				
			||||||
github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4=
 | 
					github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4=
 | 
				
			||||||
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10 h1:1rGP4ISFpBj9xjJDXNak7EdaQtyoy3MwMZzo2+W1PLo=
 | 
					github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10 h1:1rGP4ISFpBj9xjJDXNak7EdaQtyoy3MwMZzo2+W1PLo=
 | 
				
			||||||
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4=
 | 
					github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4=
 | 
				
			||||||
 | 
					github.com/unifi-poller/poller v0.0.8-0.20200621214016-5d1ed3324a46 h1:OhbVj3VVgbpUMQFSwD0NszDsbEL7DdbTcJuU+p9DwIM=
 | 
				
			||||||
 | 
					github.com/unifi-poller/poller v0.0.8-0.20200621214016-5d1ed3324a46/go.mod h1:pJ/MeYaakLOOpbyc7s4zeZ92UzNK/rir5jkA7t5jIjo=
 | 
				
			||||||
github.com/unifi-poller/unifi v0.0.4/go.mod h1:bTUtctrf56aapjKH+L+98eThBaVFbQXw5iNGZI0g/+E=
 | 
					github.com/unifi-poller/unifi v0.0.4/go.mod h1:bTUtctrf56aapjKH+L+98eThBaVFbQXw5iNGZI0g/+E=
 | 
				
			||||||
github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8=
 | 
					github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8=
 | 
				
			||||||
github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd h1:jrwuiY1AdoPi+b+R8zjt/e8h8ZqULNB9izcyQnf3pSw=
 | 
					github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd h1:jrwuiY1AdoPi+b+R8zjt/e8h8ZqULNB9izcyQnf3pSw=
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,6 +19,10 @@ type report interface {
 | 
				
			||||||
	report(c poller.Collect, descs map[*prometheus.Desc]bool)
 | 
						report(c poller.Collect, 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{})
 | 
				
			||||||
 | 
						addUDM()
 | 
				
			||||||
 | 
						addUSG()
 | 
				
			||||||
 | 
						addUAP()
 | 
				
			||||||
 | 
						addUSW()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Satisfy gomnd.
 | 
					// Satisfy gomnd.
 | 
				
			||||||
| 
						 | 
					@ -43,7 +47,7 @@ func (r *Report) report(c poller.Collect, descs map[*prometheus.Desc]bool) {
 | 
				
			||||||
	c.Logf("UniFi Measurements Exported. Site: %d, Client: %d, "+
 | 
						c.Logf("UniFi Measurements Exported. Site: %d, Client: %d, "+
 | 
				
			||||||
		"UAP: %d, USG/UDM: %d, USW: %d, Descs: %d, "+
 | 
							"UAP: %d, USG/UDM: %d, USW: %d, Descs: %d, "+
 | 
				
			||||||
		"Metrics: %d, Errs: %d, 0s: %d, Reqs/Total: %v / %v",
 | 
							"Metrics: %d, Errs: %d, 0s: %d, Reqs/Total: %v / %v",
 | 
				
			||||||
		len(m.Sites), len(m.Clients), len(m.UAPs), len(m.UDMs)+len(m.USGs), len(m.USWs),
 | 
							len(m.Sites), len(m.Clients), r.UAP, r.UDM+r.USG, r.USW,
 | 
				
			||||||
		len(descs), r.Total, r.Errors, r.Zeros,
 | 
							len(descs), r.Total, r.Errors, r.Zeros,
 | 
				
			||||||
		r.Fetch.Round(time.Millisecond/oneDecimalPoint),
 | 
							r.Fetch.Round(time.Millisecond/oneDecimalPoint),
 | 
				
			||||||
		r.Elapsed.Round(time.Millisecond/oneDecimalPoint))
 | 
							r.Elapsed.Round(time.Millisecond/oneDecimalPoint))
 | 
				
			||||||
| 
						 | 
					@ -67,6 +71,22 @@ func (r *Report) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interf
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r *Report) addUSW() {
 | 
				
			||||||
 | 
						r.USW++
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r *Report) addUAP() {
 | 
				
			||||||
 | 
						r.UAP++
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r *Report) addUSG() {
 | 
				
			||||||
 | 
						r.USG++
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r *Report) addUDM() {
 | 
				
			||||||
 | 
						r.UDM++
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// close is not part of the interface.
 | 
					// close is not part of the interface.
 | 
				
			||||||
func (r *Report) close() {
 | 
					func (r *Report) close() {
 | 
				
			||||||
	r.wg.Wait()
 | 
						r.wg.Wait()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,7 +75,13 @@ func descSite(ns string) *site {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (u *promUnifi) exportSiteDPI(r report, s *unifi.DPITable) {
 | 
					func (u *promUnifi) exportSiteDPI(r report, v interface{}) {
 | 
				
			||||||
 | 
						s, ok := v.(*unifi.DPITable)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							u.Collector.LogErrorf("invalid type given to SiteDPI: %T", v)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, dpi := range s.ByApp {
 | 
						for _, dpi := range s.ByApp {
 | 
				
			||||||
		labelDPI := []string{unifi.DPICats.Get(dpi.Cat), unifi.DPIApps.GetApp(dpi.Cat, dpi.App), s.SiteName, s.SourceName}
 | 
							labelDPI := []string{unifi.DPICats.Get(dpi.Cat), unifi.DPIApps.GetApp(dpi.Cat, dpi.App), s.SiteName, s.SourceName}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue