add uxg and usg temps

This commit is contained in:
David Newhall II 2021-03-14 17:44:57 -07:00
parent f473f1d4c9
commit 51abe6e9b0
6 changed files with 50 additions and 3 deletions

View File

@ -83,6 +83,7 @@ type Report struct {
USW int // Total count of USW devices.
UAP int // Total count of UAP devices.
UDM int // Total count of UDM devices.
UXG int // Total count of UXG devices.
Metrics *poller.Metrics // Metrics collected and recorded.
Elapsed time.Duration // Duration elapsed collecting and exporting.
Fetch time.Duration // Duration elapsed making controller requests.
@ -331,6 +332,9 @@ func (u *promUnifi) switchExport(r report, v interface{}) {
case *unifi.USG:
r.addUSG()
u.exportUSG(r, v)
case *unifi.UXG:
r.addUXG()
u.exportUXG(r, v)
case *unifi.UDM:
r.addUDM()
u.exportUDM(r, v)

View File

@ -6,6 +6,6 @@ require (
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/common v0.18.0
github.com/unifi-poller/poller v0.0.8
github.com/unifi-poller/unifi v0.0.7-0.20210315000917-22c6030f9df5
github.com/unifi-poller/unifi v0.0.7-0.20210315003727-a4802cb45269
github.com/unifi-poller/webserver v0.0.0-20200628212441-340749c94743
)

View File

@ -20,6 +20,7 @@ type report interface {
export(m *metric, v float64) prometheus.Metric
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
addUDM()
addUXG()
addUSG()
addUAP()
addUSW()
@ -47,7 +48,7 @@ func (r *Report) report(c poller.Logger, descs map[*prometheus.Desc]bool) {
c.Logf("UniFi Measurements Exported. Site: %d, Client: %d, "+
"UAP: %d, USG/UDM: %d, USW: %d, DPI Site/Client: %d/%d, Desc: %d, "+
"Metric: %d, Err: %d, 0s: %d, Req/Total: %v / %v",
len(m.Sites), len(m.Clients), r.UAP, r.UDM+r.USG, r.USW, len(m.SitesDPI),
len(m.Sites), len(m.Clients), r.UAP, r.UDM+r.USG+r.UXG, r.USW, len(m.SitesDPI),
len(m.ClientsDPI), len(descs), r.Total, r.Errors, r.Zeros,
r.Fetch.Round(time.Millisecond/oneDecimalPoint),
r.Elapsed.Round(time.Millisecond/oneDecimalPoint))
@ -87,6 +88,10 @@ func (r *Report) addUDM() {
r.UDM++
}
func (r *Report) addUXG() {
r.UXG++
}
// close is not part of the interface.
func (r *Report) close() {
r.wg.Wait()

View File

@ -9,7 +9,7 @@ import (
type unifiDevice struct {
Info *prometheus.Desc
Uptime *prometheus.Desc
Temperature *prometheus.Desc // sw,udmp only
Temperature *prometheus.Desc
TotalMaxPower *prometheus.Desc // sw only
FanLevel *prometheus.Desc // sw only
TotalTxBytes *prometheus.Desc

View File

@ -79,6 +79,10 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) {
labels := []string{d.Type, d.SiteName, d.Name, d.SourceName}
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID}
for _, t := range d.Temperatures {
r.send([]*metric{{u.Device.Temperature, gauge, t.Value, append(labels, t.Name, t.Type)}})
}
// Gateway System Data.
u.exportWANPorts(r, labels, d.Wan1, d.Wan2)
u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)

View File

@ -0,0 +1,34 @@
package promunifi
import (
"github.com/unifi-poller/unifi"
)
// exportUXG is a collection of stats from USG and USW. It has no unique stats.
func (u *promUnifi) exportUXG(r report, d *unifi.UXG) {
if !d.Adopted.Val || d.Locating.Val {
return
}
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)
u.exportSYSstats(r, labels, d.SysStats, d.SystemStats)
u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.NumMobile, d.NumHandheld)
// Switch Data
u.exportUSWstats(r, labels, d.Stat.Sw)
u.exportPRTtable(r, labels, d.PortTable)
// Gateway Data
u.exportWANPorts(r, labels, d.Wan1, d.Wan2)
u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink)
// Dream Machine System Data.
r.send([]*metric{
{u.Device.Info, gauge, 1.0, append(labels, infoLabels...)},
{u.Device.Uptime, gauge, d.Uptime, labels},
})
for _, t := range d.Temperatures {
r.send([]*metric{{u.Device.Temperature, gauge, t.Value, append(labels, t.Name, t.Type)}})
}
}