move pieces into methods

This commit is contained in:
davidnewhall2 2019-12-03 00:19:47 -08:00
parent 0157ed9196
commit 4d485769d6
9 changed files with 327 additions and 357 deletions

View File

@ -101,10 +101,7 @@ func (u *UnifiPoller) AugmentMetrics(metrics *metrics.Metrics) {
for _, r := range metrics.USWs {
devices[r.Mac] = r.Name
}
for i, r := range metrics.UDMs {
if r.Model == "UDMPRO" {
metrics.UDMs[i].Type = "udmp"
}
for _, r := range metrics.UDMs {
devices[r.Mac] = r.Name
}
// These come blank, so set them here.

View File

@ -24,7 +24,7 @@ type uclient struct {
TxRetries *prometheus.Desc
TxPower *prometheus.Desc
TxRate *prometheus.Desc
Uptime *prometheus.Desc
Info *prometheus.Desc
WifiTxAttempts *prometheus.Desc
WiredRxBytes *prometheus.Desc
WiredRxBytesR *prometheus.Desc
@ -63,7 +63,7 @@ func descClient(ns string) *uclient {
TxPower: prometheus.NewDesc(ns+"radio_transmit_power_dbm", "Client Transmit Power", labelW, nil),
TxRate: prometheus.NewDesc(ns+"radio_transmit_rate_bps", "Client Transmit Rate", labelW, nil),
WifiTxAttempts: prometheus.NewDesc(ns+"wifi_attempts_transmit_total", "Client Wifi Transmit Attempts", labelW, nil),
Uptime: prometheus.NewDesc(ns+"uptime_seconds", "Client Uptime", labelW, nil),
Info: prometheus.NewDesc(ns+"uptime_seconds", "Client Uptime", labelW, nil), // XXX: re-purpose for info tags.
/* needs more "looking into"
DpiStatsApp: prometheus.NewDesc(ns+"dpi_stats_app", "Client DPI Stats App", labels, nil),
DpiStatsCat: prometheus.NewDesc(ns+"dpi_stats_cat", "Client DPI Stats Cat", labels, nil),
@ -83,47 +83,45 @@ func (u *promUnifi) exportClient(r report, c *unifi.Client) {
labels[len(labels)-1] = "true"
labelW[len(labelW)-1] = "true"
r.send([]*metric{
{u.Client.RxBytes, prometheus.CounterValue, c.WiredRxBytes, labels},
{u.Client.RxBytesR, prometheus.GaugeValue, c.WiredRxBytesR, labels},
{u.Client.RxPackets, prometheus.CounterValue, c.WiredRxPackets, labels},
{u.Client.TxBytes, prometheus.CounterValue, c.WiredTxBytes, labels},
{u.Client.TxBytesR, prometheus.GaugeValue, c.WiredTxBytesR, labels},
{u.Client.TxPackets, prometheus.CounterValue, c.WiredTxPackets, labels},
{u.Client.RxBytes, counter, c.WiredRxBytes, labels},
{u.Client.RxBytesR, gauge, c.WiredRxBytesR, labels},
{u.Client.RxPackets, counter, c.WiredRxPackets, labels},
{u.Client.TxBytes, counter, c.WiredTxBytes, labels},
{u.Client.TxBytesR, gauge, c.WiredTxBytesR, labels},
{u.Client.TxPackets, counter, c.WiredTxPackets, labels},
})
} else {
labels[len(labels)-1] = "false"
labelW[len(labelW)-1] = "false"
r.send([]*metric{
{u.Client.Anomalies, prometheus.CounterValue, c.Anomalies, labelW},
{u.Client.CCQ, prometheus.GaugeValue, float64(c.Ccq) / 1000.0, labelW},
{u.Client.Satisfaction, prometheus.GaugeValue, c.Satisfaction.Val / 100.0, labelW},
{u.Client.Noise, prometheus.GaugeValue, c.Noise, labelW},
{u.Client.RoamCount, prometheus.CounterValue, c.RoamCount, labelW},
{u.Client.RSSI, prometheus.GaugeValue, c.Rssi, labelW},
{u.Client.Signal, prometheus.GaugeValue, c.Signal, labelW},
{u.Client.TxPower, prometheus.GaugeValue, c.TxPower, labelW},
{u.Client.TxRate, prometheus.GaugeValue, c.TxRate * 1000, labelW},
{u.Client.WifiTxAttempts, prometheus.CounterValue, c.WifiTxAttempts, labelW},
{u.Client.RxRate, prometheus.GaugeValue, c.RxRate * 1000, labelW},
{u.Client.TxRetries, prometheus.CounterValue, c.TxRetries, labels},
{u.Client.TxBytes, prometheus.CounterValue, c.TxBytes, labels},
{u.Client.TxBytesR, prometheus.GaugeValue, c.TxBytesR, labels},
{u.Client.TxPackets, prometheus.CounterValue, c.TxPackets, labels},
{u.Client.RxBytes, prometheus.CounterValue, c.RxBytes, labels},
{u.Client.RxBytesR, prometheus.GaugeValue, c.RxBytesR, labels},
{u.Client.RxPackets, prometheus.CounterValue, c.RxPackets, labels},
{u.Client.BytesR, prometheus.GaugeValue, c.BytesR, labelW},
{u.Client.Anomalies, counter, c.Anomalies, labelW},
{u.Client.CCQ, gauge, float64(c.Ccq) / 1000.0, labelW},
{u.Client.Satisfaction, gauge, c.Satisfaction.Val / 100.0, labelW},
{u.Client.Noise, gauge, c.Noise, labelW},
{u.Client.RoamCount, counter, c.RoamCount, labelW},
{u.Client.RSSI, gauge, c.Rssi, labelW},
{u.Client.Signal, gauge, c.Signal, labelW},
{u.Client.TxPower, gauge, c.TxPower, labelW},
{u.Client.TxRate, gauge, c.TxRate * 1000, labelW},
{u.Client.WifiTxAttempts, counter, c.WifiTxAttempts, labelW},
{u.Client.RxRate, gauge, c.RxRate * 1000, labelW},
{u.Client.TxRetries, counter, c.TxRetries, labels},
{u.Client.TxBytes, counter, c.TxBytes, labels},
{u.Client.TxBytesR, gauge, c.TxBytesR, labels},
{u.Client.TxPackets, counter, c.TxPackets, labels},
{u.Client.RxBytes, counter, c.RxBytes, labels},
{u.Client.RxBytesR, gauge, c.RxBytesR, labels},
{u.Client.RxPackets, counter, c.RxPackets, labels},
{u.Client.BytesR, gauge, c.BytesR, labelW},
})
}
r.send([]*metric{
{u.Client.Uptime, prometheus.GaugeValue, c.Uptime, labelW},
/* needs more "looking into"
{u.Client.DpiStatsApp, prometheus.GaugeValue, c.DpiStats.App, labels},
{u.Client.DpiStatsCat, prometheus.GaugeValue, c.DpiStats.Cat, labels},
{u.Client.DpiStatsRxBytes, prometheus.CounterValue, c.DpiStats.RxBytes, labels},
{u.Client.DpiStatsRxPackets, prometheus.CounterValue, c.DpiStats.RxPackets, labels},
{u.Client.DpiStatsTxBytes, prometheus.CounterValue, c.DpiStats.TxBytes, labels},
{u.Client.DpiStatsTxPackets, prometheus.CounterValue, c.DpiStats.TxPackets, labels},
*/
})
r.sendone(u.Client.Info, gauge, c.Uptime, labelW)
/* needs more "looking into"
{u.Client.DpiStatsApp, gauge, c.DpiStats.App, labels},
{u.Client.DpiStatsCat, gauge, c.DpiStats.Cat, labels},
{u.Client.DpiStatsRxBytes, counter, c.DpiStats.RxBytes, labels},
{u.Client.DpiStatsRxPackets, counter, c.DpiStats.RxPackets, labels},
{u.Client.DpiStatsTxBytes, counter, c.DpiStats.TxBytes, labels},
{u.Client.DpiStatsTxPackets, counter, c.DpiStats.TxPackets, labels},
*/
}

View File

@ -16,6 +16,10 @@ import (
// channel buffer, fits at least one batch.
const buffer = 50
// simply fewer letters.
const counter = prometheus.CounterValue
const gauge = prometheus.GaugeValue
// UnifiCollectorCnfg defines the data needed to collect and report UniFi Metrics.
type UnifiCollectorCnfg struct {
// If non-empty, each of the collected metrics is prefixed by the
@ -147,10 +151,11 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) {
}
func (u *promUnifi) loopExports(r report) {
m := r.metrics()
r.add()
go func() {
defer r.done()
for _, s := range r.metrics().Sites {
for _, s := range m.Sites {
u.exportSite(r, s)
}
}()
@ -158,7 +163,7 @@ func (u *promUnifi) loopExports(r report) {
r.add()
go func() {
defer r.done()
for _, d := range r.metrics().UAPs {
for _, d := range m.UAPs {
u.exportUAP(r, d)
}
}()
@ -166,7 +171,7 @@ func (u *promUnifi) loopExports(r report) {
r.add()
go func() {
defer r.done()
for _, d := range r.metrics().UDMs {
for _, d := range m.UDMs {
u.exportUDM(r, d)
}
}()
@ -174,7 +179,7 @@ func (u *promUnifi) loopExports(r report) {
r.add()
go func() {
defer r.done()
for _, d := range r.metrics().USGs {
for _, d := range m.USGs {
u.exportUSG(r, d)
}
}()
@ -182,7 +187,7 @@ func (u *promUnifi) loopExports(r report) {
r.add()
go func() {
defer r.done()
for _, d := range r.metrics().USWs {
for _, d := range m.USWs {
u.exportUSW(r, d)
}
}()
@ -190,7 +195,7 @@ func (u *promUnifi) loopExports(r report) {
r.add()
go func() {
defer r.done()
for _, c := range r.metrics().Clients {
for _, c := range m.Clients {
u.exportClient(r, c)
}
}()

View File

@ -16,6 +16,7 @@ type report interface {
add()
done()
send([]*metric)
sendone(*prometheus.Desc, prometheus.ValueType, interface{}, []string)
metrics() *metrics.Metrics
channel() chan []*metric
report(descs map[*prometheus.Desc]bool)
@ -34,6 +35,11 @@ func (r *Report) done() {
r.wg.Add(-one)
}
func (r *Report) sendone(d *prometheus.Desc, tv prometheus.ValueType, i interface{}, s []string) {
r.wg.Add(one)
r.ch <- []*metric{{d, tv, i, s}}
}
func (r *Report) send(m []*metric) {
r.wg.Add(one)
r.ch <- m

View File

@ -70,62 +70,62 @@ func (u *promUnifi) exportSite(r report, s *unifi.Site) {
switch h.Subsystem {
case "www":
r.send([]*metric{
{u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels},
{u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels},
{u.Site.Uptime, prometheus.GaugeValue, h.Uptime, labels},
{u.Site.Latency, prometheus.GaugeValue, h.Latency.Val / 1000, labels},
{u.Site.XputUp, prometheus.GaugeValue, h.XputUp, labels},
{u.Site.XputDown, prometheus.GaugeValue, h.XputDown, labels},
{u.Site.SpeedtestPing, prometheus.GaugeValue, h.SpeedtestPing, labels},
{u.Site.Drops, prometheus.CounterValue, h.Drops, labels},
{u.Site.TxBytesR, gauge, h.TxBytesR, labels},
{u.Site.RxBytesR, gauge, h.RxBytesR, labels},
{u.Site.Uptime, gauge, h.Uptime, labels},
{u.Site.Latency, gauge, h.Latency.Val / 1000, labels},
{u.Site.XputUp, gauge, h.XputUp, labels},
{u.Site.XputDown, gauge, h.XputDown, labels},
{u.Site.SpeedtestPing, gauge, h.SpeedtestPing, labels},
{u.Site.Drops, counter, h.Drops, labels},
})
case "wlan":
r.send([]*metric{
{u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels},
{u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels},
{u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, labels},
{u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, labels},
{u.Site.NumPending, prometheus.GaugeValue, h.NumPending, labels},
{u.Site.NumUser, prometheus.GaugeValue, h.NumUser, labels},
{u.Site.NumGuest, prometheus.GaugeValue, h.NumGuest, labels},
{u.Site.NumIot, prometheus.GaugeValue, h.NumIot, labels},
{u.Site.NumAp, prometheus.GaugeValue, h.NumAp, labels},
{u.Site.NumDisabled, prometheus.GaugeValue, h.NumDisabled, labels},
{u.Site.TxBytesR, gauge, h.TxBytesR, labels},
{u.Site.RxBytesR, gauge, h.RxBytesR, labels},
{u.Site.NumAdopted, gauge, h.NumAdopted, labels},
{u.Site.NumDisconnected, gauge, h.NumDisconnected, labels},
{u.Site.NumPending, gauge, h.NumPending, labels},
{u.Site.NumUser, gauge, h.NumUser, labels},
{u.Site.NumGuest, gauge, h.NumGuest, labels},
{u.Site.NumIot, gauge, h.NumIot, labels},
{u.Site.NumAp, gauge, h.NumAp, labels},
{u.Site.NumDisabled, gauge, h.NumDisabled, labels},
})
case "wan":
r.send([]*metric{
{u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels},
{u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels},
{u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, labels},
{u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, labels},
{u.Site.NumPending, prometheus.GaugeValue, h.NumPending, labels},
{u.Site.NumGw, prometheus.GaugeValue, h.NumGw, labels},
{u.Site.NumSta, prometheus.GaugeValue, h.NumSta, labels},
{u.Site.TxBytesR, gauge, h.TxBytesR, labels},
{u.Site.RxBytesR, gauge, h.RxBytesR, labels},
{u.Site.NumAdopted, gauge, h.NumAdopted, labels},
{u.Site.NumDisconnected, gauge, h.NumDisconnected, labels},
{u.Site.NumPending, gauge, h.NumPending, labels},
{u.Site.NumGw, gauge, h.NumGw, labels},
{u.Site.NumSta, gauge, h.NumSta, labels},
})
case "lan":
r.send([]*metric{
{u.Site.TxBytesR, prometheus.GaugeValue, h.TxBytesR, labels},
{u.Site.RxBytesR, prometheus.GaugeValue, h.RxBytesR, labels},
{u.Site.NumAdopted, prometheus.GaugeValue, h.NumAdopted, labels},
{u.Site.NumDisconnected, prometheus.GaugeValue, h.NumDisconnected, labels},
{u.Site.NumPending, prometheus.GaugeValue, h.NumPending, labels},
{u.Site.NumUser, prometheus.GaugeValue, h.NumUser, labels},
{u.Site.NumGuest, prometheus.GaugeValue, h.NumGuest, labels},
{u.Site.NumIot, prometheus.GaugeValue, h.NumIot, labels},
{u.Site.NumSw, prometheus.GaugeValue, h.NumSw, labels},
{u.Site.TxBytesR, gauge, h.TxBytesR, labels},
{u.Site.RxBytesR, gauge, h.RxBytesR, labels},
{u.Site.NumAdopted, gauge, h.NumAdopted, labels},
{u.Site.NumDisconnected, gauge, h.NumDisconnected, labels},
{u.Site.NumPending, gauge, h.NumPending, labels},
{u.Site.NumUser, gauge, h.NumUser, labels},
{u.Site.NumGuest, gauge, h.NumGuest, labels},
{u.Site.NumIot, gauge, h.NumIot, labels},
{u.Site.NumSw, gauge, h.NumSw, labels},
})
case "vpn":
r.send([]*metric{
{u.Site.RemoteUserNumActive, prometheus.GaugeValue, h.RemoteUserNumActive, labels},
{u.Site.RemoteUserNumInactive, prometheus.GaugeValue, h.RemoteUserNumInactive, labels},
{u.Site.RemoteUserRxBytes, prometheus.CounterValue, h.RemoteUserRxBytes, labels},
{u.Site.RemoteUserTxBytes, prometheus.CounterValue, h.RemoteUserTxBytes, labels},
{u.Site.RemoteUserRxPackets, prometheus.CounterValue, h.RemoteUserRxPackets, labels},
{u.Site.RemoteUserTxPackets, prometheus.CounterValue, h.RemoteUserTxPackets, labels},
{u.Site.RemoteUserNumActive, gauge, h.RemoteUserNumActive, labels},
{u.Site.RemoteUserNumInactive, gauge, h.RemoteUserNumInactive, labels},
{u.Site.RemoteUserRxBytes, counter, h.RemoteUserRxBytes, labels},
{u.Site.RemoteUserTxBytes, counter, h.RemoteUserTxBytes, labels},
{u.Site.RemoteUserRxPackets, counter, h.RemoteUserRxPackets, labels},
{u.Site.RemoteUserTxPackets, counter, h.RemoteUserTxPackets, labels},
})
}
}

View File

@ -161,88 +161,62 @@ func descUAP(ns string) *uap {
func (u *promUnifi) exportUAP(r report, d *unifi.UAP) {
labels := []string{d.Type, d.SiteName, d.Name}
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt}
// Wireless System Data.
r.send([]*metric{
{u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)},
{u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels},
{u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels},
{u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels},
{u.Device.BytesD, prometheus.CounterValue, d.BytesD, labels}, // not sure if these 3 Ds are counters or gauges.
{u.Device.TxBytesD, prometheus.CounterValue, d.TxBytesD, labels}, // not sure if these 3 Ds are counters or gauges.
{u.Device.RxBytesD, prometheus.CounterValue, d.RxBytesD, labels}, // not sure if these 3 Ds are counters or gauges.
{u.Device.BytesR, prometheus.GaugeValue, d.BytesR, labels},
{u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, append(labels, "user")},
{u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, append(labels, "guest")},
{u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels},
{u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels},
{u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels},
{u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels},
{u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels},
{u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels},
{u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels},
{u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels},
})
u.exportUAPstats(r, labels, d.Stat.Ap)
u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR)
u.exportVAPtable(r, labels, d.VapTable)
u.exportRadtable(r, labels, d.RadioTable, d.RadioTableStats)
u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)
u.exportSYSstats(r, labels, d.SysStats, d.SystemStats)
u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta)
u.exportRADtable(r, labels, d.RadioTable, d.RadioTableStats)
r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...))
}
func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap) {
// labelA := append([]string{"all"}, labels[2:]...)
func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap, bytes ...unifi.FlexInt) {
labelU := []string{"user", labels[1], labels[2]}
labelG := []string{"guest", labels[1], labels[2]}
if len(bytes) > 0 {
r.send([]*metric{
// ap only stuff.
{u.Device.BytesD, counter, bytes[0], labels}, // not sure if these 3 Ds are counters or gauges.
{u.Device.TxBytesD, counter, bytes[1], labels}, // not sure if these 3 Ds are counters or gauges.
{u.Device.RxBytesD, counter, bytes[2], labels}, // not sure if these 3 Ds are counters or gauges.
{u.Device.BytesR, gauge, bytes[3], labels}, // only UAP has this one, and those ^ weird.
})
}
r.send([]*metric{
/* // all
{u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.WifiTxDropped, labelA},
{u.UAP.ApRxErrors, prometheus.CounterValue, ap.RxErrors, labelA},
{u.UAP.ApRxDropped, prometheus.CounterValue, ap.RxDropped, labelA},
{u.UAP.ApRxFrags, prometheus.CounterValue, ap.RxFrags, labelA},
{u.UAP.ApRxCrypts, prometheus.CounterValue, ap.RxCrypts, labelA},
{u.UAP.ApTxPackets, prometheus.CounterValue, ap.TxPackets, labelA},
{u.UAP.ApTxBytes, prometheus.CounterValue, ap.TxBytes, labelA},
{u.UAP.ApTxErrors, prometheus.CounterValue, ap.TxErrors, labelA},
{u.UAP.ApTxDropped, prometheus.CounterValue, ap.TxDropped, labelA},
{u.UAP.ApTxRetries, prometheus.CounterValue, ap.TxRetries, labelA},
{u.UAP.ApRxPackets, prometheus.CounterValue, ap.RxPackets, labelA},
{u.UAP.ApRxBytes, prometheus.CounterValue, ap.RxBytes, labelA},
{u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.WifiTxAttempts, labelA},
{u.UAP.MacFilterRejections, prometheus.CounterValue, ap.MacFilterRejections, labelA},
*/
// user
{u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.UserWifiTxDropped, labelU},
{u.UAP.ApRxErrors, prometheus.CounterValue, ap.UserRxErrors, labelU},
{u.UAP.ApRxDropped, prometheus.CounterValue, ap.UserRxDropped, labelU},
{u.UAP.ApRxFrags, prometheus.CounterValue, ap.UserRxFrags, labelU},
{u.UAP.ApRxCrypts, prometheus.CounterValue, ap.UserRxCrypts, labelU},
{u.UAP.ApTxPackets, prometheus.CounterValue, ap.UserTxPackets, labelU},
{u.UAP.ApTxBytes, prometheus.CounterValue, ap.UserTxBytes, labelU},
{u.UAP.ApTxErrors, prometheus.CounterValue, ap.UserTxErrors, labelU},
{u.UAP.ApTxDropped, prometheus.CounterValue, ap.UserTxDropped, labelU},
{u.UAP.ApTxRetries, prometheus.CounterValue, ap.UserTxRetries, labelU},
{u.UAP.ApRxPackets, prometheus.CounterValue, ap.UserRxPackets, labelU},
{u.UAP.ApRxBytes, prometheus.CounterValue, ap.UserRxBytes, labelU},
{u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.UserWifiTxAttempts, labelU},
{u.UAP.MacFilterRejections, prometheus.CounterValue, ap.UserMacFilterRejections, labelU},
{u.UAP.ApWifiTxDropped, counter, ap.UserWifiTxDropped, labelU},
{u.UAP.ApRxErrors, counter, ap.UserRxErrors, labelU},
{u.UAP.ApRxDropped, counter, ap.UserRxDropped, labelU},
{u.UAP.ApRxFrags, counter, ap.UserRxFrags, labelU},
{u.UAP.ApRxCrypts, counter, ap.UserRxCrypts, labelU},
{u.UAP.ApTxPackets, counter, ap.UserTxPackets, labelU},
{u.UAP.ApTxBytes, counter, ap.UserTxBytes, labelU},
{u.UAP.ApTxErrors, counter, ap.UserTxErrors, labelU},
{u.UAP.ApTxDropped, counter, ap.UserTxDropped, labelU},
{u.UAP.ApTxRetries, counter, ap.UserTxRetries, labelU},
{u.UAP.ApRxPackets, counter, ap.UserRxPackets, labelU},
{u.UAP.ApRxBytes, counter, ap.UserRxBytes, labelU},
{u.UAP.WifiTxAttempts, counter, ap.UserWifiTxAttempts, labelU},
{u.UAP.MacFilterRejections, counter, ap.UserMacFilterRejections, labelU},
// guest
{u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.GuestWifiTxDropped, labelG},
{u.UAP.ApRxErrors, prometheus.CounterValue, ap.GuestRxErrors, labelG},
{u.UAP.ApRxDropped, prometheus.CounterValue, ap.GuestRxDropped, labelG},
{u.UAP.ApRxFrags, prometheus.CounterValue, ap.GuestRxFrags, labelG},
{u.UAP.ApRxCrypts, prometheus.CounterValue, ap.GuestRxCrypts, labelG},
{u.UAP.ApTxPackets, prometheus.CounterValue, ap.GuestTxPackets, labelG},
{u.UAP.ApTxBytes, prometheus.CounterValue, ap.GuestTxBytes, labelG},
{u.UAP.ApTxErrors, prometheus.CounterValue, ap.GuestTxErrors, labelG},
{u.UAP.ApTxDropped, prometheus.CounterValue, ap.GuestTxDropped, labelG},
{u.UAP.ApTxRetries, prometheus.CounterValue, ap.GuestTxRetries, labelG},
{u.UAP.ApRxPackets, prometheus.CounterValue, ap.GuestRxPackets, labelG},
{u.UAP.ApRxBytes, prometheus.CounterValue, ap.GuestRxBytes, labelG},
{u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.GuestWifiTxAttempts, labelG},
{u.UAP.MacFilterRejections, prometheus.CounterValue, ap.GuestMacFilterRejections, labelG},
{u.UAP.ApWifiTxDropped, counter, ap.GuestWifiTxDropped, labelG},
{u.UAP.ApRxErrors, counter, ap.GuestRxErrors, labelG},
{u.UAP.ApRxDropped, counter, ap.GuestRxDropped, labelG},
{u.UAP.ApRxFrags, counter, ap.GuestRxFrags, labelG},
{u.UAP.ApRxCrypts, counter, ap.GuestRxCrypts, labelG},
{u.UAP.ApTxPackets, counter, ap.GuestTxPackets, labelG},
{u.UAP.ApTxBytes, counter, ap.GuestTxBytes, labelG},
{u.UAP.ApTxErrors, counter, ap.GuestTxErrors, labelG},
{u.UAP.ApTxDropped, counter, ap.GuestTxDropped, labelG},
{u.UAP.ApTxRetries, counter, ap.GuestTxRetries, labelG},
{u.UAP.ApRxPackets, counter, ap.GuestRxPackets, labelG},
{u.UAP.ApRxBytes, counter, ap.GuestRxBytes, labelG},
{u.UAP.WifiTxAttempts, counter, ap.GuestWifiTxAttempts, labelG},
{u.UAP.MacFilterRejections, counter, ap.GuestMacFilterRejections, labelG},
})
}
// UAP VAP Table
func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) {
// vap table stats
for _, v := range vt {
@ -252,60 +226,61 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable)
labelV := []string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage, labels[1], labels[2]}
r.send([]*metric{
{u.UAP.VAPCcq, prometheus.GaugeValue, float64(v.Ccq) / 1000.0, labelV},
{u.UAP.VAPMacFilterRejections, prometheus.CounterValue, v.MacFilterRejections, labelV},
{u.UAP.VAPNumSatisfactionSta, prometheus.GaugeValue, v.NumSatisfactionSta, labelV},
{u.UAP.VAPAvgClientSignal, prometheus.GaugeValue, v.AvgClientSignal.Val, labelV},
{u.UAP.VAPSatisfaction, prometheus.GaugeValue, v.Satisfaction.Val / 100.0, labelV},
{u.UAP.VAPSatisfactionNow, prometheus.GaugeValue, v.SatisfactionNow.Val / 100.0, labelV},
{u.UAP.VAPDNSAvgLatency, prometheus.GaugeValue, v.DNSAvgLatency.Val / 1000, labelV},
{u.UAP.VAPRxBytes, prometheus.CounterValue, v.RxBytes, labelV},
{u.UAP.VAPRxCrypts, prometheus.CounterValue, v.RxCrypts, labelV},
{u.UAP.VAPRxDropped, prometheus.CounterValue, v.RxDropped, labelV},
{u.UAP.VAPRxErrors, prometheus.CounterValue, v.RxErrors, labelV},
{u.UAP.VAPRxFrags, prometheus.CounterValue, v.RxFrags, labelV},
{u.UAP.VAPRxNwids, prometheus.CounterValue, v.RxNwids, labelV},
{u.UAP.VAPRxPackets, prometheus.CounterValue, v.RxPackets, labelV},
{u.UAP.VAPTxBytes, prometheus.CounterValue, v.TxBytes, labelV},
{u.UAP.VAPTxDropped, prometheus.CounterValue, v.TxDropped, labelV},
{u.UAP.VAPTxErrors, prometheus.CounterValue, v.TxErrors, labelV},
{u.UAP.VAPTxPackets, prometheus.CounterValue, v.TxPackets, labelV},
{u.UAP.VAPTxPower, prometheus.GaugeValue, v.TxPower, labelV},
{u.UAP.VAPTxRetries, prometheus.CounterValue, v.TxRetries, labelV},
{u.UAP.VAPTxCombinedRetries, prometheus.CounterValue, v.TxCombinedRetries, labelV},
{u.UAP.VAPTxDataMpduBytes, prometheus.CounterValue, v.TxDataMpduBytes, labelV},
{u.UAP.VAPTxRtsRetries, prometheus.CounterValue, v.TxRtsRetries, labelV},
{u.UAP.VAPTxTotal, prometheus.CounterValue, v.TxTotal, labelV},
{u.UAP.VAPTxGoodbytes, prometheus.CounterValue, v.TxTCPStats.Goodbytes, labelV},
{u.UAP.VAPTxLatAvg, prometheus.GaugeValue, v.TxTCPStats.LatAvg.Val / 1000, labelV},
{u.UAP.VAPTxLatMax, prometheus.GaugeValue, v.TxTCPStats.LatMax.Val / 1000, labelV},
{u.UAP.VAPTxLatMin, prometheus.GaugeValue, v.TxTCPStats.LatMin.Val / 1000, labelV},
{u.UAP.VAPRxGoodbytes, prometheus.CounterValue, v.RxTCPStats.Goodbytes, labelV},
{u.UAP.VAPRxLatAvg, prometheus.GaugeValue, v.RxTCPStats.LatAvg.Val / 1000, labelV},
{u.UAP.VAPRxLatMax, prometheus.GaugeValue, v.RxTCPStats.LatMax.Val / 1000, labelV},
{u.UAP.VAPRxLatMin, prometheus.GaugeValue, v.RxTCPStats.LatMin.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovAvg, prometheus.GaugeValue, v.WifiTxLatencyMov.Avg.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovMax, prometheus.GaugeValue, v.WifiTxLatencyMov.Max.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovMin, prometheus.GaugeValue, v.WifiTxLatencyMov.Min.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovTotal, prometheus.CounterValue, v.WifiTxLatencyMov.Total, labelV}, // not sure if gauge or counter.
{u.UAP.VAPWifiTxLatencyMovCount, prometheus.CounterValue, v.WifiTxLatencyMov.TotalCount, labelV}, // not sure if gauge or counter.
{u.UAP.VAPCcq, gauge, float64(v.Ccq) / 1000.0, labelV},
{u.UAP.VAPMacFilterRejections, counter, v.MacFilterRejections, labelV},
{u.UAP.VAPNumSatisfactionSta, gauge, v.NumSatisfactionSta, labelV},
{u.UAP.VAPAvgClientSignal, gauge, v.AvgClientSignal.Val, labelV},
{u.UAP.VAPSatisfaction, gauge, v.Satisfaction.Val / 100.0, labelV},
{u.UAP.VAPSatisfactionNow, gauge, v.SatisfactionNow.Val / 100.0, labelV},
{u.UAP.VAPDNSAvgLatency, gauge, v.DNSAvgLatency.Val / 1000, labelV},
{u.UAP.VAPRxBytes, counter, v.RxBytes, labelV},
{u.UAP.VAPRxCrypts, counter, v.RxCrypts, labelV},
{u.UAP.VAPRxDropped, counter, v.RxDropped, labelV},
{u.UAP.VAPRxErrors, counter, v.RxErrors, labelV},
{u.UAP.VAPRxFrags, counter, v.RxFrags, labelV},
{u.UAP.VAPRxNwids, counter, v.RxNwids, labelV},
{u.UAP.VAPRxPackets, counter, v.RxPackets, labelV},
{u.UAP.VAPTxBytes, counter, v.TxBytes, labelV},
{u.UAP.VAPTxDropped, counter, v.TxDropped, labelV},
{u.UAP.VAPTxErrors, counter, v.TxErrors, labelV},
{u.UAP.VAPTxPackets, counter, v.TxPackets, labelV},
{u.UAP.VAPTxPower, gauge, v.TxPower, labelV},
{u.UAP.VAPTxRetries, counter, v.TxRetries, labelV},
{u.UAP.VAPTxCombinedRetries, counter, v.TxCombinedRetries, labelV},
{u.UAP.VAPTxDataMpduBytes, counter, v.TxDataMpduBytes, labelV},
{u.UAP.VAPTxRtsRetries, counter, v.TxRtsRetries, labelV},
{u.UAP.VAPTxTotal, counter, v.TxTotal, labelV},
{u.UAP.VAPTxGoodbytes, counter, v.TxTCPStats.Goodbytes, labelV},
{u.UAP.VAPTxLatAvg, gauge, v.TxTCPStats.LatAvg.Val / 1000, labelV},
{u.UAP.VAPTxLatMax, gauge, v.TxTCPStats.LatMax.Val / 1000, labelV},
{u.UAP.VAPTxLatMin, gauge, v.TxTCPStats.LatMin.Val / 1000, labelV},
{u.UAP.VAPRxGoodbytes, counter, v.RxTCPStats.Goodbytes, labelV},
{u.UAP.VAPRxLatAvg, gauge, v.RxTCPStats.LatAvg.Val / 1000, labelV},
{u.UAP.VAPRxLatMax, gauge, v.RxTCPStats.LatMax.Val / 1000, labelV},
{u.UAP.VAPRxLatMin, gauge, v.RxTCPStats.LatMin.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovAvg, gauge, v.WifiTxLatencyMov.Avg.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovMax, gauge, v.WifiTxLatencyMov.Max.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovMin, gauge, v.WifiTxLatencyMov.Min.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovTotal, counter, v.WifiTxLatencyMov.Total, labelV}, // not sure if gauge or counter.
{u.UAP.VAPWifiTxLatencyMovCount, counter, v.WifiTxLatencyMov.TotalCount, labelV}, // not sure if gauge or counter.
})
}
}
func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) {
// UAP Radio Table
func (u *promUnifi) exportRADtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) {
// radio table
for _, p := range rt {
labelR := []string{p.Name, p.Radio, labels[1], labels[2]}
labelRUser := append(labelR, "user")
labelRGuest := append(labelR, "guest")
r.send([]*metric{
{u.UAP.RadioCurrentAntennaGain, prometheus.GaugeValue, p.CurrentAntennaGain, labelR},
{u.UAP.RadioHt, prometheus.GaugeValue, p.Ht, labelR},
{u.UAP.RadioMaxTxpower, prometheus.GaugeValue, p.MaxTxpower, labelR},
{u.UAP.RadioMinTxpower, prometheus.GaugeValue, p.MinTxpower, labelR},
{u.UAP.RadioNss, prometheus.GaugeValue, p.Nss, labelR},
{u.UAP.RadioRadioCaps, prometheus.GaugeValue, p.RadioCaps, labelR},
{u.UAP.RadioCurrentAntennaGain, gauge, p.CurrentAntennaGain, labelR},
{u.UAP.RadioHt, gauge, p.Ht, labelR},
{u.UAP.RadioMaxTxpower, gauge, p.MaxTxpower, labelR},
{u.UAP.RadioMinTxpower, gauge, p.MinTxpower, labelR},
{u.UAP.RadioNss, gauge, p.Nss, labelR},
{u.UAP.RadioRadioCaps, gauge, p.RadioCaps, labelR},
})
// combine radio table with radio stats table.
@ -314,18 +289,19 @@ func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTabl
continue
}
r.send([]*metric{
{u.UAP.RadioTxPower, prometheus.GaugeValue, t.TxPower, labelR},
{u.UAP.RadioAstBeXmit, prometheus.GaugeValue, t.AstBeXmit, labelR},
{u.UAP.RadioChannel, prometheus.GaugeValue, t.Channel, labelR},
{u.UAP.RadioCuSelfRx, prometheus.GaugeValue, t.CuSelfRx.Val / 100.0, labelR},
{u.UAP.RadioCuSelfTx, prometheus.GaugeValue, t.CuSelfTx.Val / 100.0, labelR},
{u.UAP.RadioExtchannel, prometheus.GaugeValue, t.Extchannel, labelR},
{u.UAP.RadioGain, prometheus.GaugeValue, t.Gain, labelR},
{u.UAP.RadioNumSta, prometheus.GaugeValue, t.GuestNumSta, labelRGuest},
{u.UAP.RadioNumSta, prometheus.GaugeValue, t.UserNumSta, labelRUser},
{u.UAP.RadioTxPackets, prometheus.GaugeValue, t.TxPackets, labelR},
{u.UAP.RadioTxRetries, prometheus.GaugeValue, t.TxRetries, labelR},
{u.UAP.RadioTxPower, gauge, t.TxPower, labelR},
{u.UAP.RadioAstBeXmit, gauge, t.AstBeXmit, labelR},
{u.UAP.RadioChannel, gauge, t.Channel, labelR},
{u.UAP.RadioCuSelfRx, gauge, t.CuSelfRx.Val / 100.0, labelR},
{u.UAP.RadioCuSelfTx, gauge, t.CuSelfTx.Val / 100.0, labelR},
{u.UAP.RadioExtchannel, gauge, t.Extchannel, labelR},
{u.UAP.RadioGain, gauge, t.Gain, labelR},
{u.UAP.RadioNumSta, gauge, t.GuestNumSta, labelRGuest},
{u.UAP.RadioNumSta, gauge, t.UserNumSta, labelRUser},
{u.UAP.RadioTxPackets, gauge, t.TxPackets, labelR},
{u.UAP.RadioTxRetries, gauge, t.TxRetries, labelR},
})
break
}
}
}

View File

@ -16,13 +16,9 @@ type unifiDevice struct {
TotalBytes *prometheus.Desc
BytesR *prometheus.Desc // ap only
BytesD *prometheus.Desc // ap only
Bytes *prometheus.Desc // ap only
TxBytesD *prometheus.Desc // ap only
RxBytesD *prometheus.Desc // ap only
Counter *prometheus.Desc
NumDesktop *prometheus.Desc // gw only
NumMobile *prometheus.Desc // gw only
NumHandheld *prometheus.Desc // gw only
Loadavg1 *prometheus.Desc
Loadavg5 *prometheus.Desc
Loadavg15 *prometheus.Desc
@ -46,7 +42,6 @@ func descDevice(ns string) *unifiDevice {
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil),
BytesR: prometheus.NewDesc(ns+"rate_bytes", "Transfer Rate", labels, nil),
BytesD: prometheus.NewDesc(ns+"d_bytes", "Total Bytes D???", labels, nil),
Bytes: prometheus.NewDesc(ns+"transferred_bytes_total", "Bytes Transferred", labels, nil),
TxBytesD: prometheus.NewDesc(ns+"d_tranmsit_bytes", "Transmit Bytes D???", labels, nil),
RxBytesD: prometheus.NewDesc(ns+"d_receive_bytes", "Receive Bytes D???", labels, nil),
Counter: prometheus.NewDesc(ns+"stations", "Number of Stations", append(labels, "station_type"), nil),
@ -65,37 +60,61 @@ func descDevice(ns string) *unifiDevice {
func (u *promUnifi) exportUDM(r report, d *unifi.UDM) {
labels := []string{d.Type, d.SiteName, d.Name}
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt}
// Dream Machine System Data.
r.send([]*metric{
{u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)},
{u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels},
{u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels},
{u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels},
{u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, append(labels, "user")},
{u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, append(labels, "guest")},
{u.Device.Counter, prometheus.GaugeValue, d.NumDesktop, append(labels, "desktop")},
{u.Device.Counter, prometheus.GaugeValue, d.NumMobile, append(labels, "mobile")},
{u.Device.Counter, prometheus.GaugeValue, d.NumHandheld, append(labels, "handheld")},
{u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels},
{u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels},
{u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels},
{u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels},
{u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels},
{u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels},
{u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels},
{u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels},
})
// 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.exportPortTable(r, labels, d.PortTable)
u.exportPRTtable(r, labels, d.PortTable)
// Gateway Data
u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink)
u.exportWANPorts(r, labels, d.Wan1, d.Wan2)
u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink)
// Dream Machine System Data.
r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...))
// Wireless Data - UDM (non-pro) only
if d.Stat.Ap != nil && d.VapTable != nil {
u.exportUAPstats(r, labels, d.Stat.Ap)
// u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR)
u.exportVAPtable(r, labels, *d.VapTable)
u.exportRadtable(r, labels, *d.RadioTable, *d.RadioTableStats)
u.exportRADtable(r, labels, *d.RadioTable, *d.RadioTableStats)
}
}
// shared by all
func (u *promUnifi) exportBYTstats(r report, labels []string, tx, rx unifi.FlexInt) {
r.send([]*metric{
{u.Device.TotalTxBytes, counter, tx, labels},
{u.Device.TotalRxBytes, counter, rx, labels},
{u.Device.TotalBytes, counter, tx.Val + rx.Val, labels},
})
}
// shared by all
func (u *promUnifi) exportSTAcount(r report, labels []string, stas ...unifi.FlexInt) {
r.send([]*metric{
{u.Device.Counter, gauge, stas[0], append(labels, "user")},
{u.Device.Counter, gauge, stas[1], append(labels, "guest")},
})
if len(stas) > 2 {
r.send([]*metric{
{u.Device.Counter, gauge, stas[2], append(labels, "desktop")},
{u.Device.Counter, gauge, stas[3], append(labels, "mobile")},
{u.Device.Counter, gauge, stas[4], append(labels, "handheld")},
})
}
}
// shared by all
func (u *promUnifi) exportSYSstats(r report, labels []string, s unifi.SysStats, ss unifi.SystemStats) {
r.send([]*metric{
{u.Device.Loadavg1, gauge, s.Loadavg1, labels},
{u.Device.Loadavg5, gauge, s.Loadavg5, labels},
{u.Device.Loadavg15, gauge, s.Loadavg15, labels},
{u.Device.MemUsed, gauge, s.MemUsed, labels},
{u.Device.MemTotal, gauge, s.MemTotal, labels},
{u.Device.MemBuffer, gauge, s.MemBuffer, labels},
{u.Device.CPU, gauge, ss.CPU.Val / 100.0, labels},
{u.Device.Mem, gauge, ss.Mem.Val / 100.0, labels},
})
}

View File

@ -72,56 +72,35 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) {
labels := []string{d.Type, d.SiteName, d.Name}
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt}
// Gateway System Data.
r.send([]*metric{
{u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)},
{u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels},
{u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels},
{u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels},
{u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, append(labels, "user")},
{u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, append(labels, "guest")},
{u.Device.Counter, prometheus.GaugeValue, d.NumDesktop, append(labels, "desktop")},
{u.Device.Counter, prometheus.GaugeValue, d.NumMobile, append(labels, "mobile")},
{u.Device.Counter, prometheus.GaugeValue, d.NumHandheld, append(labels, "handheld")},
{u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels},
{u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels},
{u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels},
{u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels},
{u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels},
{u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels},
{u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels},
{u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels},
})
u.exportWANPorts(r, labels, d.Wan1, d.Wan2)
u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)
u.exportSYSstats(r, labels, d.SysStats, d.SystemStats)
u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink)
u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.UserNumSta, d.GuestNumSta)
r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...))
}
// Gateway States
func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) {
labelLan := []string{"lan", labels[1], labels[2]}
labelWan := []string{"all", labels[1], labels[2]}
r.send([]*metric{
/* // Combined Port Stats - not really needed. sum() the others instead.
{u.USG.WanRxPackets, prometheus.CounterValue, gw.WanRxPackets, labelWan},
{u.USG.WanRxBytes, prometheus.CounterValue, gw.WanRxBytes, labelWan},
{u.USG.WanRxDropped, prometheus.CounterValue, gw.WanRxDropped, labelWan},
{u.USG.WanTxPackets, prometheus.CounterValue, gw.WanTxPackets, labelWan},
{u.USG.WanTxBytes, prometheus.CounterValue, gw.WanTxBytes, labelWan},
{u.USG.WanRxErrors, prometheus.CounterValue, gw.WanRxErrors, labelWan},
*/
{u.USG.LanRxPackets, prometheus.CounterValue, gw.LanRxPackets, labelLan},
{u.USG.LanRxBytes, prometheus.CounterValue, gw.LanRxBytes, labelLan},
{u.USG.LanTxPackets, prometheus.CounterValue, gw.LanTxPackets, labelLan},
{u.USG.LanTxBytes, prometheus.CounterValue, gw.LanTxBytes, labelLan},
{u.USG.LanRxDropped, prometheus.CounterValue, gw.LanRxDropped, labelLan},
{u.USG.UplinkLatency, prometheus.GaugeValue, ul.Latency.Val / 1000, labelWan},
{u.USG.UplinkSpeed, prometheus.GaugeValue, ul.Speed, labelWan},
{u.USG.LanRxPackets, counter, gw.LanRxPackets, labelLan},
{u.USG.LanRxBytes, counter, gw.LanRxBytes, labelLan},
{u.USG.LanTxPackets, counter, gw.LanTxPackets, labelLan},
{u.USG.LanTxBytes, counter, gw.LanTxBytes, labelLan},
{u.USG.LanRxDropped, counter, gw.LanRxDropped, labelLan},
{u.USG.UplinkLatency, gauge, ul.Latency.Val / 1000, labelWan},
{u.USG.UplinkSpeed, gauge, ul.Speed, labelWan},
// Speed Test Stats
{u.USG.Latency, prometheus.GaugeValue, st.Latency.Val / 1000, labelWan},
{u.USG.Runtime, prometheus.GaugeValue, st.Runtime, labelWan},
{u.USG.XputDownload, prometheus.GaugeValue, st.XputDownload, labelWan},
{u.USG.XputUpload, prometheus.GaugeValue, st.XputUpload, labelWan},
{u.USG.Latency, gauge, st.Latency.Val / 1000, labelWan},
{u.USG.Runtime, gauge, st.Runtime, labelWan},
{u.USG.XputDownload, gauge, st.XputDownload, labelWan},
{u.USG.XputUpload, gauge, st.XputUpload, labelWan},
})
}
// WAN Stats
func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) {
for _, wan := range wans {
if !wan.Up.Val {
@ -129,21 +108,21 @@ func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan)
}
labelWan := []string{wan.Name, labels[1], labels[2]}
r.send([]*metric{
{u.USG.WanRxPackets, prometheus.CounterValue, wan.RxPackets, labelWan},
{u.USG.WanRxBytes, prometheus.CounterValue, wan.RxBytes, labelWan},
{u.USG.WanRxDropped, prometheus.CounterValue, wan.RxDropped, labelWan},
{u.USG.WanRxErrors, prometheus.CounterValue, wan.RxErrors, labelWan},
{u.USG.WanTxPackets, prometheus.CounterValue, wan.TxPackets, labelWan},
{u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, labelWan},
{u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, labelWan},
{u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, labelWan},
{u.USG.WanSpeed, prometheus.CounterValue, wan.Speed.Val * 1000000, labelWan},
{u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, labelWan},
{u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, labelWan},
{u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, labelWan},
{u.USG.WanTxErrors, prometheus.CounterValue, wan.TxErrors, labelWan},
{u.USG.WanTxMulticast, prometheus.CounterValue, wan.TxMulticast, labelWan},
{u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, labelWan},
{u.USG.WanRxPackets, counter, wan.RxPackets, labelWan},
{u.USG.WanRxBytes, counter, wan.RxBytes, labelWan},
{u.USG.WanRxDropped, counter, wan.RxDropped, labelWan},
{u.USG.WanRxErrors, counter, wan.RxErrors, labelWan},
{u.USG.WanTxPackets, counter, wan.TxPackets, labelWan},
{u.USG.WanTxBytes, counter, wan.TxBytes, labelWan},
{u.USG.WanRxBroadcast, counter, wan.RxBroadcast, labelWan},
{u.USG.WanRxMulticast, counter, wan.RxMulticast, labelWan},
{u.USG.WanSpeed, counter, wan.Speed.Val * 1000000, labelWan},
{u.USG.WanTxBroadcast, counter, wan.TxBroadcast, labelWan},
{u.USG.WanTxBytesR, counter, wan.TxBytesR, labelWan},
{u.USG.WanTxDropped, counter, wan.TxDropped, labelWan},
{u.USG.WanTxErrors, counter, wan.TxErrors, labelWan},
{u.USG.WanTxMulticast, counter, wan.TxMulticast, labelWan},
{u.USG.WanBytesR, gauge, wan.BytesR, labelWan},
})
}
}

View File

@ -50,6 +50,7 @@ func descUSW(ns string) *usw {
labelS := []string{"site_name", "name"}
labelP := []string{"port_id", "port_num", "port_name", "port_mac", "port_ip", "site_name", "name"}
return &usw{
// This data may be derivable by sum()ing the port data.
SwRxPackets: prometheus.NewDesc(ns+"switch_receive_packets_total", "Switch Packets Received Total", labelS, nil),
SwRxBytes: prometheus.NewDesc(ns+"switch_receive_bytes_total", "Switch Bytes Received Total", labelS, nil),
SwRxErrors: prometheus.NewDesc(ns+"switch_receive_errors_total", "Switch Errors Received Total", labelS, nil),
@ -92,60 +93,49 @@ func descUSW(ns string) *usw {
func (u *promUnifi) exportUSW(r report, d *unifi.USW) {
labels := []string{d.Type, d.SiteName, d.Name}
infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt}
labelsGuest := append(labels, "guest")
labelsUser := append(labels, "user")
u.exportUSWstats(r, labels, d.Stat.Sw)
u.exportPRTtable(r, labels, d.PortTable)
u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)
u.exportSYSstats(r, labels, d.SysStats, d.SystemStats)
u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta)
r.sendone(u.Device.Info, gauge, d.Uptime, append(labels, infoLabels...))
// Switch System Data.
if d.HasTemperature.Val {
r.send([]*metric{{u.Device.Temperature, prometheus.GaugeValue, d.GeneralTemperature, labels}})
r.sendone(u.Device.Temperature, gauge, d.GeneralTemperature, labels)
}
if d.HasFan.Val {
r.send([]*metric{{u.Device.FanLevel, prometheus.GaugeValue, d.FanLevel, labels}})
r.sendone(u.Device.FanLevel, gauge, d.FanLevel, labels)
}
if d.TotalMaxPower.Txt != "" {
r.sendone(u.Device.TotalMaxPower, gauge, d.TotalMaxPower, labels)
}
// Switch System Data.
r.send([]*metric{
{u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)},
{u.Device.TotalMaxPower, prometheus.GaugeValue, d.TotalMaxPower, labels},
{u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels},
{u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels},
{u.Device.TotalBytes, prometheus.CounterValue, d.Bytes, labels},
{u.Device.Counter, prometheus.GaugeValue, d.UserNumSta, labelsUser},
{u.Device.Counter, prometheus.GaugeValue, d.GuestNumSta, labelsGuest},
{u.Device.Loadavg1, prometheus.GaugeValue, d.SysStats.Loadavg1, labels},
{u.Device.Loadavg5, prometheus.GaugeValue, d.SysStats.Loadavg5, labels},
{u.Device.Loadavg15, prometheus.GaugeValue, d.SysStats.Loadavg15, labels},
{u.Device.MemUsed, prometheus.GaugeValue, d.SysStats.MemUsed, labels},
{u.Device.MemTotal, prometheus.GaugeValue, d.SysStats.MemTotal, labels},
{u.Device.MemBuffer, prometheus.GaugeValue, d.SysStats.MemBuffer, labels},
{u.Device.CPU, prometheus.GaugeValue, d.SystemStats.CPU.Val / 100.0, labels},
{u.Device.Mem, prometheus.GaugeValue, d.SystemStats.Mem.Val / 100.0, labels},
})
u.exportPortTable(r, labels, d.PortTable)
u.exportUSWstats(r, labels, d.Stat.Sw)
}
// Switch Stats
func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) {
labelS := labels[1:]
r.send([]*metric{
{u.USW.SwRxPackets, prometheus.CounterValue, sw.RxPackets, labelS},
{u.USW.SwRxBytes, prometheus.CounterValue, sw.RxBytes, labelS},
{u.USW.SwRxErrors, prometheus.CounterValue, sw.RxErrors, labelS},
{u.USW.SwRxDropped, prometheus.CounterValue, sw.RxDropped, labelS},
{u.USW.SwRxCrypts, prometheus.CounterValue, sw.RxCrypts, labelS},
{u.USW.SwRxFrags, prometheus.CounterValue, sw.RxFrags, labelS},
{u.USW.SwTxPackets, prometheus.CounterValue, sw.TxPackets, labelS},
{u.USW.SwTxBytes, prometheus.CounterValue, sw.TxBytes, labelS},
{u.USW.SwTxErrors, prometheus.CounterValue, sw.TxErrors, labelS},
{u.USW.SwTxDropped, prometheus.CounterValue, sw.TxDropped, labelS},
{u.USW.SwTxRetries, prometheus.CounterValue, sw.TxRetries, labelS},
{u.USW.SwRxMulticast, prometheus.CounterValue, sw.RxMulticast, labelS},
{u.USW.SwRxBroadcast, prometheus.CounterValue, sw.RxBroadcast, labelS},
{u.USW.SwTxMulticast, prometheus.CounterValue, sw.TxMulticast, labelS},
{u.USW.SwTxBroadcast, prometheus.CounterValue, sw.TxBroadcast, labelS},
{u.USW.SwBytes, prometheus.CounterValue, sw.Bytes, labelS},
{u.USW.SwRxPackets, counter, sw.RxPackets, labelS},
{u.USW.SwRxBytes, counter, sw.RxBytes, labelS},
{u.USW.SwRxErrors, counter, sw.RxErrors, labelS},
{u.USW.SwRxDropped, counter, sw.RxDropped, labelS},
{u.USW.SwRxCrypts, counter, sw.RxCrypts, labelS},
{u.USW.SwRxFrags, counter, sw.RxFrags, labelS},
{u.USW.SwTxPackets, counter, sw.TxPackets, labelS},
{u.USW.SwTxBytes, counter, sw.TxBytes, labelS},
{u.USW.SwTxErrors, counter, sw.TxErrors, labelS},
{u.USW.SwTxDropped, counter, sw.TxDropped, labelS},
{u.USW.SwTxRetries, counter, sw.TxRetries, labelS},
{u.USW.SwRxMulticast, counter, sw.RxMulticast, labelS},
{u.USW.SwRxBroadcast, counter, sw.RxBroadcast, labelS},
{u.USW.SwTxMulticast, counter, sw.TxMulticast, labelS},
{u.USW.SwTxBroadcast, counter, sw.TxBroadcast, labelS},
{u.USW.SwBytes, counter, sw.Bytes, labelS},
})
}
func (u *promUnifi) exportPortTable(r report, labels []string, pt []unifi.Port) {
// Switch Port Table
func (u *promUnifi) exportPRTtable(r report, labels []string, pt []unifi.Port) {
// Per-port data on a switch
for _, p := range pt {
if !p.Up.Val || !p.Enable.Val {
@ -155,29 +145,29 @@ func (u *promUnifi) exportPortTable(r report, labels []string, pt []unifi.Port)
labelP := []string{labels[2] + " Port " + p.PortIdx.Txt, p.PortIdx.Txt, p.Name, p.Mac, p.IP, labels[1], labels[2]}
if p.PoeEnable.Val && p.PortPoe.Val {
r.send([]*metric{
{u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, labelP},
{u.USW.PoePower, prometheus.GaugeValue, p.PoePower, labelP},
{u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, labelP},
{u.USW.PoeCurrent, gauge, p.PoeCurrent, labelP},
{u.USW.PoePower, gauge, p.PoePower, labelP},
{u.USW.PoeVoltage, gauge, p.PoeVoltage, labelP},
})
}
r.send([]*metric{
{u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, labelP},
{u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, labelP},
{u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, labelP},
{u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, labelP},
{u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, labelP},
{u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, labelP},
{u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, labelP},
{u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction.Val / 100.0, labelP},
{u.USW.Speed, prometheus.GaugeValue, p.Speed.Val * 1000000, labelP},
{u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, labelP},
{u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, labelP},
{u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, labelP},
{u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, labelP},
{u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, labelP},
{u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, labelP},
{u.USW.TxPackets, prometheus.CounterValue, p.TxPackets, labelP},
{u.USW.RxBroadcast, counter, p.RxBroadcast, labelP},
{u.USW.RxBytes, counter, p.RxBytes, labelP},
{u.USW.RxBytesR, gauge, p.RxBytesR, labelP},
{u.USW.RxDropped, counter, p.RxDropped, labelP},
{u.USW.RxErrors, counter, p.RxErrors, labelP},
{u.USW.RxMulticast, counter, p.RxMulticast, labelP},
{u.USW.RxPackets, counter, p.RxPackets, labelP},
{u.USW.Satisfaction, gauge, p.Satisfaction.Val / 100.0, labelP},
{u.USW.Speed, gauge, p.Speed.Val * 1000000, labelP},
{u.USW.TxBroadcast, counter, p.TxBroadcast, labelP},
{u.USW.TxBytes, counter, p.TxBytes, labelP},
{u.USW.TxBytesR, gauge, p.TxBytesR, labelP},
{u.USW.TxDropped, counter, p.TxDropped, labelP},
{u.USW.TxErrors, counter, p.TxErrors, labelP},
{u.USW.TxMulticast, counter, p.TxMulticast, labelP},
{u.USW.TxPackets, counter, p.TxPackets, labelP},
})
}
}