From 4bdec1552f8a59759c1a350d7b8c73faa7774fd2 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 2 Dec 2019 18:33:29 +0100 Subject: [PATCH 1/3] Move excess device labels to info metric Move some of the excess device inventory labels to an "info" metric. This reduces query output noise and indexing overhead. These labels can still be used for filtering with a `group_left` query. Signed-off-by: Ben Kochie --- core/poller/pkg/promunifi/uap.go | 16 +++++++++------- core/poller/pkg/promunifi/udm.go | 9 +++++++-- core/poller/pkg/promunifi/usg.go | 4 +++- core/poller/pkg/promunifi/usw.go | 10 ++++++---- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core/poller/pkg/promunifi/uap.go b/core/poller/pkg/promunifi/uap.go index daa19911..7350c01a 100644 --- a/core/poller/pkg/promunifi/uap.go +++ b/core/poller/pkg/promunifi/uap.go @@ -82,8 +82,8 @@ type uap struct { } func descUAP(ns string) *uap { - // labels := []string{"ip", "version", "model", "serial", "type", "mac", "site_name", "name"} - labelA := []string{"stat", "site_name", "name"} // stat + labels[6:] + // labels := []string{"type", "site_name", "name"} + labelA := []string{"stat", "site_name", "name"} // stat + labels[1:] labelV := []string{"vap_name", "bssid", "radio", "radio_name", "essid", "usage", "site_name", "name"} labelR := []string{"radio_name", "radio", "site_name", "name"} return &uap{ @@ -164,9 +164,11 @@ func descUAP(ns string) *uap { } func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { - labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} + labels := []string{d.Type, d.SiteName, d.Name} + infoLabels := []string{d.IP, d.Version, d.Model, d.Serial, d.Mac} // Wireless System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, {u.Device.Uptime, prometheus.GaugeValue, d.Uptime, labels}, {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, @@ -195,8 +197,8 @@ func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap) { // labelA := append([]string{"all"}, labels[2:]...) - labelU := append([]string{"user"}, labels[6:]...) - labelG := append([]string{"guest"}, labels[6:]...) + labelU := append([]string{"user"}, labels[1:]...) + labelG := append([]string{"guest"}, labels[1:]...) r.send([]*metric{ /* // all {u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.WifiTxDropped, labelA}, @@ -253,7 +255,7 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) if !v.Up.Val { continue } - labelV := append([]string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage}, labels[6:]...) + labelV := append([]string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage}, labels[1:]...) r.send([]*metric{ {u.UAP.VAPCcq, prometheus.GaugeValue, float64(v.Ccq) / 1000.0, labelV}, @@ -300,7 +302,7 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) { // radio table for _, p := range rt { - labelR := append([]string{p.Name, p.Radio}, labels[6:]...) + labelR := append([]string{p.Name, p.Radio}, labels[1:]...) r.send([]*metric{ {u.UAP.RadioCurrentAntennaGain, prometheus.GaugeValue, p.CurrentAntennaGain, labelR}, {u.UAP.RadioHt, prometheus.GaugeValue, p.Ht, labelR}, diff --git a/core/poller/pkg/promunifi/udm.go b/core/poller/pkg/promunifi/udm.go index ef251bd4..fa7cbb35 100644 --- a/core/poller/pkg/promunifi/udm.go +++ b/core/poller/pkg/promunifi/udm.go @@ -7,6 +7,7 @@ import ( // These are shared by all four device types: UDM, UAP, USG, USW type unifiDevice struct { + Info *prometheus.Desc Uptime *prometheus.Desc Temperature *prometheus.Desc // sw only TotalMaxPower *prometheus.Desc // sw only @@ -36,8 +37,10 @@ type unifiDevice struct { } func descDevice(ns string) *unifiDevice { - labels := []string{"ip", "version", "model", "serial", "type", "mac", "site_name", "name"} + labels := []string{"type", "site_name", "name"} + infoLabels := []string{"ip", "version", "model", "serial", "mac"} return &unifiDevice{ + Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil), Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil), Temperature: prometheus.NewDesc(ns+"temperature_celsius", "Temperature", labels, nil), TotalMaxPower: prometheus.NewDesc(ns+"max_power_total", "Total Max Power", labels, nil), @@ -69,9 +72,11 @@ func descDevice(ns string) *unifiDevice { // 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) { - labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} + labels := []string{d.Type, d.SiteName, d.Name} + infoLabels := []string{d.IP, d.Version, d.Model, d.Serial, d.Mac} // Dream Machine System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, {u.Device.Uptime, prometheus.GaugeValue, d.Uptime, labels}, {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, diff --git a/core/poller/pkg/promunifi/usg.go b/core/poller/pkg/promunifi/usg.go index 2aaa6e26..28b528e1 100644 --- a/core/poller/pkg/promunifi/usg.go +++ b/core/poller/pkg/promunifi/usg.go @@ -71,9 +71,11 @@ func descUSG(ns string) *usg { } func (u *promUnifi) exportUSG(r report, d *unifi.USG) { - labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} + labels := []string{d.Type, d.SiteName, d.Name} + infoLabels := []string{d.IP, d.Version, d.Model, d.Serial, d.Mac} // Gateway System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, {u.Device.Uptime, prometheus.GaugeValue, d.Uptime, labels}, {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, {u.Device.TotalRxBytes, prometheus.CounterValue, d.RxBytes, labels}, diff --git a/core/poller/pkg/promunifi/usw.go b/core/poller/pkg/promunifi/usw.go index 8d6a1bdf..5048c807 100644 --- a/core/poller/pkg/promunifi/usw.go +++ b/core/poller/pkg/promunifi/usw.go @@ -47,8 +47,8 @@ type usw struct { func descUSW(ns string) *usw { pns := ns + "port_" - // labels := []string{"ip", "version", "model", "serial", "type", "mac", "site_name", "name"} - labelS := []string{"site_name", "name"} // labels[6:] + // labels := []string{"type", "site_name", "name"} + labelS := []string{"site_name", "name"} // labels[1:] labelP := []string{"port_id", "port_num", "port_name", "port_mac", "port_ip", "site_name", "name"} return &usw{ SwRxPackets: prometheus.NewDesc(ns+"switch_receive_packets_total", "Switch Packets Received Total", labelS, nil), @@ -91,7 +91,8 @@ func descUSW(ns string) *usw { } func (u *promUnifi) exportUSW(r report, d *unifi.USW) { - labels := []string{d.IP, d.Version, d.Model, d.Serial, d.Type, d.Mac, d.SiteName, d.Name} + labels := []string{d.Type, d.SiteName, d.Name} + infoLabels := []string{d.IP, d.Version, d.Model, d.Serial, d.Mac} if d.HasTemperature.Val { r.send([]*metric{{u.Device.Temperature, prometheus.GaugeValue, d.GeneralTemperature, labels}}) } @@ -101,6 +102,7 @@ func (u *promUnifi) exportUSW(r report, d *unifi.USW) { // Switch System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, {u.Device.Uptime, prometheus.GaugeValue, d.Uptime, labels}, {u.Device.TotalMaxPower, prometheus.GaugeValue, d.TotalMaxPower, labels}, {u.Device.TotalTxBytes, prometheus.CounterValue, d.TxBytes, labels}, @@ -123,7 +125,7 @@ func (u *promUnifi) exportUSW(r report, d *unifi.USW) { } func (u *promUnifi) exportUSWstats(r report, labels []string, sw *unifi.Sw) { - labelS := labels[6:] + labelS := labels[1:] r.send([]*metric{ {u.USW.SwRxPackets, prometheus.CounterValue, sw.RxPackets, labelS}, {u.USW.SwRxBytes, prometheus.CounterValue, sw.RxBytes, labelS}, From 3085f73cce7fc94a57dce6a0d76bf503fb88d430 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 2 Dec 2019 22:28:51 +0100 Subject: [PATCH 2/3] Use explicit label items rather than a cut of the slice. Signed-off-by: Ben Kochie --- core/poller/pkg/promunifi/uap.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/poller/pkg/promunifi/uap.go b/core/poller/pkg/promunifi/uap.go index 7350c01a..7cae0c4a 100644 --- a/core/poller/pkg/promunifi/uap.go +++ b/core/poller/pkg/promunifi/uap.go @@ -197,8 +197,8 @@ func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { func (u *promUnifi) exportUAPstats(r report, labels []string, ap *unifi.Ap) { // labelA := append([]string{"all"}, labels[2:]...) - labelU := append([]string{"user"}, labels[1:]...) - labelG := append([]string{"guest"}, labels[1:]...) + labelU := []string{"user", labels[1], labels[2]} + labelG := []string{"guest", labels[1], labels[2]} r.send([]*metric{ /* // all {u.UAP.ApWifiTxDropped, prometheus.CounterValue, ap.WifiTxDropped, labelA}, @@ -255,7 +255,7 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) if !v.Up.Val { continue } - labelV := append([]string{v.Name, v.Bssid, v.Radio, v.RadioName, v.Essid, v.Usage}, labels[1:]...) + 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}, @@ -302,7 +302,7 @@ func (u *promUnifi) exportVAPtable(r report, labels []string, vt unifi.VapTable) func (u *promUnifi) exportRadtable(r report, labels []string, rt unifi.RadioTable, rts unifi.RadioTableStats) { // radio table for _, p := range rt { - labelR := append([]string{p.Name, p.Radio}, labels[1:]...) + labelR := []string{p.Name, p.Radio, labels[1], labels[2]} r.send([]*metric{ {u.UAP.RadioCurrentAntennaGain, prometheus.GaugeValue, p.CurrentAntennaGain, labelR}, {u.UAP.RadioHt, prometheus.GaugeValue, p.Ht, labelR}, From 43ad96ae8d4fa49af481f9e844195f523db3bbe9 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 2 Dec 2019 23:34:49 +0100 Subject: [PATCH 3/3] Remove IP address from device info label. Signed-off-by: Ben Kochie --- core/poller/pkg/promunifi/uap.go | 2 +- core/poller/pkg/promunifi/udm.go | 4 ++-- core/poller/pkg/promunifi/usg.go | 4 ++-- core/poller/pkg/promunifi/usw.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/poller/pkg/promunifi/uap.go b/core/poller/pkg/promunifi/uap.go index 7cae0c4a..8711bb4f 100644 --- a/core/poller/pkg/promunifi/uap.go +++ b/core/poller/pkg/promunifi/uap.go @@ -165,7 +165,7 @@ 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.IP, d.Version, d.Model, d.Serial, d.Mac} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac} // Wireless System Data. r.send([]*metric{ {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, diff --git a/core/poller/pkg/promunifi/udm.go b/core/poller/pkg/promunifi/udm.go index fa7cbb35..78899ed8 100644 --- a/core/poller/pkg/promunifi/udm.go +++ b/core/poller/pkg/promunifi/udm.go @@ -38,7 +38,7 @@ type unifiDevice struct { func descDevice(ns string) *unifiDevice { labels := []string{"type", "site_name", "name"} - infoLabels := []string{"ip", "version", "model", "serial", "mac"} + infoLabels := []string{"version", "model", "serial", "mac"} return &unifiDevice{ Info: prometheus.NewDesc(ns+"info", "Device Information", append(labels, infoLabels...), nil), Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil), @@ -73,7 +73,7 @@ func descDevice(ns string) *unifiDevice { // 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) { labels := []string{d.Type, d.SiteName, d.Name} - infoLabels := []string{d.IP, d.Version, d.Model, d.Serial, d.Mac} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac} // Dream Machine System Data. r.send([]*metric{ {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, diff --git a/core/poller/pkg/promunifi/usg.go b/core/poller/pkg/promunifi/usg.go index 28b528e1..a33cb7e2 100644 --- a/core/poller/pkg/promunifi/usg.go +++ b/core/poller/pkg/promunifi/usg.go @@ -36,7 +36,7 @@ type usg struct { } func descUSG(ns string) *usg { - // labels := []string{"ip", "version", "model", "serial", "type", "mac", "site_name", "name"} + // labels := []string{"version", "model", "serial", "type", "mac", "site_name", "name"} // labelWan := append([]string{"port"}, labels[6:]...) labels := []string{"port", "site_name", "name"} return &usg{ @@ -72,7 +72,7 @@ func descUSG(ns string) *usg { func (u *promUnifi) exportUSG(r report, d *unifi.USG) { labels := []string{d.Type, d.SiteName, d.Name} - infoLabels := []string{d.IP, d.Version, d.Model, d.Serial, d.Mac} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac} // Gateway System Data. r.send([]*metric{ {u.Device.Info, prometheus.GaugeValue, 1.0, append(labels, infoLabels...)}, diff --git a/core/poller/pkg/promunifi/usw.go b/core/poller/pkg/promunifi/usw.go index 5048c807..94b810aa 100644 --- a/core/poller/pkg/promunifi/usw.go +++ b/core/poller/pkg/promunifi/usw.go @@ -92,7 +92,7 @@ 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.IP, d.Version, d.Model, d.Serial, d.Mac} + infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac} if d.HasTemperature.Val { r.send([]*metric{{u.Device.Temperature, prometheus.GaugeValue, d.GeneralTemperature, labels}}) }