-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
353 lines (312 loc) · 11.8 KB
/
server.js
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
#!/usr/bin/env node
var debug = require( 'debug' )( 'app:main' );
var express = require( 'express' );
var server = express();
var promclient = require( 'prom-client' );
var async = require( 'async' );
var config = require( './config.json' );
var livebox = require( 'livebox-collect' )( config.hostname, config.login, config.password );
var livebox_device_info = new promclient.Gauge({
name: 'livebox_device_info',
help: "A metric with a constant '1' value labeled by several modem characteristics",
labelNames: [
'Manufacturer',
'ModelName',
'ProductClass',
'SerialNumber',
'HardwareVersion',
'SoftwareVersion',
'AdditionalHardwareVersion',
'AdditionalSoftwareVersion',
'RescueVersion',
'ProvisioningCode',
'BaseMAC',
'ExternalIPAddress',
'AdditionalSoftwareVersion',
'HardwareVersion',
'Bootloader',
'RescueBootloader',
'DeviceStatus'
]
});
var livebox_dsl_info = new promclient.Gauge({
name: 'livebox_dsl_info',
help: "A metric with a constant '1' value labeled by several DSL characteristics",
labelNames: [
'StandardUsed',
'StandardsSupported',
'CurrentProfile',
'ModulationHint',
'ModulationType',
'ChannelEncapsulationType',
'DataPath',
'LinkStatus'
]
});
var livebox_mibs_dsl0_bitspersecond = new promclient.Gauge({
name: 'livebox_mibs_dsl0_bitspersecond',
help: 'DSL synchronisation rate labeled by direction and type',
labelNames: [
'SerialNumber',
'type',
'direction'
]
});
var livebox_dslstat_errors_total = new promclient.Gauge({
name: 'livebox_dslstat_errors_total',
help: 'Total number of DSL errors observed labeled by type (FEC, CRC and HEC) and extremity (ATUC=Central and ATUR=remote, modem)',
labelNames: [
'SerialNumber',
'type',
'extremity'
]
});
var livebox_dslstat_erroredseconds_total = new promclient.Gauge({
name: 'livebox_dslstat_erroredseconds_total',
help: 'Total number of errored seconds labeled by severity',
labelNames: [
'SerialNumber',
'severity'
]
});
var livebox_dslstat_blocks_total = new promclient.Gauge({
name: 'livebox_dslstat_blocks_total',
help: 'Total number of DSL blocks exchanged, labeled by type',
labelNames: [
'SerialNumber',
'type'
]
});
var livebox_dslstat_loss_of_framing_total = new promclient.Gauge({
name: 'livebox_dslstat_loss_of_framing_total',
help: 'Total number of loss of framing observed',
labelNames: [
'SerialNumber'
]
});
var livebox_mibs_dsl0_upbokle_decibels = new promclient.Gauge({
name: 'livebox_mibs_dsl0_upbokle_decibels',
help: 'Example of a gauge',
labelNames: [
'SerialNumber'
]
});
var livebox_mibs_dsl0_power_decibelmilliwatts = new promclient.Gauge({
name: 'livebox_mibs_dsl0_power_decibelmilliwatts',
help: 'The amount of power transmitted from the exchange and the modem.',
labelNames: [
'SerialNumber',
'direction'
]
});
var livebox_mibs_dsl0_noisemargin_decibels = new promclient.Gauge({
name: 'livebox_mibs_dsl0_noisemargin_decibels',
help: 'Example of a gauge',
labelNames: [
'SerialNumber',
'direction'
]
});
var livebox_mibs_dsl0_attenuation_decibels = new promclient.Gauge({
name: 'livebox_mibs_dsl0_attenuation_decibels',
help: 'The degradation of signal over distance',
labelNames: [
'SerialNumber',
'type',
'direction'
]
});
var livebox_reboots_total = new promclient.Gauge({
name: 'livebox_reboot_total',
help: 'Total number of reboots since last reset',
labelNames: [
'SerialNumber'
]
});
var livebox_uptime_seconds_total = new promclient.Gauge({
name: 'livebox_uptime_seconds_total',
help: 'Total seconds of device uptime',
labelNames: [
'SerialNumber'
]
});
function collect() {
livebox.connect( function( err ) {
if( err ) {
console.error( 'Auth error:', err );
process.exit( 1 );
}
async.parallel({
'deviceInfo' : function( callback ) {
livebox.deviceInfo( function( err, data ) {
callback( err, data.status );
});
},
'getDSLStats' : function( callback ) {
livebox.getDSLStats( function( err, data ) {
callback( err, data.status );
});
},
'getMibs-dsl' : function( callback ) {
livebox.getMibs( 'dsl', function( err, data ) {
callback( err, data.status.dsl );
});
}
}, function( err, result ) {
if( err ) {
console.error( err );
return;
}
debug( result );
livebox_device_info.set({
'Manufacturer' : result.deviceInfo.Manufacturer,
'ModelName' : result.deviceInfo.ModelName,
'ProductClass' : result.deviceInfo.ProductClass,
'SerialNumber' : result.deviceInfo.SerialNumber,
'HardwareVersion' : result.deviceInfo.HardwareVersion,
'SoftwareVersion' : result.deviceInfo.SoftwareVersion,
'AdditionalHardwareVersion' : result.deviceInfo.AdditionalHardwareVersion,
'AdditionalSoftwareVersion' : result.deviceInfo.AdditionalSoftwareVersion,
'Bootloader' : result.deviceInfo['X_SOFTATHOME-COM_AdditionalSoftwareVersions'],
'RescueBootloader' : result.deviceInfo['X_SOFTATHOME-COM_AdditionalSoftwareVersions'],
'RescueVersion' : result.deviceInfo.RescueVersion,
'ProvisioningCode' : result.deviceInfo.ProvisioningCode,
'BaseMAC' : result.deviceInfo.BaseMAC,
'ExternalIPAddress' : result.deviceInfo.ExternalIPAddress,
'HardwareVersion' : result.deviceInfo.HardwareVersion,
'DeviceStatus' : result.deviceInfo.DeviceStatus
}, 1 )
livebox_dsl_info.set({
'StandardUsed' : result['getMibs-dsl'].dsl0.StandardUsed,
'StandardsSupported' : result['getMibs-dsl'].dsl0.StandardsSupported,
'CurrentProfile' : result['getMibs-dsl'].dsl0.CurrentProfile,
'ModulationType' : result['getMibs-dsl'].dsl0.ModulationType,
'ModulationHint' : result['getMibs-dsl'].dsl0.ModulationHint,
'ChannelEncapsulationType' : result['getMibs-dsl'].dsl0.ChannelEncapsulationType,
'DataPath' : result['getMibs-dsl'].dsl0.DataPath,
'LinkStatus' : result['getMibs-dsl'].dsl0.LinkStatus
}, 1 )
livebox_reboots_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber
}, result.deviceInfo.NumberOfReboots )
livebox_uptime_seconds_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber
}, result.deviceInfo.UpTime )
livebox_mibs_dsl0_bitspersecond.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'upstream',
'type' : 'current'
}, result['getMibs-dsl'].dsl0.UpstreamCurrRate )
livebox_mibs_dsl0_bitspersecond.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'downstream',
'type' : 'current'
}, result['getMibs-dsl'].dsl0.DownstreamCurrRate )
livebox_mibs_dsl0_bitspersecond.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'upstream',
'type' : 'max'
}, result['getMibs-dsl'].dsl0.UpstreamMaxRate )
livebox_mibs_dsl0_bitspersecond.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'downstream',
'type' : 'max'
}, result['getMibs-dsl'].dsl0.DownstreamMaxRate )
livebox_dslstat_errors_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'FEC',
'extremity' : 'ATUR'
}, result.getDSLStats.FECErrors )
livebox_dslstat_errors_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'FEC',
'extremity' : 'ATUC'
}, result.getDSLStats.ATUCFECErrors )
livebox_dslstat_errors_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'HEC',
'extremity' : 'ATUR'
}, result.getDSLStats.HECErrors )
livebox_dslstat_errors_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'HEC',
'extremity' : 'ATUC'
}, result.getDSLStats.ATUCHECErrors )
livebox_dslstat_errors_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'CRC',
'extremity' : 'ATUR'
}, result.getDSLStats.CRCErrors )
livebox_dslstat_errors_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'CRC',
'extremity' : 'ATUC'
}, result.getDSLStats.ATUCCRCErrors )
livebox_dslstat_erroredseconds_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'severity' : 'severe'
}, result.getDSLStats.SeverelyErroredSecs )
livebox_dslstat_erroredseconds_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'severity' : 'minor'
}, result.getDSLStats.ErroredSecs )
livebox_dslstat_blocks_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'receive'
}, result.getDSLStats.ReceiveBlocks )
livebox_dslstat_blocks_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'transmit'
}, result.getDSLStats.TransmitBlocks )
livebox_dslstat_loss_of_framing_total.set({
'SerialNumber' : result.deviceInfo.SerialNumber
}, result.getDSLStats.LossOfFraming )
livebox_mibs_dsl0_upbokle_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber
}, result['getMibs-dsl'].dsl0.UPBOKLE / 10 )
livebox_mibs_dsl0_power_decibelmilliwatts.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'downstream'
}, result['getMibs-dsl'].dsl0.DownstreamPower / 10 )
livebox_mibs_dsl0_power_decibelmilliwatts.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'upstream'
}, result['getMibs-dsl'].dsl0.UpstreamPower / 10 )
livebox_mibs_dsl0_noisemargin_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'downstream'
}, result['getMibs-dsl'].dsl0.DownstreamNoiseMargin / 10 )
livebox_mibs_dsl0_noisemargin_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'direction' : 'upstream'
}, result['getMibs-dsl'].dsl0.UpstreamNoiseMargin / 10 )
livebox_mibs_dsl0_attenuation_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'signal',
'direction' : 'downstream'
}, result['getMibs-dsl'].dsl0.DownstreamAttenuation / 10 )
livebox_mibs_dsl0_attenuation_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'signal',
'direction' : 'upstream'
}, result['getMibs-dsl'].dsl0.UpstreamAttenuation / 10 )
livebox_mibs_dsl0_attenuation_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'line',
'direction' : 'downstream'
}, result['getMibs-dsl'].dsl0.DownstreamLineAttenuation / 10 )
livebox_mibs_dsl0_attenuation_decibels.set({
'SerialNumber' : result.deviceInfo.SerialNumber,
'type' : 'line',
'direction' : 'upstream'
}, result['getMibs-dsl'].dsl0.UpstreamLineAttenuation / 10 )
})
})
}
setInterval( collect, 10000 );
server.get('/metrics', function ( req, res ) {
res.set( 'Content-Type', promclient.register.contentType );
res.end( promclient.register.metrics() );
});
console.log('Server listening to 9446, metrics exposed on /metrics endpoint');
server.listen( 9446 );