Cody Lee 2023-01-06 21:12:24 -06:00
parent f243af7dd5
commit 1edb580084
No known key found for this signature in database
8 changed files with 29 additions and 47 deletions

2
go.mod
View File

@ -35,7 +35,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/unpoller/unifi v0.3.0
github.com/unpoller/unifi v0.3.2
golang.org/x/sys v0.3.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect

4
go.sum
View File

@ -75,8 +75,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/unpoller/unifi v0.3.0 h1:cWAt+ytfcwEVr085JMPzsVss5tvMzC9RuvOcP9F+Ux8=
github.com/unpoller/unifi v0.3.0/go.mod h1:pD8ZEJTTlcmLJ6FjIOfujnfvb2P0iyaOwPMHmKW2jXY=
github.com/unpoller/unifi v0.3.2 h1:82rzPlGNkUPBDXpd7KQ/mrAyqCfrlvh5ZJ9mNlzIF28=
github.com/unpoller/unifi v0.3.2/go.mod h1:pD8ZEJTTlcmLJ6FjIOfujnfvb2P0iyaOwPMHmKW2jXY=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=

View File

@ -1,8 +1,6 @@
package datadogunifi
import (
"fmt"
"github.com/unpoller/unifi"
)
@ -90,8 +88,8 @@ func (u *DatadogUnifi) batchClientDPI(r report, v any, appTotal, catTotal totals
}
for _, dpi := range s.ByApp {
category := unifi.DPICats.Get(int(dpi.Cat.Val))
application := unifi.DPIApps.GetApp(int(dpi.Cat.Val), int(dpi.App.Val))
category := unifi.DPICats.Get(dpi.Cat.Int())
application := unifi.DPIApps.GetApp(dpi.Cat.Int(), dpi.App.Int())
fillDPIMapTotals(appTotal, application, s.SourceName, s.SiteName, dpi)
fillDPIMapTotals(catTotal, category, s.SourceName, s.SiteName, dpi)
@ -129,14 +127,10 @@ func fillDPIMapTotals(m totalsDPImap, name, controller, site string, dpi unifi.D
}
existing := m[controller][site][name]
existing.TxPackets.Val += dpi.TxPackets.Val
existing.TxPackets.Txt = fmt.Sprintf("%f", existing.TxPackets.Val)
existing.RxPackets.Val += dpi.RxPackets.Val
existing.RxPackets.Txt = fmt.Sprintf("%f", existing.RxPackets.Val)
existing.TxBytes.Val += dpi.TxBytes.Val
existing.TxBytes.Txt = fmt.Sprintf("%f", existing.TxBytes.Val)
existing.RxBytes.Val += dpi.RxBytes.Val
existing.RxBytes.Txt = fmt.Sprintf("%f", existing.RxBytes.Val)
existing.TxPackets.Add(&dpi.TxPackets)
existing.RxPackets.Add(&dpi.RxPackets)
existing.TxBytes.Add(&dpi.TxBytes)
existing.RxBytes.Add(&dpi.RxBytes)
m[controller][site][name] = existing
}

View File

@ -66,15 +66,15 @@ func (u *DatadogUnifi) reportSiteDPI(r report, s *unifi.DPITable) {
metricName := metricNamespace("sitedpi")
tags := []string{
tag("category", unifi.DPICats.Get(int(dpi.Cat.Val))),
tag("application", unifi.DPIApps.GetApp(int(dpi.Cat.Val), int(dpi.App.Val))),
tag("category", unifi.DPICats.Get(dpi.Cat.Int())),
tag("application", unifi.DPIApps.GetApp(dpi.Cat.Int(), dpi.App.Int())),
tag("site_name", s.SiteName),
tag("source", s.SourceName),
}
_ = r.reportCount(metricName("tx_packets"), int64(dpi.TxPackets.Val), tags)
_ = r.reportCount(metricName("rx_packets"), int64(dpi.RxPackets.Val), tags)
_ = r.reportCount(metricName("tx_bytes"), int64(dpi.TxBytes.Val), tags)
_ = r.reportCount(metricName("rx_bytes"), int64(dpi.RxBytes.Val), tags)
_ = r.reportCount(metricName("tx_packets"), dpi.TxPackets.Int64(), tags)
_ = r.reportCount(metricName("rx_packets"), dpi.RxPackets.Int64(), tags)
_ = r.reportCount(metricName("tx_bytes"), dpi.TxBytes.Int64(), tags)
_ = r.reportCount(metricName("rx_bytes"), dpi.RxBytes.Int64(), tags)
}
}

View File

@ -1,8 +1,6 @@
package influxunifi
import (
"fmt"
"github.com/unpoller/unifi"
)
@ -86,8 +84,8 @@ func (u *InfluxUnifi) batchClientDPI(r report, v any, appTotal, catTotal totalsD
}
for _, dpi := range s.ByApp {
category := unifi.DPICats.Get(int(dpi.Cat.Val))
application := unifi.DPIApps.GetApp(int(dpi.Cat.Val), int(dpi.App.Val))
category := unifi.DPICats.Get(dpi.Cat.Int())
application := unifi.DPIApps.GetApp(dpi.Cat.Int(), dpi.App.Int())
fillDPIMapTotals(appTotal, application, s.SourceName, s.SiteName, dpi)
fillDPIMapTotals(catTotal, category, s.SourceName, s.SiteName, dpi)
@ -123,14 +121,10 @@ func fillDPIMapTotals(m totalsDPImap, name, controller, site string, dpi unifi.D
}
existing := m[controller][site][name]
existing.TxPackets.Val += dpi.TxPackets.Val
existing.TxPackets.Txt = fmt.Sprintf("%f", existing.TxPackets.Val)
existing.RxPackets.Val += dpi.RxPackets.Val
existing.RxPackets.Txt = fmt.Sprintf("%f", existing.RxPackets.Val)
existing.TxBytes.Val += dpi.TxBytes.Val
existing.TxBytes.Txt = fmt.Sprintf("%f", existing.TxBytes.Val)
existing.RxBytes.Val += dpi.RxBytes.Val
existing.RxBytes.Txt = fmt.Sprintf("%f", existing.RxBytes.Val)
existing.TxPackets.Add(&dpi.TxPackets)
existing.RxPackets.Add(&dpi.RxPackets)
existing.TxBytes.Add(&dpi.TxBytes)
existing.RxBytes.Add(&dpi.RxBytes)
m[controller][site][name] = existing
}

View File

@ -68,8 +68,8 @@ func (u *InfluxUnifi) batchSiteDPI(r report, v any) {
r.send(&metric{
Table: "sitedpi",
Tags: map[string]string{
"category": unifi.DPICats.Get(int(dpi.Cat.Val)),
"application": unifi.DPIApps.GetApp(int(dpi.Cat.Val), int(dpi.App.Val)),
"category": unifi.DPICats.Get(dpi.Cat.Int()),
"application": unifi.DPIApps.GetApp(dpi.Cat.Int(), dpi.App.Int()),
"site_name": s.SiteName,
"source": s.SourceName,
},

View File

@ -1,8 +1,6 @@
package promunifi
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/unpoller/unifi"
)
@ -86,7 +84,7 @@ func (u *promUnifi) exportClientDPI(r report, v any, appTotal, catTotal totalsDP
for _, dpi := range s.ByApp {
labelDPI := []string{
s.Name, s.MAC, s.SiteName, s.SourceName,
unifi.DPICats.Get(int(dpi.Cat.Val)), unifi.DPIApps.GetApp(int(dpi.Cat.Val), int(dpi.App.Val)),
unifi.DPICats.Get(int(dpi.Cat.Val)), unifi.DPIApps.GetApp(dpi.Cat.Int(), dpi.App.Int()),
}
fillDPIMapTotals(appTotal, labelDPI[5], s.SourceName, s.SiteName, dpi)
@ -172,14 +170,10 @@ func fillDPIMapTotals(m totalsDPImap, name, controller, site string, dpi unifi.D
}
oldDPI := m[controller][site][name]
oldDPI.TxPackets.Val += dpi.TxPackets.Val
oldDPI.TxPackets.Txt = fmt.Sprintf("%f", oldDPI.TxPackets.Val)
oldDPI.RxPackets.Val += dpi.RxPackets.Val
oldDPI.RxPackets.Txt = fmt.Sprintf("%f", oldDPI.RxPackets.Val)
oldDPI.TxBytes.Val += dpi.TxBytes.Val
oldDPI.TxBytes.Txt = fmt.Sprintf("%f", oldDPI.TxBytes.Val)
oldDPI.RxBytes.Val += dpi.RxBytes.Val
oldDPI.RxBytes.Txt = fmt.Sprintf("%f", oldDPI.RxBytes.Val)
oldDPI.TxPackets.Add(&dpi.TxPackets)
oldDPI.RxPackets.Add(&dpi.RxPackets)
oldDPI.TxBytes.Add(&dpi.TxBytes)
oldDPI.RxBytes.Add(&dpi.RxBytes)
m[controller][site][name] = oldDPI
}

View File

@ -83,7 +83,7 @@ func (u *promUnifi) exportSiteDPI(r report, v any) {
}
for _, dpi := range s.ByApp {
labelDPI := []string{unifi.DPICats.Get(int(dpi.Cat.Val)), unifi.DPIApps.GetApp(int(dpi.Cat.Val), int(dpi.App.Val)), s.SiteName, s.SourceName}
labelDPI := []string{unifi.DPICats.Get(dpi.Cat.Int()), unifi.DPIApps.GetApp(dpi.Cat.Int(), dpi.App.Int()), s.SiteName, s.SourceName}
// log.Println(labelsDPI, dpi.Cat, dpi.App, dpi.TxBytes, dpi.RxBytes, dpi.TxPackets, dpi.RxPackets)
r.send([]*metric{