still cleaning
This commit is contained in:
		
							parent
							
								
									29c59e71b9
								
							
						
					
					
						commit
						883a5a7beb
					
				|  | @ -71,7 +71,7 @@ func descClient(ns string) *uclient { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportClient(r report, c *unifi.Client) { | ||||
| func (u *promUnifi) exportClient(r report, c *unifi.Client) { | ||||
| 	labels := []string{c.Name, c.Mac, c.SiteName, c.GwName, c.SwName, c.Vlan.Txt, c.IP, c.Oui, c.Network, c.SwPort.Txt, c.ApName, ""} | ||||
| 	labelW := append([]string{c.RadioName, c.Radio, c.RadioProto, c.Channel.Txt, c.Essid, c.Bssid, c.RadioDescription}, labels...) | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ type UnifiCollectorCnfg struct { | |||
| 	LoggingFn func(*Report) | ||||
| } | ||||
| 
 | ||||
| type unifiCollector struct { | ||||
| type promUnifi struct { | ||||
| 	Config UnifiCollectorCnfg | ||||
| 	Client *uclient | ||||
| 	Device *unifiDevice | ||||
|  | @ -74,7 +74,7 @@ func NewUnifiCollector(opts UnifiCollectorCnfg) prometheus.Collector { | |||
| 	if opts.Namespace = strings.Trim(opts.Namespace, "_") + "_"; opts.Namespace == "_" { | ||||
| 		opts.Namespace = "" | ||||
| 	} | ||||
| 	return &unifiCollector{ | ||||
| 	return &promUnifi{ | ||||
| 		Config: opts, | ||||
| 		Client: descClient(opts.Namespace + "client_"), | ||||
| 		Device: descDevice(opts.Namespace + "device_"), // stats for all device types.
 | ||||
|  | @ -87,7 +87,7 @@ func NewUnifiCollector(opts UnifiCollectorCnfg) prometheus.Collector { | |||
| 
 | ||||
| // Describe satisfies the prometheus Collector. This returns all of the
 | ||||
| // metric descriptions that this packages produces.
 | ||||
| func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) { | ||||
| func (u *promUnifi) Describe(ch chan<- *prometheus.Desc) { | ||||
| 	for _, f := range []interface{}{u.Client, u.Device, u.UAP, u.USG, u.USW, u.Site} { | ||||
| 		v := reflect.Indirect(reflect.ValueOf(f)) | ||||
| 		// Loop each struct member and send it to the provided channel.
 | ||||
|  | @ -102,7 +102,7 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) { | |||
| 
 | ||||
| // Collect satisfies the prometheus Collector. This runs the input method to get
 | ||||
| // the current metrics (from another package) then exports them for prometheus.
 | ||||
| func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { | ||||
| func (u *promUnifi) Collect(ch chan<- prometheus.Metric) { | ||||
| 	var err error | ||||
| 	r := &Report{cf: u.Config, ch: make(chan []*metric, buffer), Start: time.Now()} | ||||
| 	defer r.close() | ||||
|  | @ -126,7 +126,7 @@ func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { | |||
| 
 | ||||
| // 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 *unifiCollector) exportMetrics(r report, ch chan<- prometheus.Metric) { | ||||
| func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) { | ||||
| 	descs := make(map[*prometheus.Desc]bool) // used as a counter
 | ||||
| 	defer r.report(descs) | ||||
| 	for newMetrics := range r.channel() { | ||||
|  |  | |||
|  | @ -4,42 +4,42 @@ package promunifi | |||
| // Moved them here to consolate clutter from the other files. Also, if these change,
 | ||||
| // they usually all change at once since they're pretty much the same code.
 | ||||
| 
 | ||||
| func (u *unifiCollector) loopSites(r report) { | ||||
| func (u *promUnifi) loopSites(r report) { | ||||
| 	defer r.done() | ||||
| 	for _, s := range r.metrics().Sites { | ||||
| 		u.exportSite(r, s) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) loopUAPs(r report) { | ||||
| func (u *promUnifi) loopUAPs(r report) { | ||||
| 	defer r.done() | ||||
| 	for _, d := range r.metrics().UAPs { | ||||
| 		u.exportUAP(r, d) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) loopUDMs(r report) { | ||||
| func (u *promUnifi) loopUDMs(r report) { | ||||
| 	defer r.done() | ||||
| 	for _, d := range r.metrics().UDMs { | ||||
| 		u.exportUDM(r, d) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) loopUSGs(r report) { | ||||
| func (u *promUnifi) loopUSGs(r report) { | ||||
| 	defer r.done() | ||||
| 	for _, d := range r.metrics().USGs { | ||||
| 		u.exportUSG(r, d) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) loopUSWs(r report) { | ||||
| func (u *promUnifi) loopUSWs(r report) { | ||||
| 	defer r.done() | ||||
| 	for _, d := range r.metrics().USWs { | ||||
| 		u.exportUSW(r, d) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) loopClients(r report) { | ||||
| func (u *promUnifi) loopClients(r report) { | ||||
| 	defer r.done() | ||||
| 	for _, c := range r.metrics().Clients { | ||||
| 		u.exportClient(r, c) | ||||
|  |  | |||
|  | @ -64,7 +64,7 @@ func descSite(ns string) *site { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportSite(r report, s *unifi.Site) { | ||||
| func (u *promUnifi) exportSite(r report, s *unifi.Site) { | ||||
| 	for _, h := range s.Health { | ||||
| 		labels := []string{h.Subsystem, h.Status, s.SiteName} | ||||
| 		switch h.Subsystem { | ||||
|  |  | |||
|  | @ -165,7 +165,7 @@ func descUAP(ns string) *uap { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportUAP(r report, d *unifi.UAP) { | ||||
| func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { | ||||
| 	labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} | ||||
| 	// Wireless System Data.
 | ||||
| 	r.send([]*metric{ | ||||
|  | @ -195,7 +195,7 @@ func (u *unifiCollector) exportUAP(r report, d *unifi.UAP) { | |||
| 	u.exportRadtable(r, labels, d.RadioTable, d.RadioTableStats) | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportUAPstats(r report, labels []string, ap *unifi.Ap) { | ||||
| func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap) { | ||||
| 	//	labelA := append([]string{"all"}, labels[2:]...)
 | ||||
| 	labelU := append([]string{"user"}, labels[6:]...) | ||||
| 	labelG := append([]string{"guest"}, labels[6:]...) | ||||
|  | @ -249,7 +249,7 @@ func (u *unifiCollector) exportUAPstats(r report, labels []string, ap *unifi.Ap) | |||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportVAPtable(r report, labels []string, vt unifi.VapTable) { | ||||
| func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) { | ||||
| 	// vap table stats
 | ||||
| 	for _, v := range vt { | ||||
| 		if !v.Up.Val { | ||||
|  | @ -299,7 +299,7 @@ func (u *unifiCollector) exportVAPtable(r report, labels []string, vt unifi.VapT | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportRadtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) { | ||||
| func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) { | ||||
| 	// radio table
 | ||||
| 	for _, p := range rt { | ||||
| 		labelR := append([]string{p.Name, p.Radio}, labels[6:]...) | ||||
|  |  | |||
|  | @ -68,7 +68,7 @@ func descDevice(ns string) *unifiDevice { | |||
| } | ||||
| 
 | ||||
| // UDM is a collection of stats from USG, USW and UAP. It has no unique stats.
 | ||||
| func (u *unifiCollector) exportUDM(r report, d *unifi.UDM) { | ||||
| func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { | ||||
| 	labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} | ||||
| 	// Dream Machine System Data.
 | ||||
| 	r.send([]*metric{ | ||||
|  |  | |||
|  | @ -66,7 +66,7 @@ func descUSG(ns string) *usg { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportUSG(r report, d *unifi.USG) { | ||||
| func (u *promUnifi) exportUSG(r report, d *unifi.USG) { | ||||
| 	labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} | ||||
| 	// Gateway System Data.
 | ||||
| 	r.send([]*metric{ | ||||
|  | @ -93,7 +93,7 @@ func (u *unifiCollector) exportUSG(r report, d *unifi.USG) { | |||
| 	u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus) | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus) { | ||||
| func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus) { | ||||
| 	labelLan := []string{"lan", labels[6], labels[7]} | ||||
| 	labelWan := []string{"all", labels[6], labels[7]} | ||||
| 	r.send([]*metric{ | ||||
|  | @ -118,7 +118,7 @@ func (u *unifiCollector) exportUSGstats(r report, labels []string, gw *unifi.Gw, | |||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportWANPorts(r report, labels []string, wans ...unifi.Wan) { | ||||
| func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) { | ||||
| 	for _, wan := range wans { | ||||
| 		if !wan.Up.Val { | ||||
| 			continue // only record UP interfaces.
 | ||||
|  |  | |||
|  | @ -90,7 +90,7 @@ func descUSW(ns string) *usw { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportUSW(r report, d *unifi.USW) { | ||||
| func (u *promUnifi) exportUSW(r report, d *unifi.USW) { | ||||
| 	labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} | ||||
| 	if d.HasTemperature.Val { | ||||
| 		r.send([]*metric{{u.Device.Temperature, prometheus.GaugeValue, d.GeneralTemperature, labels}}) | ||||
|  | @ -122,7 +122,7 @@ func (u *unifiCollector) exportUSW(r report, d *unifi.USW) { | |||
| 	u.exportUSWstats(r, labels, d.Stat.Sw) | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportUSWstats(r report, labels []string, sw *unifi.Sw) { | ||||
| func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) { | ||||
| 	labelS := labels[6:] | ||||
| 	r.send([]*metric{ | ||||
| 		{u.USW.SwRxPackets, prometheus.CounterValue, sw.RxPackets, labelS}, | ||||
|  | @ -144,7 +144,7 @@ func (u *unifiCollector) exportUSWstats(r report, labels []string, sw *unifi.Sw) | |||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (u *unifiCollector) exportPortTable(r report, labels []string, pt []unifi.Port) { | ||||
| func (u *promUnifi) exportPortTable(r report, labels []string, pt []unifi.Port) { | ||||
| 	// Per-port data on a switch
 | ||||
| 	for _, p := range pt { | ||||
| 		if !p.Up.Val { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue