diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index 3aa107ae..c537632e 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -80,8 +80,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{ @@ -160,9 +160,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.Version, d.Model, d.Serial, d.Mac} // Wireless System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, d.Uptime, 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}, @@ -190,8 +192,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 := []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}, @@ -248,7 +250,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 := []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}, @@ -295,7 +297,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 := []string{p.Name, p.Radio, labels[1], labels[2]} labelRUser := append(labelR, "user") labelRGuest := append(labelR, "guest") r.send([]*metric{ diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index be23f485..53ade3ac 100644 --- a/pkg/promunifi/udm.go +++ b/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 @@ -34,8 +35,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{"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), @@ -65,11 +68,13 @@ 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.Version, d.Model, d.Serial, d.Mac} labelsGuest := append(labels, "guest") labelsUser := append(labels, "user") // Dream Machine System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, d.Uptime, 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/pkg/promunifi/usg.go b/pkg/promunifi/usg.go index 57c36166..abc09bbe 100644 --- a/pkg/promunifi/usg.go +++ b/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{ @@ -71,11 +71,13 @@ 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.Version, d.Model, d.Serial, d.Mac} labelsUser := append(labels, "user") labelsGuest := append(labels, "guest") // Gateway System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, d.Uptime, 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}, @@ -99,8 +101,8 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) { } func (u *promUnifi) exportUSGstats(r report, labels []string, gw *unifi.Gw, st unifi.SpeedtestStatus, ul unifi.Uplink) { - labelLan := []string{"lan", labels[6], labels[7]} - labelWan := []string{"all", labels[6], labels[7]} + 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}, @@ -130,7 +132,7 @@ func (u *promUnifi) exportWANPorts(r report, labels []string, wans ...unifi.Wan) if !wan.Up.Val { continue // only record UP interfaces. } - labelWan := []string{wan.Name, labels[6], labels[7]} + 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}, diff --git a/pkg/promunifi/usw.go b/pkg/promunifi/usw.go index 4bf76f99..76e0f737 100644 --- a/pkg/promunifi/usw.go +++ b/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,9 @@ 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.Version, d.Model, d.Serial, d.Mac} labelsGuest := append(labels, "guest") labelsUser := append(labels, "user") if d.HasTemperature.Val { @@ -103,6 +105,7 @@ func (u *promUnifi) exportUSW(r report, d *unifi.USW) { // Switch System Data. r.send([]*metric{ + {u.Device.Info, prometheus.GaugeValue, d.Uptime, 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}, @@ -124,7 +127,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}, @@ -152,7 +155,7 @@ func (u *promUnifi) exportPortTable(r report, labels []string, pt []unifi.Port) continue } // Copy labels, and add four new ones. - labelP := []string{labels[7] + " Port " + p.PortIdx.Txt, p.PortIdx.Txt, p.Name, p.Mac, p.IP, labels[6], labels[7]} + 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},