Update lint
This commit is contained in:
parent
7e95254b44
commit
26e49dbdcd
|
|
@ -1,9 +1,9 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.13.x
|
||||
- 1.14.x
|
||||
before_install:
|
||||
# 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
|
||||
script:
|
||||
- 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}})
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// fillDPIMapTotals fills in totals for categories and applications. maybe clients too.
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ const (
|
|||
gauge = prometheus.GaugeValue
|
||||
)
|
||||
|
||||
var (
|
||||
errMetricFetchFailed = fmt.Errorf("metric fetch failed")
|
||||
)
|
||||
|
||||
type promUnifi struct {
|
||||
*Config `json:"prometheus" toml:"prometheus" xml:"prometheus" yaml:"prometheus"`
|
||||
Client *uclient
|
||||
|
|
@ -82,7 +86,9 @@ type target struct {
|
|||
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{}}
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
if !ok {
|
||||
|
|
@ -272,81 +278,40 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric, ourChan
|
|||
func (u *promUnifi) loopExports(r report) {
|
||||
m := r.metrics()
|
||||
|
||||
r.add()
|
||||
r.add()
|
||||
r.add()
|
||||
r.add()
|
||||
r.add()
|
||||
r.add()
|
||||
r.add()
|
||||
r.add()
|
||||
for _, s := range m.Sites {
|
||||
u.exportSite(r, s)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer r.done()
|
||||
for _, s := range m.SitesDPI {
|
||||
u.exportSiteDPI(r, s)
|
||||
}
|
||||
|
||||
for _, s := range m.Sites {
|
||||
u.exportSite(r, s)
|
||||
}
|
||||
}()
|
||||
for _, c := range m.Clients {
|
||||
u.exportClient(r, c)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer r.done()
|
||||
appTotal := make(totalsDPImap)
|
||||
catTotal := make(totalsDPImap)
|
||||
|
||||
for _, s := range m.SitesDPI {
|
||||
u.exportSiteDPI(r, s)
|
||||
}
|
||||
}()
|
||||
for _, c := range m.ClientsDPI {
|
||||
u.exportClientDPI(r, c, appTotal, catTotal)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer r.done()
|
||||
u.exportClientDPItotals(r, appTotal, catTotal)
|
||||
|
||||
for _, c := range m.Clients {
|
||||
u.exportClient(r, c)
|
||||
}
|
||||
}()
|
||||
for _, d := range m.UAPs {
|
||||
u.exportUAP(r, d)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer r.done()
|
||||
for _, d := range m.UDMs {
|
||||
u.exportUDM(r, d)
|
||||
}
|
||||
|
||||
appTotal := make(totalsDPImap)
|
||||
catTotal := make(totalsDPImap)
|
||||
for _, d := range m.USGs {
|
||||
u.exportUSG(r, d)
|
||||
}
|
||||
|
||||
for _, c := range m.ClientsDPI {
|
||||
u.exportClientDPI(r, c, appTotal, catTotal)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}()
|
||||
for _, d := range m.USWs {
|
||||
u.exportUSW(r, d)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ import (
|
|||
// This file contains the report interface.
|
||||
// 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 {
|
||||
add()
|
||||
done()
|
||||
send([]*metric)
|
||||
metrics() *poller.Metrics
|
||||
|
|
@ -22,20 +21,15 @@ type report interface {
|
|||
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
|
||||
}
|
||||
|
||||
// satisfy gomnd
|
||||
const one = 1
|
||||
// Satisfy gomnd.
|
||||
const oneDecimalPoint = 10.0
|
||||
|
||||
func (r *Report) add() {
|
||||
r.wg.Add(one)
|
||||
}
|
||||
|
||||
func (r *Report) done() {
|
||||
r.wg.Add(-one)
|
||||
r.wg.Done()
|
||||
}
|
||||
|
||||
func (r *Report) send(m []*metric) {
|
||||
r.wg.Add(one)
|
||||
r.wg.Add(1) // notlint: gomnd
|
||||
r.ch <- m
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +63,7 @@ func (r *Report) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interf
|
|||
r.Errors++
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func descUAP(ns string) *uap {
|
||||
func descUAP(ns string) *uap { // nolint: funlen
|
||||
labelA := []string{"stat", "site_name", "name", "source"} // stat + labels[1:]
|
||||
labelV := []string{"vap_name", "bssid", "radio", "radio_name", "essid", "usage", "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) {
|
||||
// vap table stats
|
||||
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) {
|
||||
// radio table
|
||||
for _, p := range rt {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"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 {
|
||||
Info *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) {
|
||||
r.send([]*metric{
|
||||
{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) {
|
||||
r.send([]*metric{
|
||||
{u.Device.Counter, gauge, stas[0], append(labels, "user")},
|
||||
{u.Device.Counter, gauge, stas[1], append(labels, "guest")},
|
||||
})
|
||||
|
||||
if len(stas) > 2 {
|
||||
if len(stas) > 2 { // nolint: gomnd
|
||||
r.send([]*metric{
|
||||
{u.Device.Counter, gauge, stas[2], append(labels, "desktop")},
|
||||
{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) {
|
||||
r.send([]*metric{
|
||||
{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) {
|
||||
if gw == nil {
|
||||
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) {
|
||||
for _, wan := range wans {
|
||||
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) {
|
||||
if sw == nil {
|
||||
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) {
|
||||
// Per-port data on a switch
|
||||
for _, p := range pt {
|
||||
|
|
|
|||
Loading…
Reference in New Issue