-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollector_cm.go
386 lines (341 loc) · 12.3 KB
/
collector_cm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package main
import (
"context"
"fmt"
"log/slog"
"strconv"
hitron "github.com/hairyhenderson/hitron_coda"
"github.com/prometheus/client_golang/prometheus"
)
// cmCollector tracks interesting metrics from the hitron CM* APIs
type cmCollector struct {
ctx context.Context
client func() *hitron.CableModem
sysInfo struct {
usDataRate prometheus.Gauge
dsDataRate prometheus.Gauge
dhcpLeaseSeconds *prometheus.GaugeVec
}
dsInfo struct {
frequency *prometheus.GaugeVec
signalStrength *prometheus.GaugeVec
snr *prometheus.GaugeVec
receivedBytes *prometheus.CounterVec
corrected *prometheus.CounterVec
uncorrected *prometheus.CounterVec
}
usInfo struct {
frequency *prometheus.GaugeVec
signalStrength *prometheus.GaugeVec
bandwidth *prometheus.GaugeVec
}
dsOfdm struct {
subcarrierFreq *prometheus.GaugeVec
plcPower *prometheus.GaugeVec
}
usOfdm struct {
digAtten *prometheus.GaugeVec
digAttenBo *prometheus.GaugeVec
channelBw *prometheus.GaugeVec
repPower *prometheus.GaugeVec
targetPower *prometheus.GaugeVec
}
versionInfo *prometheus.GaugeVec
}
//nolint:funlen
func newCMCollector(ctx context.Context, clientProvider func() *hitron.CableModem) cmCollector {
c := cmCollector{ctx: ctx, client: clientProvider}
sub := "cm"
c.sysInfo.usDataRate = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_data_rate_bytes_per_second",
Help: "WAN upstream data rate, in bytes per second",
})
c.sysInfo.dsDataRate = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_data_rate_bytes_per_second",
Help: "WAN downstream data rate, in bytes per second",
})
c.sysInfo.dhcpLeaseSeconds = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "dhcp_lease_duration_seconds",
Help: "Lease duration for DHCP on WAN interface",
}, []string{"ip", "mac_addr"})
portInfoLabels := []string{"port", "channel", "modulation"}
c.dsInfo.frequency = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_frequency_hertz",
Help: "Downstream port frequency",
}, portInfoLabels)
c.dsInfo.signalStrength = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_signal_strength_dbmv",
Help: "Downstream data channel signal strength, in dBmV (decibels above/below 1 millivolt)",
}, portInfoLabels)
c.dsInfo.snr = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_signal_noise_ratio_db",
Help: "Downstream data channel signal-to-noise ratio, in dB",
}, portInfoLabels)
c.dsInfo.receivedBytes = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_received_bytes",
Help: "Number of octets/bytes received",
}, portInfoLabels)
c.dsInfo.corrected = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_corrected_blocks",
Help: "Number of blocks received that required correction due to corruption, and were corrected",
}, portInfoLabels)
c.dsInfo.uncorrected = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_uncorrected_blocks",
Help: "Number of blocks received that required correction due to corruption, but were unable to be corrected",
}, portInfoLabels)
c.usInfo.frequency = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_frequency_hertz",
Help: "Upstream port frequency",
}, portInfoLabels)
c.usInfo.signalStrength = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_signal_strength_dbmv",
Help: "Upstream data channel signal strength, in dBmV (decibels above/below 1 millivolt)",
}, portInfoLabels)
c.usInfo.bandwidth = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_bandwidth_bytes_per_second",
Help: "Upstream data channel bandwidth, in bytes per second",
}, portInfoLabels)
dsOfdmLabels := []string{"receiver", "fft_type"}
c.dsOfdm.subcarrierFreq = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_ofdm_subcarrier_freq_hertz",
Help: "Downstream frequency in Hz of the first OFDM subcarrier",
}, dsOfdmLabels)
c.dsOfdm.plcPower = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "downstream_ofdm_plc_power_dbmv",
Help: "Power level device was instructed to use on this OFDM connection by the Physical Link Channel, in dB above/below 1mV",
}, dsOfdmLabels)
usOfdmLabels := []string{"channel", "enabled", "fft_size"}
c.usOfdm.digAtten = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_ofdm_digital_attenuation_db",
Help: "The digital attenuation (signal loss) of the transmission medium on which the channel's signal is carried, in decibels (dB).",
}, usOfdmLabels)
c.usOfdm.digAttenBo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_ofdm_measured_digital_attenuation_db",
Help: "The measured digital attenuation of the channel's signal, in decibels (dB).",
}, usOfdmLabels)
c.usOfdm.channelBw = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_ofdm_channel_bandwidth_hz",
Help: "Bandwidth of this channel, expressed as the number of subchannels multiplied by the channel's FFT size, in hertz (Hz).",
}, usOfdmLabels)
c.usOfdm.repPower = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_ofdm_reported_power_qdbmv",
Help: "Reported power of this channel, in quarter-dB above/below 1mV (quarter-dBmV).",
}, usOfdmLabels)
c.usOfdm.targetPower = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "upstream_ofdm_target_power_qdbmv",
Help: "Target power (P1.6r_n, or power spectral density in 1.6MHz) of this channel, in quarter-dB above/below 1mV (quarter-dBmV).",
}, usOfdmLabels)
c.versionInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNS,
Subsystem: sub,
Name: "version_info",
Help: "A metric with a constant '1' value labeled by various version information.",
}, []string{"device_id", "model", "vendor", "serial", "hw_version", "api_version", "sw_version"})
return c
}
// Describe implements Prometheus.Collector.
func (c cmCollector) Describe(ch chan<- *prometheus.Desc) {
c.sysInfo.usDataRate.Describe(ch)
c.sysInfo.dsDataRate.Describe(ch)
c.sysInfo.dhcpLeaseSeconds.Describe(ch)
c.dsInfo.frequency.Describe(ch)
c.dsInfo.signalStrength.Describe(ch)
c.dsInfo.snr.Describe(ch)
c.dsInfo.receivedBytes.Describe(ch)
c.dsInfo.corrected.Describe(ch)
c.dsInfo.uncorrected.Describe(ch)
c.usInfo.frequency.Describe(ch)
c.usInfo.signalStrength.Describe(ch)
c.usInfo.bandwidth.Describe(ch)
c.dsOfdm.plcPower.Describe(ch)
c.dsOfdm.subcarrierFreq.Describe(ch)
c.usOfdm.channelBw.Describe(ch)
c.usOfdm.digAtten.Describe(ch)
c.usOfdm.digAttenBo.Describe(ch)
c.usOfdm.repPower.Describe(ch)
c.usOfdm.targetPower.Describe(ch)
c.versionInfo.Describe(ch)
}
// Collect implements Prometheus.Collector.
func (c cmCollector) Collect(ch chan<- prometheus.Metric) {
client := c.client()
if client == nil {
err := fmt.Errorf("client not initialized: %v", client)
slog.ErrorContext(c.ctx, "Error scraping target", slog.Any("err", err))
exporterClientErrors.Inc()
return
}
c.collectSysInfo(ch, client)
c.collectDsInfo(ch, client)
c.collectUsInfo(ch, client)
c.collectOfdm(ch, client)
c.collectVersionInfo(ch, client)
}
func (c cmCollector) collectVersionInfo(ch chan<- prometheus.Metric, client *hitron.CableModem) {
vi, err := client.CMVersion(c.ctx)
if err != nil {
slog.ErrorContext(c.ctx, "Error scraping CMVersion", slog.Any("err", err))
exporterRequestErrors.Inc()
return
}
l := prometheus.Labels{
"device_id": vi.DeviceID,
"model": vi.ModelName,
"vendor": vi.VendorName,
"serial": vi.SerialNum,
"hw_version": vi.HwVersion,
"api_version": vi.APIVersion,
"sw_version": vi.SoftwareVersion,
}
c.versionInfo.With(l).Set(1)
c.versionInfo.Collect(ch)
}
func (c cmCollector) collectSysInfo(ch chan<- prometheus.Metric, client *hitron.CableModem) {
si, err := client.CMSysInfo(c.ctx)
if err != nil {
slog.ErrorContext(c.ctx, "Error scraping CMSysInfo", slog.Any("err", err))
exporterRequestErrors.Inc()
return
}
// bytes not bits
//nolint:gomnd
c.sysInfo.usDataRate.Set(float64(si.UsDataRate) / 8)
c.sysInfo.usDataRate.Collect(ch)
// bytes not bits
//nolint:gomnd
c.sysInfo.dsDataRate.Set(float64(si.DsDataRate) / 8)
c.sysInfo.dsDataRate.Collect(ch)
c.sysInfo.dhcpLeaseSeconds.
WithLabelValues(si.IP.String(), si.MacAddr.String()).
Set(si.Lease.Seconds())
c.sysInfo.dhcpLeaseSeconds.Collect(ch)
}
func (c cmCollector) collectDsInfo(ch chan<- prometheus.Metric, client *hitron.CableModem) {
dsinfo, err := client.CMDsInfo(c.ctx)
if err != nil {
slog.ErrorContext(c.ctx, "Error scraping CMDsInfo", slog.Any("err", err))
exporterRequestErrors.Inc()
return
}
for _, port := range dsinfo.Ports {
l := prometheus.Labels{
"port": port.PortID,
"channel": port.ChannelID,
"modulation": port.Modulation,
}
c.dsInfo.frequency.With(l).Set(float64(port.Frequency))
c.dsInfo.signalStrength.With(l).Set(port.SignalStrength)
c.dsInfo.snr.With(l).Set(port.SNR)
c.dsInfo.receivedBytes.With(l).Add(float64(port.DsOctets))
c.dsInfo.corrected.With(l).Add(float64(port.Correcteds))
c.dsInfo.uncorrected.With(l).Add(float64(port.Uncorrect))
}
c.dsInfo.frequency.Collect(ch)
c.dsInfo.signalStrength.Collect(ch)
c.dsInfo.snr.Collect(ch)
c.dsInfo.receivedBytes.Collect(ch)
c.dsInfo.corrected.Collect(ch)
c.dsInfo.uncorrected.Collect(ch)
}
func (c cmCollector) collectUsInfo(ch chan<- prometheus.Metric, client *hitron.CableModem) {
usinfo, err := client.CMUsInfo(c.ctx)
if err != nil {
slog.ErrorContext(c.ctx, "Error scraping CMUsInfo", slog.Any("err", err))
exporterRequestErrors.Inc()
return
}
for _, port := range usinfo.Ports {
l := prometheus.Labels{
"port": port.PortID,
"channel": port.ChannelID,
"modulation": port.Modulation,
}
c.usInfo.frequency.With(l).Set(float64(port.Frequency))
c.usInfo.signalStrength.With(l).Set(port.SignalStrength)
// we want bytes/sec here, not bits/sec
//nolint:gomnd
c.usInfo.bandwidth.With(l).Set(float64(port.Bandwidth) / 8)
}
c.usInfo.frequency.Collect(ch)
c.usInfo.signalStrength.Collect(ch)
c.usInfo.bandwidth.Collect(ch)
}
func (c cmCollector) collectOfdm(ch chan<- prometheus.Metric, client *hitron.CableModem) {
usofdm, err := client.CMUsOfdm(c.ctx)
if err != nil {
slog.ErrorContext(c.ctx, "Error scraping CMUsOfdm", slog.Any("err", err))
exporterRequestErrors.Inc()
} else {
for _, channel := range usofdm.Channels {
l := prometheus.Labels{
"channel": strconv.Itoa(channel.ID),
"enabled": strconv.FormatBool(channel.Enable),
"fft_size": channel.FFTSize,
}
c.usOfdm.channelBw.With(l).Set(channel.ChannelBw)
c.usOfdm.digAtten.With(l).Set(channel.DigAtten)
c.usOfdm.digAttenBo.With(l).Set(channel.DigAttenBo)
c.usOfdm.repPower.With(l).Set(channel.RepPower)
c.usOfdm.targetPower.With(l).Set(channel.RepPower1_6)
}
c.usOfdm.channelBw.Collect(ch)
c.usOfdm.digAtten.Collect(ch)
c.usOfdm.digAttenBo.Collect(ch)
c.usOfdm.repPower.Collect(ch)
c.usOfdm.targetPower.Collect(ch)
}
dsofdm, err := client.CMDsOfdm(c.ctx)
if err != nil {
slog.ErrorContext(c.ctx, "Error scraping CMDsOfdm", slog.Any("err", err))
exporterRequestErrors.Inc()
} else {
for _, receiver := range dsofdm.Receivers {
l := prometheus.Labels{
"receiver": strconv.Itoa(receiver.ID),
"fft_type": receiver.FFTType,
}
c.dsOfdm.plcPower.With(l).Set(receiver.PLCPower)
c.dsOfdm.subcarrierFreq.With(l).Set(float64(receiver.SubcarrierFreq))
}
c.dsOfdm.plcPower.Collect(ch)
c.dsOfdm.subcarrierFreq.Collect(ch)
}
}