satisfy new interface

This commit is contained in:
davidnewhall2 2020-06-21 16:36:59 -07:00
parent 7c90bccdeb
commit e7ce83dc86
6 changed files with 81 additions and 45 deletions

View File

@ -75,7 +75,13 @@ func (u *InfluxUnifi) batchClient(r report, s *unifi.Client) { // nolint: funlen
// totalsDPImap: controller, site, name (app/cat name), dpi.
type totalsDPImap map[string]map[string]map[string]unifi.DPIData
func (u *InfluxUnifi) batchClientDPI(r report, s *unifi.DPITable, appTotal, catTotal totalsDPImap) {
func (u *InfluxUnifi) batchClientDPI(r report, v interface{}, appTotal, catTotal totalsDPImap) {
s, ok := v.(*unifi.DPITable)
if !ok {
u.Collector.LogErrorf("invalid type given to batchClientDPI: %T", v)
return
}
for _, dpi := range s.ByApp {
category := unifi.DPICats.Get(dpi.Cat)
application := unifi.DPIApps.GetApp(dpi.Cat, dpi.App)

View File

@ -5,7 +5,7 @@ go 1.14
require (
github.com/influxdata/influxdb1-client v0.0.0-20200515024757-02f0bf5dbca3
github.com/pkg/errors v0.9.1
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10
github.com/unifi-poller/poller v0.0.8-0.20200621214016-5d1ed3324a46
github.com/unifi-poller/unifi v0.0.5-0.20200621075746-253ccae7e106
golift.io/cnfg v0.0.5
)

View File

@ -104,6 +104,8 @@ github.com/unifi-poller/poller v0.0.8-0.20200621103717-5f3d60890ed6 h1:V19WgXwjX
github.com/unifi-poller/poller v0.0.8-0.20200621103717-5f3d60890ed6/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4=
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10 h1:1rGP4ISFpBj9xjJDXNak7EdaQtyoy3MwMZzo2+W1PLo=
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4=
github.com/unifi-poller/poller v0.0.8-0.20200621214016-5d1ed3324a46 h1:OhbVj3VVgbpUMQFSwD0NszDsbEL7DdbTcJuU+p9DwIM=
github.com/unifi-poller/poller v0.0.8-0.20200621214016-5d1ed3324a46/go.mod h1:pJ/MeYaakLOOpbyc7s4zeZ92UzNK/rir5jkA7t5jIjo=
github.com/unifi-poller/promunifi v0.0.9-0.20200620104707-26208eb4336b h1:HgmbS5cKfvw3x0ie6IV/FfhxNtKwAvICKxXL7gg2sgM=
github.com/unifi-poller/promunifi v0.0.9-0.20200620104707-26208eb4336b/go.mod h1:jOcYehhsOrs4ctswSKEqGuqSgVBpConaWmRYskycbUc=
github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8=

View File

@ -215,12 +215,24 @@ func (u *InfluxUnifi) collect(r report, ch chan *metric) {
func (u *InfluxUnifi) loopPoints(r report) {
m := r.metrics()
for _, s := range m.Sites {
u.switchExport(r, s)
}
for _, s := range m.SitesDPI {
u.batchSiteDPI(r, s)
}
for _, s := range m.Sites {
u.batchSite(r, s)
for _, s := range m.Clients {
u.switchExport(r, s)
}
for _, s := range m.Devices {
u.switchExport(r, s)
}
for _, s := range r.events().Logs {
u.switchExport(r, s)
}
appTotal := make(totalsDPImap)
@ -231,46 +243,32 @@ func (u *InfluxUnifi) loopPoints(r report) {
}
reportClientDPItotals(r, appTotal, catTotal)
for _, s := range m.Clients {
u.batchClient(r, s)
}
for _, s := range r.events().Logs {
switch v := s.(type) {
case *unifi.Event:
u.batchEvent(r, v)
case *unifi.IDS:
u.batchIDS(r, v)
default:
u.Collector.LogErrorf("invalid event: %T", v)
}
}
u.loopDevicePoints(r)
}
func (u *InfluxUnifi) loopDevicePoints(r report) {
m := r.metrics()
if m.Devices == nil {
m.Devices = &unifi.Devices{}
return
}
for _, s := range m.UAPs {
u.batchUAP(r, s)
}
for _, s := range m.USGs {
u.batchUSG(r, s)
}
for _, s := range m.USWs {
u.batchUSW(r, s)
}
for _, s := range m.UDMs {
u.batchUDM(r, s)
func (u *InfluxUnifi) switchExport(r report, v interface{}) {
switch v := v.(type) {
case *unifi.UAP:
r.addUAP()
u.batchUAP(r, v)
case *unifi.USW:
r.addUSW()
u.batchUSW(r, v)
case *unifi.USG:
r.addUSG()
u.batchUSG(r, v)
case *unifi.UDM:
r.addUDM()
u.batchUDM(r, v)
case *unifi.Site:
u.batchSite(r, v)
case *unifi.Client:
u.batchClient(r, v)
case *unifi.Event:
u.batchEvent(r, v)
case *unifi.IDS:
u.batchIDS(r, v)
default:
u.Collector.LogErrorf("invalid export type: %T", v)
}
}
@ -280,7 +278,7 @@ func (u *InfluxUnifi) LogInfluxReport(r *Report) {
u.Collector.Logf("UniFi Metrics Recorded. Sites: %d, Clients: %d, "+
"UAP: %d, USG/UDM: %d, USW: %d, IDS+Events: %d, Points: %d, "+
"Fields: %d, Errs: %d, Elapsed: %v",
len(m.Sites), len(m.Clients), len(m.UAPs), len(m.UDMs)+len(m.USGs),
len(m.USWs), len(r.Events.Logs), r.Total,
len(m.Sites), len(m.Clients), r.UAP, r.UDM+r.USG,
r.USW, len(r.Events.Logs), r.Total,
r.Fields, len(r.Errors), r.Elapsed.Round(time.Millisecond))
}

View File

@ -15,6 +15,10 @@ type Report struct {
Errors []error
Total int
Fields int
USG int // Total count of USG devices.
USW int // Total count of USW devices.
UAP int // Total count of UAP devices.
UDM int // Total count of UDM devices.
Start time.Time
Elapsed time.Duration
ch chan *metric
@ -31,6 +35,10 @@ type report interface {
batch(m *metric, pt *influx.Point)
metrics() *poller.Metrics
events() *poller.Events
addUDM()
addUSG()
addUAP()
addUSW()
}
func (r *Report) metrics() *poller.Metrics {
@ -56,6 +64,22 @@ func (r *Report) send(m *metric) {
/* The following methods are not thread safe. */
func (r *Report) addUSW() {
r.USW++
}
func (r *Report) addUAP() {
r.UAP++
}
func (r *Report) addUSG() {
r.USG++
}
func (r *Report) addUDM() {
r.UDM++
}
func (r *Report) error(err error) {
if err != nil {
r.Errors = append(r.Errors, err)

View File

@ -57,7 +57,13 @@ func (u *InfluxUnifi) batchSite(r report, s *unifi.Site) {
}
}
func (u *InfluxUnifi) batchSiteDPI(r report, s *unifi.DPITable) {
func (u *InfluxUnifi) batchSiteDPI(r report, v interface{}) {
s, ok := v.(*unifi.DPITable)
if !ok {
u.Collector.LogErrorf("invalid type given to batchSiteDPI: %T", v)
return
}
for _, dpi := range s.ByApp {
r.send(&metric{
Table: "sitedpi",