Merge pull request #152 from davidnewhall/dn2_updates

Fixes and Updates
This commit is contained in:
David Newhall II 2019-12-03 03:20:13 -08:00 committed by GitHub
commit 011d9322a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 370 additions and 387 deletions

View File

@ -24,6 +24,7 @@ install:
# download super-linter: golangci-lint # download super-linter: golangci-lint
- curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest
- rvm install 2.0.0 - rvm install 2.0.0
- rvm 2.0.0 do gem install --no-document package_cloud
- rvm 2.0.0 do gem install --no-document fpm - rvm 2.0.0 do gem install --no-document fpm
before_script: before_script:
# Create your own deploy key, tar it, and encrypt the file to make this work. Optionally add a bitly_token file to the archive. # Create your own deploy key, tar it, and encrypt the file to make this work. Optionally add a bitly_token file to the archive.
@ -70,3 +71,8 @@ deploy:
script: scripts/formula-deploy.sh script: scripts/formula-deploy.sh
on: on:
tags: true tags: true
- provider: script
script: scripts/package-deploy.sh
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|v[0-9.])$

View File

@ -276,20 +276,3 @@ install: man readme $(BINARY)
/usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/ /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/
[ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE) [ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE)
/usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/ /usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/
# If you installed with `make install` run `make uninstall` before installing a binary package. (even on Linux!!!)
# This will remove the package install from macOS, it will not remove a package install from Linux.
uninstall:
@echo " ==> You must run make uninstall as root on Linux. Recommend not running as root on macOS."
[ -x /bin/systemctl ] && /bin/systemctl disable $(BINARY) || true
[ -x /bin/systemctl ] && /bin/systemctl stop $(BINARY) || true
[ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist ] \
&& /bin/launchctl unload ~/Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist || true
[ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist ] \
&& /bin/launchctl unload /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist || true
rm -rf /usr/local/{etc,bin,share/doc}/$(BINARY)
rm -f ~/Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist
rm -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist || true
rm -f /etc/systemd/system/$(BINARY).service /usr/local/share/man/man1/$(BINARY).1.gz
[ -x /bin/systemctl ] && /bin/systemctl --system daemon-reload || true
@[ -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist ] && echo " ==> Unload and delete this file manually:" && echo " sudo launchctl unload /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist" && echo " sudo rm -f /Library/LaunchAgents/com.github.$(GHUSER).$(BINARY).plist" || true

View File

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

View File

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

View File

@ -16,6 +16,10 @@ import (
// channel buffer, fits at least one batch. // channel buffer, fits at least one batch.
const buffer = 50 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. // UnifiCollectorCnfg defines the data needed to collect and report UniFi Metrics.
type UnifiCollectorCnfg struct { type UnifiCollectorCnfg struct {
// If non-empty, each of the collected metrics is prefixed by the // If non-empty, each of the collected metrics is prefixed by the
@ -117,16 +121,17 @@ func (u *promUnifi) Collect(ch chan<- prometheus.Metric) {
} }
// Pass Report interface into our collecting and reporting methods. // Pass Report interface into our collecting and reporting methods.
go u.exportMetrics(r, ch) go u.exportMetrics(r, ch, r.ch)
u.loopExports(r) u.loopExports(r)
} }
// This is closely tied to the method above with a sync.WaitGroup. // This is closely tied to the method above with a sync.WaitGroup.
// This method runs in a go routine and exits when the channel closes. // This method runs in a go routine and exits when the channel closes.
func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) { // This is where our channels connects to the prometheus channel.
func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric, ourChan chan []*metric) {
descs := make(map[*prometheus.Desc]bool) // used as a counter descs := make(map[*prometheus.Desc]bool) // used as a counter
defer r.report(descs) defer r.report(descs)
for newMetrics := range r.channel() { for newMetrics := range ourChan {
for _, m := range newMetrics { for _, m := range newMetrics {
descs[m.Desc] = true descs[m.Desc] = true
switch v := m.Value.(type) { switch v := m.Value.(type) {
@ -147,10 +152,11 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric) {
} }
func (u *promUnifi) loopExports(r report) { func (u *promUnifi) loopExports(r report) {
m := r.metrics()
r.add() r.add()
go func() { go func() {
defer r.done() defer r.done()
for _, s := range r.metrics().Sites { for _, s := range m.Sites {
u.exportSite(r, s) u.exportSite(r, s)
} }
}() }()
@ -158,7 +164,7 @@ func (u *promUnifi) loopExports(r report) {
r.add() r.add()
go func() { go func() {
defer r.done() defer r.done()
for _, d := range r.metrics().UAPs { for _, d := range m.UAPs {
u.exportUAP(r, d) u.exportUAP(r, d)
} }
}() }()
@ -166,7 +172,7 @@ func (u *promUnifi) loopExports(r report) {
r.add() r.add()
go func() { go func() {
defer r.done() defer r.done()
for _, d := range r.metrics().UDMs { for _, d := range m.UDMs {
u.exportUDM(r, d) u.exportUDM(r, d)
} }
}() }()
@ -174,7 +180,7 @@ func (u *promUnifi) loopExports(r report) {
r.add() r.add()
go func() { go func() {
defer r.done() defer r.done()
for _, d := range r.metrics().USGs { for _, d := range m.USGs {
u.exportUSG(r, d) u.exportUSG(r, d)
} }
}() }()
@ -182,7 +188,7 @@ func (u *promUnifi) loopExports(r report) {
r.add() r.add()
go func() { go func() {
defer r.done() defer r.done()
for _, d := range r.metrics().USWs { for _, d := range m.USWs {
u.exportUSW(r, d) u.exportUSW(r, d)
} }
}() }()
@ -190,7 +196,7 @@ func (u *promUnifi) loopExports(r report) {
r.add() r.add()
go func() { go func() {
defer r.done() defer r.done()
for _, c := range r.metrics().Clients { for _, c := range m.Clients {
u.exportClient(r, c) u.exportClient(r, c)
} }
}() }()

View File

@ -17,7 +17,6 @@ type report interface {
done() done()
send([]*metric) send([]*metric)
metrics() *metrics.Metrics metrics() *metrics.Metrics
channel() chan []*metric
report(descs map[*prometheus.Desc]bool) report(descs map[*prometheus.Desc]bool)
export(m *metric, v float64) prometheus.Metric export(m *metric, v float64) prometheus.Metric
error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{}) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{})
@ -43,10 +42,6 @@ func (r *Report) metrics() *metrics.Metrics {
return r.Metrics return r.Metrics
} }
func (r *Report) channel() chan []*metric {
return r.ch
}
func (r *Report) report(descs map[*prometheus.Desc]bool) { func (r *Report) report(descs map[*prometheus.Desc]bool) {
if r.cf.LoggingFn == nil { if r.cf.LoggingFn == nil {
return return

View File

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

View File

@ -160,89 +160,67 @@ func descUAP(ns string) *uap {
func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { func (u *promUnifi) exportUAP(r report, d *unifi.UAP) {
labels := []string{d.Type, d.SiteName, d.Name} 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} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt}
u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR)
// 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.exportVAPtable(r, labels, d.VapTable) 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.send([]*metric{
{u.Device.Info, gauge, 1.0, append(labels, infoLabels...)},
{u.Device.Uptime, gauge, d.Uptime, labels},
})
} }
func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap) { // udm doesn't have these stats exposed yet, so pass 2 or 6 metrics.
// 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]} labelU := []string{"user", labels[1], labels[2]}
labelG := []string{"guest", 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{ 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 // user
{u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.UserWifiTxDropped, labelU}, {u.UAP.ApWifiTxDropped, counter, ap.UserWifiTxDropped, labelU},
{u.UAP.ApRxErrors, prometheus.CounterValue, ap.UserRxErrors, labelU}, {u.UAP.ApRxErrors, counter, ap.UserRxErrors, labelU},
{u.UAP.ApRxDropped, prometheus.CounterValue, ap.UserRxDropped, labelU}, {u.UAP.ApRxDropped, counter, ap.UserRxDropped, labelU},
{u.UAP.ApRxFrags, prometheus.CounterValue, ap.UserRxFrags, labelU}, {u.UAP.ApRxFrags, counter, ap.UserRxFrags, labelU},
{u.UAP.ApRxCrypts, prometheus.CounterValue, ap.UserRxCrypts, labelU}, {u.UAP.ApRxCrypts, counter, ap.UserRxCrypts, labelU},
{u.UAP.ApTxPackets, prometheus.CounterValue, ap.UserTxPackets, labelU}, {u.UAP.ApTxPackets, counter, ap.UserTxPackets, labelU},
{u.UAP.ApTxBytes, prometheus.CounterValue, ap.UserTxBytes, labelU}, {u.UAP.ApTxBytes, counter, ap.UserTxBytes, labelU},
{u.UAP.ApTxErrors, prometheus.CounterValue, ap.UserTxErrors, labelU}, {u.UAP.ApTxErrors, counter, ap.UserTxErrors, labelU},
{u.UAP.ApTxDropped, prometheus.CounterValue, ap.UserTxDropped, labelU}, {u.UAP.ApTxDropped, counter, ap.UserTxDropped, labelU},
{u.UAP.ApTxRetries, prometheus.CounterValue, ap.UserTxRetries, labelU}, {u.UAP.ApTxRetries, counter, ap.UserTxRetries, labelU},
{u.UAP.ApRxPackets, prometheus.CounterValue, ap.UserRxPackets, labelU}, {u.UAP.ApRxPackets, counter, ap.UserRxPackets, labelU},
{u.UAP.ApRxBytes, prometheus.CounterValue, ap.UserRxBytes, labelU}, {u.UAP.ApRxBytes, counter, ap.UserRxBytes, labelU},
{u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.UserWifiTxAttempts, labelU}, {u.UAP.WifiTxAttempts, counter, ap.UserWifiTxAttempts, labelU},
{u.UAP.MacFilterRejections, prometheus.CounterValue, ap.UserMacFilterRejections, labelU}, {u.UAP.MacFilterRejections, counter, ap.UserMacFilterRejections, labelU},
// guest // guest
{u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.GuestWifiTxDropped, labelG}, {u.UAP.ApWifiTxDropped, counter, ap.GuestWifiTxDropped, labelG},
{u.UAP.ApRxErrors, prometheus.CounterValue, ap.GuestRxErrors, labelG}, {u.UAP.ApRxErrors, counter, ap.GuestRxErrors, labelG},
{u.UAP.ApRxDropped, prometheus.CounterValue, ap.GuestRxDropped, labelG}, {u.UAP.ApRxDropped, counter, ap.GuestRxDropped, labelG},
{u.UAP.ApRxFrags, prometheus.CounterValue, ap.GuestRxFrags, labelG}, {u.UAP.ApRxFrags, counter, ap.GuestRxFrags, labelG},
{u.UAP.ApRxCrypts, prometheus.CounterValue, ap.GuestRxCrypts, labelG}, {u.UAP.ApRxCrypts, counter, ap.GuestRxCrypts, labelG},
{u.UAP.ApTxPackets, prometheus.CounterValue, ap.GuestTxPackets, labelG}, {u.UAP.ApTxPackets, counter, ap.GuestTxPackets, labelG},
{u.UAP.ApTxBytes, prometheus.CounterValue, ap.GuestTxBytes, labelG}, {u.UAP.ApTxBytes, counter, ap.GuestTxBytes, labelG},
{u.UAP.ApTxErrors, prometheus.CounterValue, ap.GuestTxErrors, labelG}, {u.UAP.ApTxErrors, counter, ap.GuestTxErrors, labelG},
{u.UAP.ApTxDropped, prometheus.CounterValue, ap.GuestTxDropped, labelG}, {u.UAP.ApTxDropped, counter, ap.GuestTxDropped, labelG},
{u.UAP.ApTxRetries, prometheus.CounterValue, ap.GuestTxRetries, labelG}, {u.UAP.ApTxRetries, counter, ap.GuestTxRetries, labelG},
{u.UAP.ApRxPackets, prometheus.CounterValue, ap.GuestRxPackets, labelG}, {u.UAP.ApRxPackets, counter, ap.GuestRxPackets, labelG},
{u.UAP.ApRxBytes, prometheus.CounterValue, ap.GuestRxBytes, labelG}, {u.UAP.ApRxBytes, counter, ap.GuestRxBytes, labelG},
{u.UAP.WifiTxAttempts, prometheus.CounterValue, ap.GuestWifiTxAttempts, labelG}, {u.UAP.WifiTxAttempts, counter, ap.GuestWifiTxAttempts, labelG},
{u.UAP.MacFilterRejections, prometheus.CounterValue, ap.GuestMacFilterRejections, labelG}, {u.UAP.MacFilterRejections, counter, ap.GuestMacFilterRejections, labelG},
}) })
} }
// UAP VAP Table
func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) { func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) {
// vap table stats // vap table stats
for _, v := range vt { for _, v := range vt {
@ -252,60 +230,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]} labelV := []string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage, labels[1], labels[2]}
r.send([]*metric{ r.send([]*metric{
{u.UAP.VAPCcq, prometheus.GaugeValue, float64(v.Ccq) / 1000.0, labelV}, {u.UAP.VAPCcq, gauge, float64(v.Ccq) / 1000.0, labelV},
{u.UAP.VAPMacFilterRejections, prometheus.CounterValue, v.MacFilterRejections, labelV}, {u.UAP.VAPMacFilterRejections, counter, v.MacFilterRejections, labelV},
{u.UAP.VAPNumSatisfactionSta, prometheus.GaugeValue, v.NumSatisfactionSta, labelV}, {u.UAP.VAPNumSatisfactionSta, gauge, v.NumSatisfactionSta, labelV},
{u.UAP.VAPAvgClientSignal, prometheus.GaugeValue, v.AvgClientSignal.Val, labelV}, {u.UAP.VAPAvgClientSignal, gauge, v.AvgClientSignal.Val, labelV},
{u.UAP.VAPSatisfaction, prometheus.GaugeValue, v.Satisfaction.Val / 100.0, labelV}, {u.UAP.VAPSatisfaction, gauge, v.Satisfaction.Val / 100.0, labelV},
{u.UAP.VAPSatisfactionNow, prometheus.GaugeValue, v.SatisfactionNow.Val / 100.0, labelV}, {u.UAP.VAPSatisfactionNow, gauge, v.SatisfactionNow.Val / 100.0, labelV},
{u.UAP.VAPDNSAvgLatency, prometheus.GaugeValue, v.DNSAvgLatency.Val / 1000, labelV}, {u.UAP.VAPDNSAvgLatency, gauge, v.DNSAvgLatency.Val / 1000, labelV},
{u.UAP.VAPRxBytes, prometheus.CounterValue, v.RxBytes, labelV}, {u.UAP.VAPRxBytes, counter, v.RxBytes, labelV},
{u.UAP.VAPRxCrypts, prometheus.CounterValue, v.RxCrypts, labelV}, {u.UAP.VAPRxCrypts, counter, v.RxCrypts, labelV},
{u.UAP.VAPRxDropped, prometheus.CounterValue, v.RxDropped, labelV}, {u.UAP.VAPRxDropped, counter, v.RxDropped, labelV},
{u.UAP.VAPRxErrors, prometheus.CounterValue, v.RxErrors, labelV}, {u.UAP.VAPRxErrors, counter, v.RxErrors, labelV},
{u.UAP.VAPRxFrags, prometheus.CounterValue, v.RxFrags, labelV}, {u.UAP.VAPRxFrags, counter, v.RxFrags, labelV},
{u.UAP.VAPRxNwids, prometheus.CounterValue, v.RxNwids, labelV}, {u.UAP.VAPRxNwids, counter, v.RxNwids, labelV},
{u.UAP.VAPRxPackets, prometheus.CounterValue, v.RxPackets, labelV}, {u.UAP.VAPRxPackets, counter, v.RxPackets, labelV},
{u.UAP.VAPTxBytes, prometheus.CounterValue, v.TxBytes, labelV}, {u.UAP.VAPTxBytes, counter, v.TxBytes, labelV},
{u.UAP.VAPTxDropped, prometheus.CounterValue, v.TxDropped, labelV}, {u.UAP.VAPTxDropped, counter, v.TxDropped, labelV},
{u.UAP.VAPTxErrors, prometheus.CounterValue, v.TxErrors, labelV}, {u.UAP.VAPTxErrors, counter, v.TxErrors, labelV},
{u.UAP.VAPTxPackets, prometheus.CounterValue, v.TxPackets, labelV}, {u.UAP.VAPTxPackets, counter, v.TxPackets, labelV},
{u.UAP.VAPTxPower, prometheus.GaugeValue, v.TxPower, labelV}, {u.UAP.VAPTxPower, gauge, v.TxPower, labelV},
{u.UAP.VAPTxRetries, prometheus.CounterValue, v.TxRetries, labelV}, {u.UAP.VAPTxRetries, counter, v.TxRetries, labelV},
{u.UAP.VAPTxCombinedRetries, prometheus.CounterValue, v.TxCombinedRetries, labelV}, {u.UAP.VAPTxCombinedRetries, counter, v.TxCombinedRetries, labelV},
{u.UAP.VAPTxDataMpduBytes, prometheus.CounterValue, v.TxDataMpduBytes, labelV}, {u.UAP.VAPTxDataMpduBytes, counter, v.TxDataMpduBytes, labelV},
{u.UAP.VAPTxRtsRetries, prometheus.CounterValue, v.TxRtsRetries, labelV}, {u.UAP.VAPTxRtsRetries, counter, v.TxRtsRetries, labelV},
{u.UAP.VAPTxTotal, prometheus.CounterValue, v.TxTotal, labelV}, {u.UAP.VAPTxTotal, counter, v.TxTotal, labelV},
{u.UAP.VAPTxGoodbytes, prometheus.CounterValue, v.TxTCPStats.Goodbytes, labelV}, {u.UAP.VAPTxGoodbytes, counter, v.TxTCPStats.Goodbytes, labelV},
{u.UAP.VAPTxLatAvg, prometheus.GaugeValue, v.TxTCPStats.LatAvg.Val / 1000, labelV}, {u.UAP.VAPTxLatAvg, gauge, v.TxTCPStats.LatAvg.Val / 1000, labelV},
{u.UAP.VAPTxLatMax, prometheus.GaugeValue, v.TxTCPStats.LatMax.Val / 1000, labelV}, {u.UAP.VAPTxLatMax, gauge, v.TxTCPStats.LatMax.Val / 1000, labelV},
{u.UAP.VAPTxLatMin, prometheus.GaugeValue, v.TxTCPStats.LatMin.Val / 1000, labelV}, {u.UAP.VAPTxLatMin, gauge, v.TxTCPStats.LatMin.Val / 1000, labelV},
{u.UAP.VAPRxGoodbytes, prometheus.CounterValue, v.RxTCPStats.Goodbytes, labelV}, {u.UAP.VAPRxGoodbytes, counter, v.RxTCPStats.Goodbytes, labelV},
{u.UAP.VAPRxLatAvg, prometheus.GaugeValue, v.RxTCPStats.LatAvg.Val / 1000, labelV}, {u.UAP.VAPRxLatAvg, gauge, v.RxTCPStats.LatAvg.Val / 1000, labelV},
{u.UAP.VAPRxLatMax, prometheus.GaugeValue, v.RxTCPStats.LatMax.Val / 1000, labelV}, {u.UAP.VAPRxLatMax, gauge, v.RxTCPStats.LatMax.Val / 1000, labelV},
{u.UAP.VAPRxLatMin, prometheus.GaugeValue, v.RxTCPStats.LatMin.Val / 1000, labelV}, {u.UAP.VAPRxLatMin, gauge, v.RxTCPStats.LatMin.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovAvg, prometheus.GaugeValue, v.WifiTxLatencyMov.Avg.Val / 1000, labelV}, {u.UAP.VAPWifiTxLatencyMovAvg, gauge, v.WifiTxLatencyMov.Avg.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovMax, prometheus.GaugeValue, v.WifiTxLatencyMov.Max.Val / 1000, labelV}, {u.UAP.VAPWifiTxLatencyMovMax, gauge, v.WifiTxLatencyMov.Max.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovMin, prometheus.GaugeValue, v.WifiTxLatencyMov.Min.Val / 1000, labelV}, {u.UAP.VAPWifiTxLatencyMovMin, gauge, v.WifiTxLatencyMov.Min.Val / 1000, labelV},
{u.UAP.VAPWifiTxLatencyMovTotal, prometheus.CounterValue, v.WifiTxLatencyMov.Total, labelV}, // not sure if gauge or counter. {u.UAP.VAPWifiTxLatencyMovTotal, counter, 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.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 // radio table
for _, p := range rt { for _, p := range rt {
labelR := []string{p.Name, p.Radio, labels[1], labels[2]} labelR := []string{p.Name, p.Radio, labels[1], labels[2]}
labelRUser := append(labelR, "user") labelRUser := append(labelR, "user")
labelRGuest := append(labelR, "guest") labelRGuest := append(labelR, "guest")
r.send([]*metric{ r.send([]*metric{
{u.UAP.RadioCurrentAntennaGain, prometheus.GaugeValue, p.CurrentAntennaGain, labelR}, {u.UAP.RadioCurrentAntennaGain, gauge, p.CurrentAntennaGain, labelR},
{u.UAP.RadioHt, prometheus.GaugeValue, p.Ht, labelR}, {u.UAP.RadioHt, gauge, p.Ht, labelR},
{u.UAP.RadioMaxTxpower, prometheus.GaugeValue, p.MaxTxpower, labelR}, {u.UAP.RadioMaxTxpower, gauge, p.MaxTxpower, labelR},
{u.UAP.RadioMinTxpower, prometheus.GaugeValue, p.MinTxpower, labelR}, {u.UAP.RadioMinTxpower, gauge, p.MinTxpower, labelR},
{u.UAP.RadioNss, prometheus.GaugeValue, p.Nss, labelR}, {u.UAP.RadioNss, gauge, p.Nss, labelR},
{u.UAP.RadioRadioCaps, prometheus.GaugeValue, p.RadioCaps, labelR}, {u.UAP.RadioRadioCaps, gauge, p.RadioCaps, labelR},
}) })
// combine radio table with radio stats table. // combine radio table with radio stats table.
@ -314,18 +293,19 @@ func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTabl
continue continue
} }
r.send([]*metric{ r.send([]*metric{
{u.UAP.RadioTxPower, prometheus.GaugeValue, t.TxPower, labelR}, {u.UAP.RadioTxPower, gauge, t.TxPower, labelR},
{u.UAP.RadioAstBeXmit, prometheus.GaugeValue, t.AstBeXmit, labelR}, {u.UAP.RadioAstBeXmit, gauge, t.AstBeXmit, labelR},
{u.UAP.RadioChannel, prometheus.GaugeValue, t.Channel, labelR}, {u.UAP.RadioChannel, gauge, t.Channel, labelR},
{u.UAP.RadioCuSelfRx, prometheus.GaugeValue, t.CuSelfRx.Val / 100.0, labelR}, {u.UAP.RadioCuSelfRx, gauge, t.CuSelfRx.Val / 100.0, labelR},
{u.UAP.RadioCuSelfTx, prometheus.GaugeValue, t.CuSelfTx.Val / 100.0, labelR}, {u.UAP.RadioCuSelfTx, gauge, t.CuSelfTx.Val / 100.0, labelR},
{u.UAP.RadioExtchannel, prometheus.GaugeValue, t.Extchannel, labelR}, {u.UAP.RadioExtchannel, gauge, t.Extchannel, labelR},
{u.UAP.RadioGain, prometheus.GaugeValue, t.Gain, labelR}, {u.UAP.RadioGain, gauge, t.Gain, labelR},
{u.UAP.RadioNumSta, prometheus.GaugeValue, t.GuestNumSta, labelRGuest}, {u.UAP.RadioNumSta, gauge, t.GuestNumSta, labelRGuest},
{u.UAP.RadioNumSta, prometheus.GaugeValue, t.UserNumSta, labelRUser}, {u.UAP.RadioNumSta, gauge, t.UserNumSta, labelRUser},
{u.UAP.RadioTxPackets, prometheus.GaugeValue, t.TxPackets, labelR}, {u.UAP.RadioTxPackets, gauge, t.TxPackets, labelR},
{u.UAP.RadioTxRetries, prometheus.GaugeValue, t.TxRetries, labelR}, {u.UAP.RadioTxRetries, gauge, t.TxRetries, labelR},
}) })
break
} }
} }
} }

View File

@ -7,7 +7,8 @@ import (
// These are shared by all four device types: UDM, UAP, USG, USW // These are shared by all four device types: UDM, UAP, USG, USW
type unifiDevice struct { type unifiDevice struct {
Info *prometheus.Desc // uptime Info *prometheus.Desc
Uptime *prometheus.Desc
Temperature *prometheus.Desc // sw only Temperature *prometheus.Desc // sw only
TotalMaxPower *prometheus.Desc // sw only TotalMaxPower *prometheus.Desc // sw only
FanLevel *prometheus.Desc // sw only FanLevel *prometheus.Desc // sw only
@ -16,13 +17,9 @@ type unifiDevice struct {
TotalBytes *prometheus.Desc TotalBytes *prometheus.Desc
BytesR *prometheus.Desc // ap only BytesR *prometheus.Desc // ap only
BytesD *prometheus.Desc // ap only BytesD *prometheus.Desc // ap only
Bytes *prometheus.Desc // ap only
TxBytesD *prometheus.Desc // ap only TxBytesD *prometheus.Desc // ap only
RxBytesD *prometheus.Desc // ap only RxBytesD *prometheus.Desc // ap only
Counter *prometheus.Desc Counter *prometheus.Desc
NumDesktop *prometheus.Desc // gw only
NumMobile *prometheus.Desc // gw only
NumHandheld *prometheus.Desc // gw only
Loadavg1 *prometheus.Desc Loadavg1 *prometheus.Desc
Loadavg5 *prometheus.Desc Loadavg5 *prometheus.Desc
Loadavg15 *prometheus.Desc Loadavg15 *prometheus.Desc
@ -35,9 +32,10 @@ type unifiDevice struct {
func descDevice(ns string) *unifiDevice { func descDevice(ns string) *unifiDevice {
labels := []string{"type", "site_name", "name"} labels := []string{"type", "site_name", "name"}
infoLabels := []string{"version", "model", "serial", "mac", "ip", "id", "bytes"} infoLabels := []string{"version", "model", "serial", "mac", "ip", "id", "bytes", "uptime"}
return &unifiDevice{ return &unifiDevice{
Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil), Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil),
Uptime: prometheus.NewDesc(ns+"uptime_seconds", "Device Uptime", labels, nil),
Temperature: prometheus.NewDesc(ns+"temperature_celsius", "Temperature", labels, nil), Temperature: prometheus.NewDesc(ns+"temperature_celsius", "Temperature", labels, nil),
TotalMaxPower: prometheus.NewDesc(ns+"max_power_total", "Total Max Power", labels, nil), TotalMaxPower: prometheus.NewDesc(ns+"max_power_total", "Total Max Power", labels, nil),
FanLevel: prometheus.NewDesc(ns+"fan_level", "Fan Level", labels, nil), FanLevel: prometheus.NewDesc(ns+"fan_level", "Fan Level", labels, nil),
@ -46,7 +44,6 @@ func descDevice(ns string) *unifiDevice {
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil), TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil),
BytesR: prometheus.NewDesc(ns+"rate_bytes", "Transfer Rate", labels, nil), BytesR: prometheus.NewDesc(ns+"rate_bytes", "Transfer Rate", labels, nil),
BytesD: prometheus.NewDesc(ns+"d_bytes", "Total Bytes D???", 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), TxBytesD: prometheus.NewDesc(ns+"d_tranmsit_bytes", "Transmit Bytes D???", labels, nil),
RxBytesD: prometheus.NewDesc(ns+"d_receive_bytes", "Receive 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), Counter: prometheus.NewDesc(ns+"stations", "Number of Stations", append(labels, "station_type"), nil),
@ -64,38 +61,65 @@ func descDevice(ns string) *unifiDevice {
// UDM is a collection of stats from USG, USW and UAP. It has no unique stats. // UDM is a collection of stats from USG, USW and UAP. It has no unique stats.
func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { func (u *promUnifi) exportUDM(r report, d *unifi.UDM) {
labels := []string{d.Type, d.SiteName, d.Name} 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} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt}
// Dream Machine System Data. // Shared data (all devices do this).
r.send([]*metric{ u.exportBYTstats(r, labels, d.TxBytes, d.RxBytes)
{u.Device.Info, prometheus.GaugeValue, d.Uptime, append(labels, infoLabels...)}, u.exportSYSstats(r, labels, d.SysStats, d.SystemStats)
{u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, u.exportSTAcount(r, labels, d.UserNumSta, d.GuestNumSta, d.NumDesktop, d.NumMobile, d.NumHandheld)
{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},
})
// Switch Data // Switch Data
u.exportUSWstats(r, labels, d.Stat.Sw) u.exportUSWstats(r, labels, d.Stat.Sw)
u.exportPortTable(r, labels, d.PortTable) u.exportPRTtable(r, labels, d.PortTable)
// Gateway Data // Gateway Data
u.exportUSGstats(r, labels, d.Stat.Gw, d.SpeedtestStatus, d.Uplink)
u.exportWANPorts(r, labels, d.Wan1, d.Wan2) 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},
})
// Wireless Data - UDM (non-pro) only // Wireless Data - UDM (non-pro) only
if d.Stat.Ap != nil && d.VapTable != nil { if d.Stat.Ap != nil && d.VapTable != nil {
u.exportUAPstats(r, labels, d.Stat.Ap) 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.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, pass 2 or 5 stats.
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

@ -70,58 +70,40 @@ func descUSG(ns string) *usg {
func (u *promUnifi) exportUSG(r report, d *unifi.USG) { func (u *promUnifi) exportUSG(r report, d *unifi.USG) {
labels := []string{d.Type, d.SiteName, d.Name} 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} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt}
// Gateway System Data. // 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.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.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.send([]*metric{
{u.Device.Info, gauge, 1.0, append(labels, infoLabels...)},
{u.Device.Uptime, gauge, d.Uptime, labels},
})
} }
// Gateway States
func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) { func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) {
labelLan := []string{"lan", labels[1], labels[2]} labelLan := []string{"lan", labels[1], labels[2]}
labelWan := []string{"all", labels[1], labels[2]} labelWan := []string{"all", labels[1], labels[2]}
r.send([]*metric{ r.send([]*metric{
/* // Combined Port Stats - not really needed. sum() the others instead. {u.USG.LanRxPackets, counter, gw.LanRxPackets, labelLan},
{u.USG.WanRxPackets, prometheus.CounterValue, gw.WanRxPackets, labelWan}, {u.USG.LanRxBytes, counter, gw.LanRxBytes, labelLan},
{u.USG.WanRxBytes, prometheus.CounterValue, gw.WanRxBytes, labelWan}, {u.USG.LanTxPackets, counter, gw.LanTxPackets, labelLan},
{u.USG.WanRxDropped, prometheus.CounterValue, gw.WanRxDropped, labelWan}, {u.USG.LanTxBytes, counter, gw.LanTxBytes, labelLan},
{u.USG.WanTxPackets, prometheus.CounterValue, gw.WanTxPackets, labelWan}, {u.USG.LanRxDropped, counter, gw.LanRxDropped, labelLan},
{u.USG.WanTxBytes, prometheus.CounterValue, gw.WanTxBytes, labelWan}, {u.USG.UplinkLatency, gauge, ul.Latency.Val / 1000, labelWan},
{u.USG.WanRxErrors, prometheus.CounterValue, gw.WanRxErrors, labelWan}, {u.USG.UplinkSpeed, gauge, ul.Speed, 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},
// Speed Test Stats // Speed Test Stats
{u.USG.Latency, prometheus.GaugeValue, st.Latency.Val / 1000, labelWan}, {u.USG.Latency, gauge, st.Latency.Val / 1000, labelWan},
{u.USG.Runtime, prometheus.GaugeValue, st.Runtime, labelWan}, {u.USG.Runtime, gauge, st.Runtime, labelWan},
{u.USG.XputDownload, prometheus.GaugeValue, st.XputDownload, labelWan}, {u.USG.XputDownload, gauge, st.XputDownload, labelWan},
{u.USG.XputUpload, prometheus.GaugeValue, st.XputUpload, labelWan}, {u.USG.XputUpload, gauge, st.XputUpload, labelWan},
}) })
} }
// WAN Stats
func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) { func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) {
for _, wan := range wans { for _, wan := range wans {
if !wan.Up.Val { if !wan.Up.Val {
@ -129,21 +111,21 @@ func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan)
} }
labelWan := []string{wan.Name, labels[1], labels[2]} labelWan := []string{wan.Name, labels[1], labels[2]}
r.send([]*metric{ r.send([]*metric{
{u.USG.WanRxPackets, prometheus.CounterValue, wan.RxPackets, labelWan}, {u.USG.WanRxPackets, counter, wan.RxPackets, labelWan},
{u.USG.WanRxBytes, prometheus.CounterValue, wan.RxBytes, labelWan}, {u.USG.WanRxBytes, counter, wan.RxBytes, labelWan},
{u.USG.WanRxDropped, prometheus.CounterValue, wan.RxDropped, labelWan}, {u.USG.WanRxDropped, counter, wan.RxDropped, labelWan},
{u.USG.WanRxErrors, prometheus.CounterValue, wan.RxErrors, labelWan}, {u.USG.WanRxErrors, counter, wan.RxErrors, labelWan},
{u.USG.WanTxPackets, prometheus.CounterValue, wan.TxPackets, labelWan}, {u.USG.WanTxPackets, counter, wan.TxPackets, labelWan},
{u.USG.WanTxBytes, prometheus.CounterValue, wan.TxBytes, labelWan}, {u.USG.WanTxBytes, counter, wan.TxBytes, labelWan},
{u.USG.WanRxBroadcast, prometheus.CounterValue, wan.RxBroadcast, labelWan}, {u.USG.WanRxBroadcast, counter, wan.RxBroadcast, labelWan},
{u.USG.WanRxMulticast, prometheus.CounterValue, wan.RxMulticast, labelWan}, {u.USG.WanRxMulticast, counter, wan.RxMulticast, labelWan},
{u.USG.WanSpeed, prometheus.CounterValue, wan.Speed.Val * 1000000, labelWan}, {u.USG.WanSpeed, counter, wan.Speed.Val * 1000000, labelWan},
{u.USG.WanTxBroadcast, prometheus.CounterValue, wan.TxBroadcast, labelWan}, {u.USG.WanTxBroadcast, counter, wan.TxBroadcast, labelWan},
{u.USG.WanTxBytesR, prometheus.CounterValue, wan.TxBytesR, labelWan}, {u.USG.WanTxBytesR, counter, wan.TxBytesR, labelWan},
{u.USG.WanTxDropped, prometheus.CounterValue, wan.TxDropped, labelWan}, {u.USG.WanTxDropped, counter, wan.TxDropped, labelWan},
{u.USG.WanTxErrors, prometheus.CounterValue, wan.TxErrors, labelWan}, {u.USG.WanTxErrors, counter, wan.TxErrors, labelWan},
{u.USG.WanTxMulticast, prometheus.CounterValue, wan.TxMulticast, labelWan}, {u.USG.WanTxMulticast, counter, wan.TxMulticast, labelWan},
{u.USG.WanBytesR, prometheus.GaugeValue, wan.BytesR, labelWan}, {u.USG.WanBytesR, gauge, wan.BytesR, labelWan},
}) })
} }
} }

View File

@ -50,6 +50,7 @@ func descUSW(ns string) *usw {
labelS := []string{"site_name", "name"} labelS := []string{"site_name", "name"}
labelP := []string{"port_id", "port_num", "port_name", "port_mac", "port_ip", "site_name", "name"} labelP := []string{"port_id", "port_num", "port_name", "port_mac", "port_ip", "site_name", "name"}
return &usw{ 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), 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), 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), SwRxErrors: prometheus.NewDesc(ns+"switch_receive_errors_total", "Switch Errors Received Total", labelS, nil),
@ -91,61 +92,53 @@ func descUSW(ns string) *usw {
func (u *promUnifi) exportUSW(r report, d *unifi.USW) { func (u *promUnifi) exportUSW(r report, d *unifi.USW) {
labels := []string{d.Type, d.SiteName, d.Name} 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} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt}
labelsGuest := append(labels, "guest") u.exportUSWstats(r, labels, d.Stat.Sw)
labelsUser := append(labels, "user") 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.send([]*metric{
{u.Device.Info, gauge, 1.0, append(labels, infoLabels...)},
{u.Device.Uptime, gauge, d.Uptime, labels},
})
// Switch System Data.
if d.HasTemperature.Val { if d.HasTemperature.Val {
r.send([]*metric{{u.Device.Temperature, prometheus.GaugeValue, d.GeneralTemperature, labels}}) r.send([]*metric{{u.Device.Temperature, gauge, d.GeneralTemperature, labels}})
} }
if d.HasFan.Val { if d.HasFan.Val {
r.send([]*metric{{u.Device.FanLevel, prometheus.GaugeValue, d.FanLevel, labels}}) r.send([]*metric{{u.Device.FanLevel, gauge, d.FanLevel, labels}})
}
if d.TotalMaxPower.Txt != "" {
r.send([]*metric{{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) { func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) {
labelS := labels[1:] labelS := labels[1:]
r.send([]*metric{ r.send([]*metric{
{u.USW.SwRxPackets, prometheus.CounterValue, sw.RxPackets, labelS}, {u.USW.SwRxPackets, counter, sw.RxPackets, labelS},
{u.USW.SwRxBytes, prometheus.CounterValue, sw.RxBytes, labelS}, {u.USW.SwRxBytes, counter, sw.RxBytes, labelS},
{u.USW.SwRxErrors, prometheus.CounterValue, sw.RxErrors, labelS}, {u.USW.SwRxErrors, counter, sw.RxErrors, labelS},
{u.USW.SwRxDropped, prometheus.CounterValue, sw.RxDropped, labelS}, {u.USW.SwRxDropped, counter, sw.RxDropped, labelS},
{u.USW.SwRxCrypts, prometheus.CounterValue, sw.RxCrypts, labelS}, {u.USW.SwRxCrypts, counter, sw.RxCrypts, labelS},
{u.USW.SwRxFrags, prometheus.CounterValue, sw.RxFrags, labelS}, {u.USW.SwRxFrags, counter, sw.RxFrags, labelS},
{u.USW.SwTxPackets, prometheus.CounterValue, sw.TxPackets, labelS}, {u.USW.SwTxPackets, counter, sw.TxPackets, labelS},
{u.USW.SwTxBytes, prometheus.CounterValue, sw.TxBytes, labelS}, {u.USW.SwTxBytes, counter, sw.TxBytes, labelS},
{u.USW.SwTxErrors, prometheus.CounterValue, sw.TxErrors, labelS}, {u.USW.SwTxErrors, counter, sw.TxErrors, labelS},
{u.USW.SwTxDropped, prometheus.CounterValue, sw.TxDropped, labelS}, {u.USW.SwTxDropped, counter, sw.TxDropped, labelS},
{u.USW.SwTxRetries, prometheus.CounterValue, sw.TxRetries, labelS}, {u.USW.SwTxRetries, counter, sw.TxRetries, labelS},
{u.USW.SwRxMulticast, prometheus.CounterValue, sw.RxMulticast, labelS}, {u.USW.SwRxMulticast, counter, sw.RxMulticast, labelS},
{u.USW.SwRxBroadcast, prometheus.CounterValue, sw.RxBroadcast, labelS}, {u.USW.SwRxBroadcast, counter, sw.RxBroadcast, labelS},
{u.USW.SwTxMulticast, prometheus.CounterValue, sw.TxMulticast, labelS}, {u.USW.SwTxMulticast, counter, sw.TxMulticast, labelS},
{u.USW.SwTxBroadcast, prometheus.CounterValue, sw.TxBroadcast, labelS}, {u.USW.SwTxBroadcast, counter, sw.TxBroadcast, labelS},
{u.USW.SwBytes, prometheus.CounterValue, sw.Bytes, 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 // Per-port data on a switch
for _, p := range pt { for _, p := range pt {
if !p.Up.Val || !p.Enable.Val { if !p.Up.Val || !p.Enable.Val {
@ -155,29 +148,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]} 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 { if p.PoeEnable.Val && p.PortPoe.Val {
r.send([]*metric{ r.send([]*metric{
{u.USW.PoeCurrent, prometheus.GaugeValue, p.PoeCurrent, labelP}, {u.USW.PoeCurrent, gauge, p.PoeCurrent, labelP},
{u.USW.PoePower, prometheus.GaugeValue, p.PoePower, labelP}, {u.USW.PoePower, gauge, p.PoePower, labelP},
{u.USW.PoeVoltage, prometheus.GaugeValue, p.PoeVoltage, labelP}, {u.USW.PoeVoltage, gauge, p.PoeVoltage, labelP},
}) })
} }
r.send([]*metric{ r.send([]*metric{
{u.USW.RxBroadcast, prometheus.CounterValue, p.RxBroadcast, labelP}, {u.USW.RxBroadcast, counter, p.RxBroadcast, labelP},
{u.USW.RxBytes, prometheus.CounterValue, p.RxBytes, labelP}, {u.USW.RxBytes, counter, p.RxBytes, labelP},
{u.USW.RxBytesR, prometheus.GaugeValue, p.RxBytesR, labelP}, {u.USW.RxBytesR, gauge, p.RxBytesR, labelP},
{u.USW.RxDropped, prometheus.CounterValue, p.RxDropped, labelP}, {u.USW.RxDropped, counter, p.RxDropped, labelP},
{u.USW.RxErrors, prometheus.CounterValue, p.RxErrors, labelP}, {u.USW.RxErrors, counter, p.RxErrors, labelP},
{u.USW.RxMulticast, prometheus.CounterValue, p.RxMulticast, labelP}, {u.USW.RxMulticast, counter, p.RxMulticast, labelP},
{u.USW.RxPackets, prometheus.CounterValue, p.RxPackets, labelP}, {u.USW.RxPackets, counter, p.RxPackets, labelP},
{u.USW.Satisfaction, prometheus.GaugeValue, p.Satisfaction.Val / 100.0, labelP}, {u.USW.Satisfaction, gauge, p.Satisfaction.Val / 100.0, labelP},
{u.USW.Speed, prometheus.GaugeValue, p.Speed.Val * 1000000, labelP}, {u.USW.Speed, gauge, p.Speed.Val * 1000000, labelP},
{u.USW.TxBroadcast, prometheus.CounterValue, p.TxBroadcast, labelP}, {u.USW.TxBroadcast, counter, p.TxBroadcast, labelP},
{u.USW.TxBytes, prometheus.CounterValue, p.TxBytes, labelP}, {u.USW.TxBytes, counter, p.TxBytes, labelP},
{u.USW.TxBytesR, prometheus.GaugeValue, p.TxBytesR, labelP}, {u.USW.TxBytesR, gauge, p.TxBytesR, labelP},
{u.USW.TxDropped, prometheus.CounterValue, p.TxDropped, labelP}, {u.USW.TxDropped, counter, p.TxDropped, labelP},
{u.USW.TxErrors, prometheus.CounterValue, p.TxErrors, labelP}, {u.USW.TxErrors, counter, p.TxErrors, labelP},
{u.USW.TxMulticast, prometheus.CounterValue, p.TxMulticast, labelP}, {u.USW.TxMulticast, counter, p.TxMulticast, labelP},
{u.USW.TxPackets, prometheus.CounterValue, p.TxPackets, labelP}, {u.USW.TxPackets, counter, p.TxPackets, labelP},
}) })
} }
} }

19
scripts/package-deploy.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# Deploy our built packages to packagecloud.
REPO=dev
[ "$TRAVIS_BRANCH" != "$TRAVIS_TAG" ] || REPO=big
echo "deploying packages from branch: $TRAVIS_BRANCH, tag: $TRAVIS_TAG to repo: $REPO"
source .metadata.sh
# deb
package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_arm64.deb
package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_amd64.deb
package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_armhf.deb
package_cloud push golift/${REPO}/debian/stretch release/unifi-poller_${VERSION}-${ITERATION}_i386.deb
# rpm
package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.arm64.rpm
package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.x86_64.rpm
package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.armhf.rpm
package_cloud push golift/${REPO}/el/5 release/unifi-poller-${VERSION}-${ITERATION}.i386.rpm