Update lint
This commit is contained in:
parent
7e95254b44
commit
26e49dbdcd
|
|
@ -1,9 +1,9 @@
|
||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.13.x
|
- 1.14.x
|
||||||
before_install:
|
before_install:
|
||||||
# download super-linter: golangci-lint
|
# download super-linter: golangci-lint
|
||||||
- curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest
|
- curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest
|
||||||
script:
|
script:
|
||||||
- go test ./...
|
- go test ./...
|
||||||
- golangci-lint run --enable-all -D gochecknoinits -D funlen -D gomnd
|
- golangci-lint run --enable-all
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ func (u *promUnifi) exportClient(r report, c *unifi.Client) {
|
||||||
r.send([]*metric{{u.Client.Uptime, gauge, c.Uptime, labelW}})
|
r.send([]*metric{{u.Client.Uptime, gauge, c.Uptime, labelW}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// totalsDPImap: controller, site, name (app/cat name), dpi
|
// totalsDPImap: controller, site, name (app/cat name), dpi.
|
||||||
type totalsDPImap map[string]map[string]map[string]unifi.DPIData
|
type totalsDPImap map[string]map[string]map[string]unifi.DPIData
|
||||||
|
|
||||||
// fillDPIMapTotals fills in totals for categories and applications. maybe clients too.
|
// fillDPIMapTotals fills in totals for categories and applications. maybe clients too.
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ const (
|
||||||
gauge = prometheus.GaugeValue
|
gauge = prometheus.GaugeValue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errMetricFetchFailed = fmt.Errorf("metric fetch failed")
|
||||||
|
)
|
||||||
|
|
||||||
type promUnifi struct {
|
type promUnifi struct {
|
||||||
*Config `json:"prometheus" toml:"prometheus" xml:"prometheus" yaml:"prometheus"`
|
*Config `json:"prometheus" toml:"prometheus" xml:"prometheus" yaml:"prometheus"`
|
||||||
Client *uclient
|
Client *uclient
|
||||||
|
|
@ -82,7 +86,9 @@ type target struct {
|
||||||
u *promUnifi
|
u *promUnifi
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// init is how this modular code is initialized by the main app.
|
||||||
|
// This module adds itself as an output module to the poller core.
|
||||||
|
func init() { // nolint: gochecknoinits
|
||||||
u := &promUnifi{Config: &Config{}}
|
u := &promUnifi{Config: &Config{}}
|
||||||
|
|
||||||
poller.NewOutput(&poller.Output{
|
poller.NewOutput(&poller.Output{
|
||||||
|
|
@ -223,7 +229,7 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter)
|
||||||
r.Fetch = time.Since(r.Start)
|
r.Fetch = time.Since(r.Start)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.error(ch, prometheus.NewInvalidDesc(err), fmt.Errorf("metric fetch failed"))
|
r.error(ch, prometheus.NewInvalidDesc(err), errMetricFetchFailed)
|
||||||
u.Collector.LogErrorf("metric fetch failed: %v", err)
|
u.Collector.LogErrorf("metric fetch failed: %v", err)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -272,81 +278,40 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric, ourChan
|
||||||
func (u *promUnifi) loopExports(r report) {
|
func (u *promUnifi) loopExports(r report) {
|
||||||
m := r.metrics()
|
m := r.metrics()
|
||||||
|
|
||||||
r.add()
|
for _, s := range m.Sites {
|
||||||
r.add()
|
u.exportSite(r, s)
|
||||||
r.add()
|
}
|
||||||
r.add()
|
|
||||||
r.add()
|
|
||||||
r.add()
|
|
||||||
r.add()
|
|
||||||
r.add()
|
|
||||||
|
|
||||||
go func() {
|
for _, s := range m.SitesDPI {
|
||||||
defer r.done()
|
u.exportSiteDPI(r, s)
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range m.Sites {
|
for _, c := range m.Clients {
|
||||||
u.exportSite(r, s)
|
u.exportClient(r, c)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
appTotal := make(totalsDPImap)
|
||||||
defer r.done()
|
catTotal := make(totalsDPImap)
|
||||||
|
|
||||||
for _, s := range m.SitesDPI {
|
for _, c := range m.ClientsDPI {
|
||||||
u.exportSiteDPI(r, s)
|
u.exportClientDPI(r, c, appTotal, catTotal)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
u.exportClientDPItotals(r, appTotal, catTotal)
|
||||||
defer r.done()
|
|
||||||
|
|
||||||
for _, c := range m.Clients {
|
for _, d := range m.UAPs {
|
||||||
u.exportClient(r, c)
|
u.exportUAP(r, d)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
for _, d := range m.UDMs {
|
||||||
defer r.done()
|
u.exportUDM(r, d)
|
||||||
|
}
|
||||||
|
|
||||||
appTotal := make(totalsDPImap)
|
for _, d := range m.USGs {
|
||||||
catTotal := make(totalsDPImap)
|
u.exportUSG(r, d)
|
||||||
|
}
|
||||||
|
|
||||||
for _, c := range m.ClientsDPI {
|
for _, d := range m.USWs {
|
||||||
u.exportClientDPI(r, c, appTotal, catTotal)
|
u.exportUSW(r, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
u.exportClientDPItotals(r, appTotal, catTotal)
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer r.done()
|
|
||||||
|
|
||||||
for _, d := range m.UAPs {
|
|
||||||
u.exportUAP(r, d)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer r.done()
|
|
||||||
|
|
||||||
for _, d := range m.UDMs {
|
|
||||||
u.exportUDM(r, d)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer r.done()
|
|
||||||
|
|
||||||
for _, d := range m.USGs {
|
|
||||||
u.exportUSG(r, d)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer r.done()
|
|
||||||
|
|
||||||
for _, d := range m.USWs {
|
|
||||||
u.exportUSW(r, d)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,8 @@ import (
|
||||||
// This file contains the report interface.
|
// This file contains the report interface.
|
||||||
// This interface can be mocked and overridden for tests.
|
// This interface can be mocked and overridden for tests.
|
||||||
|
|
||||||
// report is an internal interface used to "process metrics"
|
// report is an internal interface used to "process metrics".
|
||||||
type report interface {
|
type report interface {
|
||||||
add()
|
|
||||||
done()
|
done()
|
||||||
send([]*metric)
|
send([]*metric)
|
||||||
metrics() *poller.Metrics
|
metrics() *poller.Metrics
|
||||||
|
|
@ -22,20 +21,15 @@ type report interface {
|
||||||
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
|
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// satisfy gomnd
|
// Satisfy gomnd.
|
||||||
const one = 1
|
|
||||||
const oneDecimalPoint = 10.0
|
const oneDecimalPoint = 10.0
|
||||||
|
|
||||||
func (r *Report) add() {
|
|
||||||
r.wg.Add(one)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Report) done() {
|
func (r *Report) done() {
|
||||||
r.wg.Add(-one)
|
r.wg.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Report) send(m []*metric) {
|
func (r *Report) send(m []*metric) {
|
||||||
r.wg.Add(one)
|
r.wg.Add(1) // notlint: gomnd
|
||||||
r.ch <- m
|
r.ch <- m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +63,7 @@ func (r *Report) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interf
|
||||||
r.Errors++
|
r.Errors++
|
||||||
|
|
||||||
if r.ReportErrors {
|
if r.ReportErrors {
|
||||||
ch <- prometheus.NewInvalidMetric(d, fmt.Errorf("error: %v", v))
|
ch <- prometheus.NewInvalidMetric(d, fmt.Errorf("error: %v", v)) // nolint: goerr113
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ type uap struct {
|
||||||
RadioTxRetries *prometheus.Desc
|
RadioTxRetries *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func descUAP(ns string) *uap {
|
func descUAP(ns string) *uap { // nolint: funlen
|
||||||
labelA := []string{"stat", "site_name", "name", "source"} // stat + labels[1:]
|
labelA := []string{"stat", "site_name", "name", "source"} // stat + labels[1:]
|
||||||
labelV := []string{"vap_name", "bssid", "radio", "radio_name", "essid", "usage", "site_name", "name", "source"}
|
labelV := []string{"vap_name", "bssid", "radio", "radio_name", "essid", "usage", "site_name", "name", "source"}
|
||||||
labelR := []string{"radio_name", "radio", "site_name", "name", "source"}
|
labelR := []string{"radio_name", "radio", "site_name", "name", "source"}
|
||||||
|
|
@ -227,7 +227,7 @@ func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap, byte
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UAP VAP Table
|
// UAP VAP Table.
|
||||||
func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) {
|
func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) {
|
||||||
// vap table stats
|
// vap table stats
|
||||||
for _, v := range vt {
|
for _, v := range vt {
|
||||||
|
|
@ -278,7 +278,7 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UAP Radio Table
|
// UAP Radio Table.
|
||||||
func (u *promUnifi) 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
|
// radio table
|
||||||
for _, p := range rt {
|
for _, p := range rt {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/unifi-poller/unifi"
|
"github.com/unifi-poller/unifi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are shared by all four device types: UDM, UAP, USG, USW
|
// These are shared by all four device types: UDM, UAP, USG, USW.
|
||||||
type unifiDevice struct {
|
type unifiDevice struct {
|
||||||
Info *prometheus.Desc
|
Info *prometheus.Desc
|
||||||
Uptime *prometheus.Desc
|
Uptime *prometheus.Desc
|
||||||
|
|
@ -91,7 +91,7 @@ func (u *promUnifi) exportUDM(r report, d *unifi.UDM) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shared by all
|
// Shared by all.
|
||||||
func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexInt) {
|
func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexInt) {
|
||||||
r.send([]*metric{
|
r.send([]*metric{
|
||||||
{u.Device.TotalTxBytes, counter, tx, labels},
|
{u.Device.TotalTxBytes, counter, tx, labels},
|
||||||
|
|
@ -100,14 +100,14 @@ func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexI
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// shared by all, pass 2 or 5 stats.
|
// 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")},
|
||||||
{u.Device.Counter, gauge, stas[1], append(labels, "guest")},
|
{u.Device.Counter, gauge, stas[1], append(labels, "guest")},
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(stas) > 2 {
|
if len(stas) > 2 { // nolint: gomnd
|
||||||
r.send([]*metric{
|
r.send([]*metric{
|
||||||
{u.Device.Counter, gauge, stas[2], append(labels, "desktop")},
|
{u.Device.Counter, gauge, stas[2], append(labels, "desktop")},
|
||||||
{u.Device.Counter, gauge, stas[3], append(labels, "mobile")},
|
{u.Device.Counter, gauge, stas[3], append(labels, "mobile")},
|
||||||
|
|
@ -116,7 +116,7 @@ func (u *promUnifi) exportSTAcount(r report, labels []string, stas ...unifi.Flex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shared by all
|
// Shared by all.
|
||||||
func (u *promUnifi) exportSYSstats(r report, labels []string, s unifi.SysStats, ss unifi.SystemStats) {
|
func (u *promUnifi) exportSYSstats(r report, labels []string, s unifi.SysStats, ss unifi.SystemStats) {
|
||||||
r.send([]*metric{
|
r.send([]*metric{
|
||||||
{u.Device.Loadavg1, gauge, s.Loadavg1, labels},
|
{u.Device.Loadavg1, gauge, s.Loadavg1, labels},
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gateway States
|
// Gateway Stats.
|
||||||
func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) {
|
func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) {
|
||||||
if gw == nil {
|
if gw == nil {
|
||||||
return
|
return
|
||||||
|
|
@ -117,7 +117,7 @@ func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st u
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// WAN Stats
|
// WAN Stats.
|
||||||
func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) {
|
func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) {
|
||||||
for _, wan := range wans {
|
for _, wan := range wans {
|
||||||
if !wan.Up.Val {
|
if !wan.Up.Val {
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ func (u *promUnifi) exportUSW(r report, d *unifi.USW) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch Stats
|
// Switch Stats.
|
||||||
func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) {
|
func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) {
|
||||||
if sw == nil {
|
if sw == nil {
|
||||||
return
|
return
|
||||||
|
|
@ -152,7 +152,7 @@ func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch Port Table
|
// Switch Port Table.
|
||||||
func (u *promUnifi) exportPRTtable(r report, labels []string, pt []unifi.Port) {
|
func (u *promUnifi) exportPRTtable(r report, labels []string, pt []unifi.Port) {
|
||||||
// Per-port data on a switch
|
// Per-port data on a switch
|
||||||
for _, p := range pt {
|
for _, p := range pt {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue