@@ -9,9 +9,20 @@ import (
9
9
"gopkg.in/routeros.v2/proto"
10
10
)
11
11
12
+ // from https://forum.mikrotik.com/viewtopic.php?t=195124#p999722:
13
+ // wifiwave2 is an implementation of drivers from the manufacturer of the
14
+ // chipset, rather than an in-house written driver (which wireless is). So
15
+ // there are many small details that are missing or incomplete...
16
+
12
17
type wlanSTACollector struct {
13
- props []string
14
- descriptions map [string ]* prometheus.Desc
18
+ // Both wifiwave2 and wireless have a similar, yet different API. They also
19
+ // expose a slightly different set of properties.
20
+ props []string
21
+ propsWirelessExtra []string
22
+ propsWirelessRXTX []string
23
+ propsWifiwave2Extra []string
24
+ propsWifiwave2RXTX []string
25
+ descriptions map [string ]* prometheus.Desc
15
26
}
16
27
17
28
func newWlanSTACollector () routerOSCollector {
@@ -21,13 +32,28 @@ func newWlanSTACollector() routerOSCollector {
21
32
}
22
33
23
34
func (c * wlanSTACollector ) init () {
24
- c .props = []string {"interface" , "mac-address" , "signal-to-noise" , "signal-strength" , "packets" , "bytes" , "frames" }
35
+ // common properties
36
+ c .props = []string {"interface" , "mac-address" }
37
+ // wifiwave2 doesn't expose SNR, and uses different name for signal-strength
38
+ c .propsWirelessExtra = []string {"signal-to-noise" , "signal-strength" }
39
+ // wireless exposes extra field "frames", not available in wifiwave2
40
+ c .propsWirelessRXTX = []string {"packets" , "bytes" , "frames" }
41
+ c .propsWifiwave2Extra = []string {"signal" }
42
+ c .propsWifiwave2RXTX = []string {"packets" , "bytes" }
43
+ // all metrics have the same label names
25
44
labelNames := []string {"name" , "address" , "interface" , "mac_address" }
26
45
c .descriptions = make (map [string ]* prometheus.Desc )
27
- for _ , p := range c .props [: len ( c . props ) - 3 ] {
46
+ for _ , p := range c .propsWirelessExtra {
28
47
c .descriptions [p ] = descriptionForPropertyName ("wlan_station" , p , labelNames )
29
48
}
30
- for _ , p := range c .props [len (c .props )- 3 :] {
49
+ // normalize the metric name 'signal-strength' for the property "signal", so that dashboards
50
+ // that capture both wireless and wifiwave2 devices don't need to normalize
51
+ c .descriptions ["signal" ] = descriptionForPropertyName ("wlan_station" , "signal-strength" , labelNames )
52
+ for _ , p := range c .propsWirelessRXTX {
53
+ c .descriptions ["tx_" + p ] = descriptionForPropertyName ("wlan_station" , "tx_" + p , labelNames )
54
+ c .descriptions ["rx_" + p ] = descriptionForPropertyName ("wlan_station" , "rx_" + p , labelNames )
55
+ }
56
+ for _ , p := range c .propsWifiwave2RXTX {
31
57
c .descriptions ["tx_" + p ] = descriptionForPropertyName ("wlan_station" , "tx_" + p , labelNames )
32
58
c .descriptions ["rx_" + p ] = descriptionForPropertyName ("wlan_station" , "rx_" + p , labelNames )
33
59
}
@@ -53,7 +79,25 @@ func (c *wlanSTACollector) collect(ctx *collectorContext) error {
53
79
}
54
80
55
81
func (c * wlanSTACollector ) fetch (ctx * collectorContext ) ([]* proto.Sentence , error ) {
56
- reply , err := ctx .client .Run ("/interface/wireless/registration-table/print" , "=.proplist=" + strings .Join (c .props , "," ))
82
+ var cmd []string
83
+ var props []string = c .props
84
+ if ctx .device .Wifiwave2 {
85
+ props = append (props , c .propsWifiwave2Extra ... )
86
+ props = append (props , c .propsWifiwave2RXTX ... )
87
+ cmd = []string {
88
+ "/interface/wifiwave2/registration-table/print" ,
89
+ "=.proplist=" + strings .Join (props , "," ),
90
+ }
91
+ } else {
92
+ props = append (props , c .propsWirelessExtra ... )
93
+ props = append (props , c .propsWirelessRXTX ... )
94
+ cmd = []string {
95
+ "/interface/wireless/registration-table/print" ,
96
+ "=.proplist=" + strings .Join (props , "," ),
97
+ }
98
+ }
99
+ log .Debugf ("Running collector command: %s" , cmd )
100
+ reply , err := ctx .client .Run (cmd ... )
57
101
if err != nil {
58
102
log .WithFields (log.Fields {
59
103
"device" : ctx .device .Name ,
@@ -69,11 +113,20 @@ func (c *wlanSTACollector) collectForStat(re *proto.Sentence, ctx *collectorCont
69
113
iface := re .Map ["interface" ]
70
114
mac := re .Map ["mac-address" ]
71
115
72
- for _ , p := range c .props [2 : len (c .props )- 3 ] {
73
- c .collectMetricForProperty (p , iface , mac , re , ctx )
74
- }
75
- for _ , p := range c .props [len (c .props )- 3 :] {
76
- c .collectMetricForTXRXCounters (p , iface , mac , re , ctx )
116
+ if ctx .device .Wifiwave2 {
117
+ for _ , p := range c .propsWifiwave2Extra {
118
+ c .collectMetricForProperty (p , iface , mac , re , ctx )
119
+ }
120
+ for _ , p := range c .propsWifiwave2RXTX {
121
+ c .collectMetricForTXRXCounters (p , iface , mac , re , ctx )
122
+ }
123
+ } else {
124
+ for _ , p := range c .propsWirelessExtra {
125
+ c .collectMetricForProperty (p , iface , mac , re , ctx )
126
+ }
127
+ for _ , p := range c .propsWirelessRXTX {
128
+ c .collectMetricForTXRXCounters (p , iface , mac , re , ctx )
129
+ }
77
130
}
78
131
}
79
132
0 commit comments