diff --git a/poller/helpers.go b/poller/helpers.go index 3ac9bf4d..71421b16 100644 --- a/poller/helpers.go +++ b/poller/helpers.go @@ -6,12 +6,14 @@ import ( "strings" ) +const callDepth = 2 + // LogError logs an error and increments the error counter. // Should be used in the poller loop. func (u *UnifiPoller) LogError(err error, prefix string) { if err != nil { u.errorCount++ - _ = log.Output(2, fmt.Sprintf("[ERROR] %v: %v", prefix, err)) + _ = log.Output(callDepth, fmt.Sprintf("[ERROR] %v: %v", prefix, err)) } } @@ -28,18 +30,18 @@ func StringInSlice(str string, slice []string) bool { // Logf prints a log entry if quiet is false. func (u *UnifiPoller) Logf(m string, v ...interface{}) { if !u.Config.Quiet { - _ = log.Output(2, fmt.Sprintf("[INFO] "+m, v...)) + _ = log.Output(callDepth, fmt.Sprintf("[INFO] "+m, v...)) } } // LogDebugf prints a debug log entry if debug is true and quite is false func (u *UnifiPoller) LogDebugf(m string, v ...interface{}) { if u.Config.Debug && !u.Config.Quiet { - _ = log.Output(2, fmt.Sprintf("[DEBUG] "+m, v...)) + _ = log.Output(callDepth, fmt.Sprintf("[DEBUG] "+m, v...)) } } // LogErrorf prints an error log entry. This is used for external library logging. func (u *UnifiPoller) LogErrorf(m string, v ...interface{}) { - _ = log.Output(2, fmt.Sprintf("[ERROR] "+m, v...)) + _ = log.Output(callDepth, fmt.Sprintf("[ERROR] "+m, v...)) } diff --git a/poller/unifi.go b/poller/unifi.go index 26dc4bf2..f5bcd9ba 100644 --- a/poller/unifi.go +++ b/poller/unifi.go @@ -78,8 +78,7 @@ func (u *UnifiPoller) CollectMetrics() (*metrics.Metrics, error) { m.Sites, err = u.GetFilteredSites() u.LogError(err, "unifi.GetSites()") if u.Config.CollectIDS { - // Check back in time since twice the interval. Dups are discarded by InfluxDB. - m.IDSList, err = u.Unifi.GetIDS(m.Sites, time.Now().Add(2*u.Config.Interval.Duration), time.Now()) + m.IDSList, err = u.Unifi.GetIDS(m.Sites, time.Now().Add(u.Config.Interval.Duration), time.Now()) u.LogError(err, "unifi.GetIDS()") } // Get all the points. diff --git a/promunifi/collector.go b/promunifi/collector.go index 6714f048..0aa781b2 100644 --- a/promunifi/collector.go +++ b/promunifi/collector.go @@ -22,7 +22,7 @@ type UnifiCollectorCnfg struct { // will be collected at all. ReportErrors bool // This function is passed to the Collect() method. The Collect method runs - // this function to retreive the latest UniFi measurements and export them. + // this function to retrieve the latest UniFi measurements and export them. CollectFn func() (*metrics.Metrics, error) // Provide a logger function if you want to run a routine *after* prometheus checks in. LoggingFn func(*Report) @@ -98,7 +98,7 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) { describe(u.Site) } -// Collect satisifes the prometheus Collector. This runs the input method to get +// 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) { var err error diff --git a/promunifi/site.go b/promunifi/site.go index b89ef2f3..2ce333c2 100644 --- a/promunifi/site.go +++ b/promunifi/site.go @@ -67,17 +67,16 @@ func descSite(ns string) *site { } } -func (u *unifiCollector) exportSites(sites unifi.Sites, ch chan []*metricExports) (e []*metricExports) { +func (u *unifiCollector) exportSites(sites unifi.Sites, ch chan []*metricExports) { for _, s := range sites { ch <- u.exportSite(s) } - return } // exportSite exports Network Site Data func (u *unifiCollector) exportSite(s *unifi.Site) []*metricExports { labels := []string{s.Name, s.Desc, s.SiteName} - var metrics []*metricExports + metrics := []*metricExports{} for _, h := range s.Health { l := append([]string{h.Subsystem, h.Status, h.GwVersion}, labels...) diff --git a/promunifi/uap.go b/promunifi/uap.go index 7a71203b..29126bbf 100644 --- a/promunifi/uap.go +++ b/promunifi/uap.go @@ -83,7 +83,7 @@ func descUAP(ns string) *uap { Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil), TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil), TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil), - TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transfered", labels, nil), + TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil), BytesD: prometheus.NewDesc(ns+"bytes_d_total", "Total Bytes D???", labels, nil), TxBytesD: prometheus.NewDesc(ns+"bytes_d_tx", "Transmit Bytes D???", labels, nil), RxBytesD: prometheus.NewDesc(ns+"bytes_d_rx", "Receive Bytes D???", labels, nil), diff --git a/promunifi/usg.go b/promunifi/usg.go index 7e832920..1fafd54e 100644 --- a/promunifi/usg.go +++ b/promunifi/usg.go @@ -66,7 +66,7 @@ func descUSG(ns string) *usg { Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil), TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil), TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil), - TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transfered", labels, nil), + TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil), NumSta: prometheus.NewDesc(ns+"stations_total", "Number of Stations", labels, nil), UserNumSta: prometheus.NewDesc(ns+"stations_user_total", "Number of User Stations", labels, nil), GuestNumSta: prometheus.NewDesc(ns+"stations_guest_total", "Number of Guest Stations", labels, nil), @@ -164,7 +164,7 @@ func (u *unifiCollector) exportUSG(s *unifi.USG) []*metricExports { } func (u *unifiCollector) exportWANPorts(labels []string, wans ...unifi.Wan) []*metricExports { - var metrics []*metricExports + metrics := []*metricExports{} for _, wan := range wans { if !wan.Up.Val { continue // only record UP interfaces. diff --git a/promunifi/usw.go b/promunifi/usw.go index 7cbefcf9..54b4bc53 100644 --- a/promunifi/usw.go +++ b/promunifi/usw.go @@ -83,7 +83,7 @@ func descUSW(ns string) *usw { FanLevel: prometheus.NewDesc(ns+"fan_level", "Fan Level", labels, nil), TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil), TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil), - TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transfered", labels, nil), + TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil), NumSta: prometheus.NewDesc(ns+"stations_total", "Number of Stations", labels, nil), UserNumSta: prometheus.NewDesc(ns+"stations_user_total", "Number of User Stations", labels, nil), GuestNumSta: prometheus.NewDesc(ns+"stations_guest_total", "Number of Guest Stations", labels, nil), @@ -111,7 +111,7 @@ func descUSW(ns string) *usw { SwRxBroadcast: prometheus.NewDesc(ns+"switch_broadcast_rx_total", "Switch Broadcast Receive Total", labels, nil), SwTxMulticast: prometheus.NewDesc(ns+"switch_multicast_tx_total", "Switch Multicast Transmit Total", labels, nil), SwTxBroadcast: prometheus.NewDesc(ns+"switch_broadcast_tx_total", "Switch Broadcast Transmit Total", labels, nil), - SwBytes: prometheus.NewDesc(ns+"switch_bytes_total", "Switch Bytes Transfered Total", labels, nil), + SwBytes: prometheus.NewDesc(ns+"switch_bytes_total", "Switch Bytes Transferred Total", labels, nil), // per-port data PoeCurrent: prometheus.NewDesc(pns+"poe_current", "POE Current", labelP, nil), @@ -187,7 +187,7 @@ func (u *unifiCollector) exportUSW(s *unifi.USW) []*metricExports { } func (u *unifiCollector) exportPortTable(pt []unifi.Port, labels []string) []*metricExports { - var metrics []*metricExports + metrics := []*metricExports{} // Per-port data on a switch for _, p := range pt { // Copy labels, and add four new ones.