From 883a5a7beb49195acfef11b1a30ed7bf1b5add5c Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Fri, 29 Nov 2019 22:58:48 -0800 Subject: [PATCH] still cleaning --- promunifi/clients.go | 2 +- promunifi/collector.go | 10 +++++----- promunifi/loops.go | 12 ++++++------ promunifi/site.go | 2 +- promunifi/uap.go | 8 ++++---- promunifi/udm.go | 2 +- promunifi/usg.go | 6 +++--- promunifi/usw.go | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/promunifi/clients.go b/promunifi/clients.go index 10c32859..c6d0186f 100644 --- a/promunifi/clients.go +++ b/promunifi/clients.go @@ -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...) diff --git a/promunifi/collector.go b/promunifi/collector.go index 6433ce13..25cfd370 100644 --- a/promunifi/collector.go +++ b/promunifi/collector.go @@ -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() { diff --git a/promunifi/loops.go b/promunifi/loops.go index 1e7cd522..9e086ec3 100644 --- a/promunifi/loops.go +++ b/promunifi/loops.go @@ -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) diff --git a/promunifi/site.go b/promunifi/site.go index 73248553..0acc3cec 100644 --- a/promunifi/site.go +++ b/promunifi/site.go @@ -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 { diff --git a/promunifi/uap.go b/promunifi/uap.go index 8a1f0eac..ed8507df 100644 --- a/promunifi/uap.go +++ b/promunifi/uap.go @@ -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:]...) diff --git a/promunifi/udm.go b/promunifi/udm.go index 09206540..9a17b41b 100644 --- a/promunifi/udm.go +++ b/promunifi/udm.go @@ -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{ diff --git a/promunifi/usg.go b/promunifi/usg.go index 8392d4a3..b8764522 100644 --- a/promunifi/usg.go +++ b/promunifi/usg.go @@ -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. diff --git a/promunifi/usw.go b/promunifi/usw.go index 2c25271e..88f7e190 100644 --- a/promunifi/usw.go +++ b/promunifi/usw.go @@ -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 {