add ubb and uci initial support

This commit is contained in:
Cody Lee
2024-12-31 16:26:54 -06:00
parent 7e3484f80e
commit a30c82093d
14 changed files with 486 additions and 9 deletions

View File

@@ -92,6 +92,8 @@ type Report struct {
UAP int // Total count of UAP devices.
UDM int // Total count of UDM 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.
Elapsed time.Duration // Duration elapsed collecting and exporting.
Fetch time.Duration // Duration elapsed making controller requests.
@@ -412,6 +414,12 @@ func (u *promUnifi) switchExport(r report, v any) {
case *unifi.UXG:
r.addUXG()
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:
r.addUDM()
u.exportUDM(r, v)

View File

@@ -21,6 +21,8 @@ type report interface {
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v any)
addUDM()
addUXG()
addUBB()
addUCI()
addUSG()
addUAP()
addUSW()
@@ -97,6 +99,14 @@ func (r *Report) addUXG() {
r.UXG++
}
func (r *Report) addUBB() {
r.UCI++
}
func (r *Report) addUCI() {
r.UCI++
}
// close is not part of the interface.
func (r *Report) close() {
r.wg.Wait()

35
pkg/promunifi/ubb.go Normal file
View File

@@ -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")}})
}

32
pkg/promunifi/uci.go Normal file
View File

@@ -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},
})
}