add ubb and uci initial support
This commit is contained in:
parent
7e3484f80e
commit
a30c82093d
6
go.mod
6
go.mod
|
|
@ -13,7 +13,7 @@ require (
|
||||||
github.com/prometheus/common v0.61.0
|
github.com/prometheus/common v0.61.0
|
||||||
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c
|
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
github.com/unpoller/unifi/v5 v5.0.4
|
github.com/unpoller/unifi/v5 v5.0.5
|
||||||
golang.org/x/crypto v0.31.0
|
golang.org/x/crypto v0.31.0
|
||||||
golang.org/x/net v0.33.0
|
golang.org/x/net v0.33.0
|
||||||
golang.org/x/term v0.27.0
|
golang.org/x/term v0.27.0
|
||||||
|
|
@ -23,8 +23,6 @@ require (
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/unpoller/unifi v0.4.3 // indirect
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||||
github.com/Microsoft/go-winio v0.6.0 // indirect
|
github.com/Microsoft/go-winio v0.6.0 // indirect
|
||||||
|
|
@ -50,4 +48,4 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
// for local iterative development only
|
// for local iterative development only
|
||||||
// replace github.com/unpoller/unifi/v5 => ../unifi
|
replace github.com/unpoller/unifi/v5 => ../unifi
|
||||||
|
|
|
||||||
6
go.sum
6
go.sum
|
|
@ -75,10 +75,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/unpoller/unifi v0.4.3 h1:MyX27nf/Nq9a+p/o5qIjNJDJSS+jvxGC7BbxDk09BRg=
|
github.com/unpoller/unifi/v5 v5.0.5 h1:4u3Dd3CrEH9t0BMCy/jjBMFN2xk67Zm3UKOT//Oq/ZQ=
|
||||||
github.com/unpoller/unifi v0.4.3/go.mod h1:TWzPB/1SVbvoweS3RcknQj3Ds+MclHzGGE2weqI+vO0=
|
github.com/unpoller/unifi/v5 v5.0.5/go.mod h1:G45KRuSH9PFrIUFmDTzWEEM/E/e7GuyXp36AVOfhm7I=
|
||||||
github.com/unpoller/unifi/v5 v5.0.4 h1:JkmNgEyAGc6Oy6siWC8nwBiu08uLB4I5dz54jRmwLOY=
|
|
||||||
github.com/unpoller/unifi/v5 v5.0.4/go.mod h1:G45KRuSH9PFrIUFmDTzWEEM/E/e7GuyXp36AVOfhm7I=
|
|
||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,10 @@ func (u *DatadogUnifi) switchExport(r report, v any) { //nolint:cyclop
|
||||||
u.batchUXG(r, v)
|
u.batchUXG(r, v)
|
||||||
case *unifi.UDM:
|
case *unifi.UDM:
|
||||||
u.batchUDM(r, v)
|
u.batchUDM(r, v)
|
||||||
|
case *unifi.UBB:
|
||||||
|
u.batchUBB(r, v)
|
||||||
|
case *unifi.UCI:
|
||||||
|
u.batchUCI(r, v)
|
||||||
case *unifi.Site:
|
case *unifi.Site:
|
||||||
u.reportSite(r, v)
|
u.reportSite(r, v)
|
||||||
case *unifi.Client:
|
case *unifi.Client:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
package datadogunifi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/unpoller/unifi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ubbT is used as a name for printed/logged counters.
|
||||||
|
const ubbT = item("UBB")
|
||||||
|
|
||||||
|
// batchUBB generates UBB datapoints for Datadog.
|
||||||
|
// These points can be passed directly to datadog.
|
||||||
|
func (u *DatadogUnifi) batchUBB(r report, s *unifi.UBB) { // nolint: funlen
|
||||||
|
if !s.Adopted.Val || s.Locating.Val {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tags := cleanTags(map[string]string{
|
||||||
|
"source": s.SourceName,
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
"ip": s.IP,
|
||||||
|
"license_state": s.LicenseState,
|
||||||
|
})
|
||||||
|
|
||||||
|
var sw *unifi.Bb
|
||||||
|
if s.Stat != nil {
|
||||||
|
sw = s.Stat.Bb
|
||||||
|
}
|
||||||
|
|
||||||
|
sysStats := unifi.SysStats{}
|
||||||
|
if s.SysStats != nil {
|
||||||
|
sysStats = *s.SysStats
|
||||||
|
}
|
||||||
|
systemStats := unifi.SystemStats{}
|
||||||
|
if s.SystemStats != nil {
|
||||||
|
systemStats = *s.SystemStats
|
||||||
|
}
|
||||||
|
|
||||||
|
data := CombineFloat64(
|
||||||
|
u.batchSysStats(sysStats, systemStats),
|
||||||
|
map[string]float64{
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
"state": s.State.Val,
|
||||||
|
"user_num_sta": s.UserNumSta.Val,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
r.addCount(ubbT)
|
||||||
|
|
||||||
|
metricName := metricNamespace("ubb")
|
||||||
|
reportGaugeForFloat64Map(r, metricName, data, tags)
|
||||||
|
|
||||||
|
tags = cleanTags(map[string]string{
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"source": s.SourceName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
"ip": s.IP,
|
||||||
|
})
|
||||||
|
data = CombineFloat64(
|
||||||
|
u.batchUBBstat(sw),
|
||||||
|
map[string]float64{
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
})
|
||||||
|
|
||||||
|
metricName = metricNamespace("usw")
|
||||||
|
reportGaugeForFloat64Map(r, metricName, data, tags)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *DatadogUnifi) batchUBBstat(sw *unifi.Bb) map[string]float64 {
|
||||||
|
if sw == nil {
|
||||||
|
return map[string]float64{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string]float64{
|
||||||
|
"stat_bytes": sw.Bytes.Val,
|
||||||
|
"stat_rx_bytes": sw.RxBytes.Val,
|
||||||
|
"stat_rx_crypts": sw.RxCrypts.Val,
|
||||||
|
"stat_rx_dropped": sw.RxDropped.Val,
|
||||||
|
"stat_rx_errors": sw.RxErrors.Val,
|
||||||
|
"stat_rx_frags": sw.RxFrags.Val,
|
||||||
|
"stat_rx_packets": sw.TxPackets.Val,
|
||||||
|
"stat_tx_bytes": sw.TxBytes.Val,
|
||||||
|
"stat_tx_dropped": sw.TxDropped.Val,
|
||||||
|
"stat_tx_errors": sw.TxErrors.Val,
|
||||||
|
"stat_tx_packets": sw.TxPackets.Val,
|
||||||
|
"stat_tx_retries": sw.TxRetries.Val,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package datadogunifi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/unpoller/unifi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// uciT is used as a name for printed/logged counters.
|
||||||
|
const uciT = item("UCI")
|
||||||
|
|
||||||
|
// batchUCI generates UCI datapoints for Datadog.
|
||||||
|
// These points can be passed directly to datadog.
|
||||||
|
func (u *DatadogUnifi) batchUCI(r report, s *unifi.UCI) { // nolint: funlen
|
||||||
|
if !s.Adopted.Val || s.Locating.Val {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tags := cleanTags(map[string]string{
|
||||||
|
"source": s.SourceName,
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
"ip": s.IP,
|
||||||
|
"license_state": s.LicenseState,
|
||||||
|
})
|
||||||
|
|
||||||
|
var sw *unifi.Sw
|
||||||
|
if s.Stat != nil {
|
||||||
|
sw = s.Stat.Sw
|
||||||
|
}
|
||||||
|
|
||||||
|
sysStats := unifi.SysStats{}
|
||||||
|
if s.SysStats != nil {
|
||||||
|
sysStats = *s.SysStats
|
||||||
|
}
|
||||||
|
systemStats := unifi.SystemStats{}
|
||||||
|
if s.SystemStats != nil {
|
||||||
|
systemStats = *s.SystemStats
|
||||||
|
}
|
||||||
|
|
||||||
|
data := CombineFloat64(
|
||||||
|
u.batchSysStats(sysStats, systemStats),
|
||||||
|
map[string]float64{
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
"state": s.State.Val,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
r.addCount(uxgT)
|
||||||
|
|
||||||
|
metricName := metricNamespace("usg")
|
||||||
|
reportGaugeForFloat64Map(r, metricName, data, tags)
|
||||||
|
|
||||||
|
tags = cleanTags(map[string]string{
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"source": s.SourceName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
"ip": s.IP,
|
||||||
|
})
|
||||||
|
data = CombineFloat64(
|
||||||
|
u.batchUSWstat(sw),
|
||||||
|
map[string]float64{
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
})
|
||||||
|
|
||||||
|
metricName = metricNamespace("usw")
|
||||||
|
reportGaugeForFloat64Map(r, metricName, data, tags)
|
||||||
|
}
|
||||||
|
|
@ -443,6 +443,10 @@ func (u *InfluxUnifi) switchExport(r report, v any) { //nolint:cyclop
|
||||||
u.batchUSG(r, v)
|
u.batchUSG(r, v)
|
||||||
case *unifi.UXG:
|
case *unifi.UXG:
|
||||||
u.batchUXG(r, v)
|
u.batchUXG(r, v)
|
||||||
|
case *unifi.UBB:
|
||||||
|
u.batchUBB(r, v)
|
||||||
|
case *unifi.UCI:
|
||||||
|
u.batchUCI(r, v)
|
||||||
case *unifi.UDM:
|
case *unifi.UDM:
|
||||||
u.batchUDM(r, v)
|
u.batchUDM(r, v)
|
||||||
case *unifi.Site:
|
case *unifi.Site:
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ func (r *Report) String() string {
|
||||||
"Gateways: %d, %s: %d, %s: %d, %s/%s/%s/%s: %d/%d/%d/%d, "+
|
"Gateways: %d, %s: %d, %s: %d, %s/%s/%s/%s: %d/%d/%d/%d, "+
|
||||||
"DPI Site/Client: %d/%d, %s: %d, %s: %d, Err: %d, Dur: %v",
|
"DPI Site/Client: %d/%d, %s: %d, %s: %d, Err: %d, Dur: %v",
|
||||||
len(m.Sites), len(m.Clients),
|
len(m.Sites), len(m.Clients),
|
||||||
c[udmT]+c[usgT]+c[uxgT], uapT, c[uapT], uswT, c[uswT],
|
c[udmT]+c[usgT]+c[uxgT]+c[uciT]+c[ubbT], uapT, c[uapT], uswT, c[uswT],
|
||||||
idsT, eventT, alarmT, anomalyT, c[idsT], c[eventT], c[alarmT], c[anomalyT],
|
idsT, eventT, alarmT, anomalyT, c[idsT], c[eventT], c[alarmT], c[anomalyT],
|
||||||
len(m.SitesDPI), len(m.ClientsDPI), pointT, c[pointT], fieldT, c[fieldT],
|
len(m.SitesDPI), len(m.ClientsDPI), pointT, c[pointT], fieldT, c[fieldT],
|
||||||
len(r.Errors), r.Elapsed.Round(time.Millisecond))
|
len(r.Errors), r.Elapsed.Round(time.Millisecond))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package influxunifi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/unpoller/unifi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ubbT is used as a name for printed/logged counters.
|
||||||
|
const ubbT = item("UBB")
|
||||||
|
|
||||||
|
// batchUXG generates UBB datapoints for InfluxDB.
|
||||||
|
// These points can be passed directly to influx.
|
||||||
|
func (u *InfluxUnifi) batchUBB(r report, s *unifi.UBB) { // nolint: funlen
|
||||||
|
if !s.Adopted.Val || s.Locating.Val {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tags := map[string]string{
|
||||||
|
"source": s.SourceName,
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
}
|
||||||
|
var sw *unifi.Bb
|
||||||
|
if s.Stat != nil {
|
||||||
|
sw = s.Stat.Bb
|
||||||
|
}
|
||||||
|
|
||||||
|
sysStats := unifi.SysStats{}
|
||||||
|
if s.SysStats != nil {
|
||||||
|
sysStats = *s.SysStats
|
||||||
|
}
|
||||||
|
systemStats := unifi.SystemStats{}
|
||||||
|
if s.SystemStats != nil {
|
||||||
|
systemStats = *s.SystemStats
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := Combine(
|
||||||
|
u.batchSysStats(sysStats, systemStats),
|
||||||
|
map[string]any{
|
||||||
|
"source": s.SourceName,
|
||||||
|
"ip": s.IP,
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"license_state": s.LicenseState,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
"state": s.State.Val,
|
||||||
|
"user-num_sta": s.UserNumSta.Val,
|
||||||
|
"version": s.Version,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
r.addCount(ubbT)
|
||||||
|
r.send(&metric{Table: "usg", Tags: tags, Fields: fields})
|
||||||
|
|
||||||
|
tags = map[string]string{
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"source": s.SourceName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
}
|
||||||
|
fields = Combine(
|
||||||
|
u.batchUBBstat(sw),
|
||||||
|
map[string]any{
|
||||||
|
"ip": s.IP,
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
})
|
||||||
|
|
||||||
|
r.send(&metric{Table: "ubb", Tags: tags, Fields: fields})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *InfluxUnifi) batchUBBstat(sw *unifi.Bb) map[string]any {
|
||||||
|
if sw == nil {
|
||||||
|
return map[string]any{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string]any{
|
||||||
|
"stat_bytes": sw.Bytes.Val,
|
||||||
|
"stat_rx_bytes": sw.RxBytes.Val,
|
||||||
|
"stat_rx_crypts": sw.RxCrypts.Val,
|
||||||
|
"stat_rx_dropped": sw.RxDropped.Val,
|
||||||
|
"stat_rx_errors": sw.RxErrors.Val,
|
||||||
|
"stat_rx_frags": sw.RxFrags.Val,
|
||||||
|
"stat_rx_packets": sw.TxPackets.Val,
|
||||||
|
"stat_tx_bytes": sw.TxBytes.Val,
|
||||||
|
"stat_tx_dropped": sw.TxDropped.Val,
|
||||||
|
"stat_tx_errors": sw.TxErrors.Val,
|
||||||
|
"stat_tx_packets": sw.TxPackets.Val,
|
||||||
|
"stat_tx_retries": sw.TxRetries.Val,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
package influxunifi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/unpoller/unifi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// uciT is used as a name for printed/logged counters.
|
||||||
|
const uciT = item("UCI")
|
||||||
|
|
||||||
|
// batchUCI generates UCI datapoints for InfluxDB.
|
||||||
|
// These points can be passed directly to influx.
|
||||||
|
func (u *InfluxUnifi) batchUCI(r report, s *unifi.UCI) { // nolint: funlen
|
||||||
|
if !s.Adopted.Val || s.Locating.Val {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tags := map[string]string{
|
||||||
|
"source": s.SourceName,
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
var sw *unifi.Sw
|
||||||
|
if s.Stat != nil {
|
||||||
|
sw = s.Stat.Sw
|
||||||
|
}
|
||||||
|
|
||||||
|
sysStats := unifi.SysStats{}
|
||||||
|
if s.SysStats != nil {
|
||||||
|
sysStats = *s.SysStats
|
||||||
|
}
|
||||||
|
systemStats := unifi.SystemStats{}
|
||||||
|
if s.SystemStats != nil {
|
||||||
|
systemStats = *s.SystemStats
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := Combine(
|
||||||
|
u.batchSysStats(sysStats, systemStats),
|
||||||
|
map[string]any{
|
||||||
|
"source": s.SourceName,
|
||||||
|
"ip": s.IP,
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"license_state": s.LicenseState,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
"state": s.State.Val,
|
||||||
|
"version": s.Version,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
r.addCount(uciT)
|
||||||
|
r.send(&metric{Table: "usg", Tags: tags, Fields: fields})
|
||||||
|
|
||||||
|
tags = map[string]string{
|
||||||
|
"mac": s.Mac,
|
||||||
|
"site_name": s.SiteName,
|
||||||
|
"source": s.SourceName,
|
||||||
|
"name": s.Name,
|
||||||
|
"version": s.Version,
|
||||||
|
"model": s.Model,
|
||||||
|
"serial": s.Serial,
|
||||||
|
"type": s.Type,
|
||||||
|
}
|
||||||
|
fields = Combine(
|
||||||
|
u.batchUSWstat(sw),
|
||||||
|
map[string]any{
|
||||||
|
"ip": s.IP,
|
||||||
|
"bytes": s.Bytes.Val,
|
||||||
|
"last_seen": s.LastSeen.Val,
|
||||||
|
"rx_bytes": s.RxBytes.Val,
|
||||||
|
"tx_bytes": s.TxBytes.Val,
|
||||||
|
"uptime": s.Uptime.Val,
|
||||||
|
})
|
||||||
|
|
||||||
|
r.send(&metric{Table: "usw", Tags: tags, Fields: fields})
|
||||||
|
}
|
||||||
|
|
@ -218,6 +218,16 @@ func extractDevices(metrics *Metrics) (*poller.Metrics, map[string]string, map[s
|
||||||
m.Devices = append(m.Devices, r)
|
m.Devices = append(m.Devices, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, r := range metrics.Devices.UBBs {
|
||||||
|
devices[r.Mac] = r.Name
|
||||||
|
m.Devices = append(m.Devices, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range metrics.Devices.UCIs {
|
||||||
|
devices[r.Mac] = r.Name
|
||||||
|
m.Devices = append(m.Devices, r)
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range metrics.Devices.PDUs {
|
for _, r := range metrics.Devices.PDUs {
|
||||||
devices[r.Mac] = r.Name
|
devices[r.Mac] = r.Name
|
||||||
m.Devices = append(m.Devices, r)
|
m.Devices = append(m.Devices, r)
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ type Report struct {
|
||||||
UAP int // Total count of UAP devices.
|
UAP int // Total count of UAP devices.
|
||||||
UDM int // Total count of UDM devices.
|
UDM int // Total count of UDM devices.
|
||||||
UXG int // Total count of UXG devices.
|
UXG int // Total count of UXG devices.
|
||||||
|
UBB int // Total count of UBB devices.
|
||||||
|
UCI int // Total count of UCI devices.
|
||||||
Metrics *poller.Metrics // Metrics collected and recorded.
|
Metrics *poller.Metrics // Metrics collected and recorded.
|
||||||
Elapsed time.Duration // Duration elapsed collecting and exporting.
|
Elapsed time.Duration // Duration elapsed collecting and exporting.
|
||||||
Fetch time.Duration // Duration elapsed making controller requests.
|
Fetch time.Duration // Duration elapsed making controller requests.
|
||||||
|
|
@ -412,6 +414,12 @@ func (u *promUnifi) switchExport(r report, v any) {
|
||||||
case *unifi.UXG:
|
case *unifi.UXG:
|
||||||
r.addUXG()
|
r.addUXG()
|
||||||
u.exportUXG(r, v)
|
u.exportUXG(r, v)
|
||||||
|
case *unifi.UBB:
|
||||||
|
r.addUBB()
|
||||||
|
u.exportUBB(r, v)
|
||||||
|
case *unifi.UCI:
|
||||||
|
r.addUCI()
|
||||||
|
u.exportUCI(r, v)
|
||||||
case *unifi.UDM:
|
case *unifi.UDM:
|
||||||
r.addUDM()
|
r.addUDM()
|
||||||
u.exportUDM(r, v)
|
u.exportUDM(r, v)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ type report interface {
|
||||||
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v any)
|
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v any)
|
||||||
addUDM()
|
addUDM()
|
||||||
addUXG()
|
addUXG()
|
||||||
|
addUBB()
|
||||||
|
addUCI()
|
||||||
addUSG()
|
addUSG()
|
||||||
addUAP()
|
addUAP()
|
||||||
addUSW()
|
addUSW()
|
||||||
|
|
@ -97,6 +99,14 @@ func (r *Report) addUXG() {
|
||||||
r.UXG++
|
r.UXG++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Report) addUBB() {
|
||||||
|
r.UCI++
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Report) addUCI() {
|
||||||
|
r.UCI++
|
||||||
|
}
|
||||||
|
|
||||||
// close is not part of the interface.
|
// close is not part of the interface.
|
||||||
func (r *Report) close() {
|
func (r *Report) close() {
|
||||||
r.wg.Wait()
|
r.wg.Wait()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package promunifi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/unpoller/unifi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// exportUBB is a collection of stats from UBB.
|
||||||
|
func (u *promUnifi) exportUBB(r report, d *unifi.UBB) {
|
||||||
|
if !d.Adopted.Val || d.Locating.Val {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//var sw *unifi.Bb
|
||||||
|
//if d.Stat != nil {
|
||||||
|
// sw = d.Stat.Bb
|
||||||
|
//}
|
||||||
|
// unsure of what to do with this yet.
|
||||||
|
|
||||||
|
labels := []string{d.Type, d.SiteName, d.Name, d.SourceName}
|
||||||
|
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID}
|
||||||
|
// Shared data (all devices do this).
|
||||||
|
u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)
|
||||||
|
if d.SysStats != nil && d.SystemStats != nil {
|
||||||
|
u.exportSYSstats(r, labels, *d.SysStats, *d.SystemStats)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dream Machine System Data.
|
||||||
|
r.send([]*metric{
|
||||||
|
{u.Device.Info, gauge, 1.0, append(labels, infoLabels...)},
|
||||||
|
{u.Device.Uptime, gauge, d.Uptime, labels},
|
||||||
|
})
|
||||||
|
|
||||||
|
// temperature
|
||||||
|
r.send([]*metric{{u.Device.Temperature, gauge, d.GeneralTemperature.Val, append(labels, d.Name, "general")}})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package promunifi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/unpoller/unifi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// exportUCI is a collection of stats from UCI.
|
||||||
|
func (u *promUnifi) exportUCI(r report, d *unifi.UCI) {
|
||||||
|
if !d.Adopted.Val || d.Locating.Val {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var sw *unifi.Sw
|
||||||
|
if d.Stat != nil {
|
||||||
|
sw = d.Stat.Sw
|
||||||
|
}
|
||||||
|
|
||||||
|
labels := []string{d.Type, d.SiteName, d.Name, d.SourceName}
|
||||||
|
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID}
|
||||||
|
// Shared data (all devices do this).
|
||||||
|
u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)
|
||||||
|
if d.SysStats != nil && d.SystemStats != nil {
|
||||||
|
u.exportSYSstats(r, labels, *d.SysStats, *d.SystemStats)
|
||||||
|
}
|
||||||
|
// Switch Data
|
||||||
|
u.exportUSWstats(r, labels, sw)
|
||||||
|
// Dream Machine System Data.
|
||||||
|
r.send([]*metric{
|
||||||
|
{u.Device.Info, gauge, 1.0, append(labels, infoLabels...)},
|
||||||
|
{u.Device.Uptime, gauge, d.Uptime, labels},
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue