From 51abe6e9b0ae17b855ad3779fcfe1be68943dcad Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sun, 14 Mar 2021 17:44:57 -0700 Subject: [PATCH] add uxg and usg temps --- integrations/promunifi/collector.go | 4 ++++ integrations/promunifi/go.mod | 2 +- integrations/promunifi/report.go | 7 +++++- integrations/promunifi/udm.go | 2 +- integrations/promunifi/usg.go | 4 ++++ integrations/promunifi/uxg.go | 34 +++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 integrations/promunifi/uxg.go diff --git a/integrations/promunifi/collector.go b/integrations/promunifi/collector.go index ed0d2106..f51219ef 100644 --- a/integrations/promunifi/collector.go +++ b/integrations/promunifi/collector.go @@ -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) diff --git a/integrations/promunifi/go.mod b/integrations/promunifi/go.mod index 43369433..a237c6c4 100644 --- a/integrations/promunifi/go.mod +++ b/integrations/promunifi/go.mod @@ -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 ) diff --git a/integrations/promunifi/report.go b/integrations/promunifi/report.go index 76d795b1..7bbd9887 100644 --- a/integrations/promunifi/report.go +++ b/integrations/promunifi/report.go @@ -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() diff --git a/integrations/promunifi/udm.go b/integrations/promunifi/udm.go index dce948fd..5acb4e03 100644 --- a/integrations/promunifi/udm.go +++ b/integrations/promunifi/udm.go @@ -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 diff --git a/integrations/promunifi/usg.go b/integrations/promunifi/usg.go index 7c94deb5..0d508bbd 100644 --- a/integrations/promunifi/usg.go +++ b/integrations/promunifi/usg.go @@ -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) diff --git a/integrations/promunifi/uxg.go b/integrations/promunifi/uxg.go new file mode 100644 index 00000000..defe5f03 --- /dev/null +++ b/integrations/promunifi/uxg.go @@ -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)}}) + } +}