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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
|
'use strict';
// SPDX-License-Identifier: GPL-3.0-or-later
// collect statistics from bind (named) v9.10+
//
// bind statistics documentation at:
// http://jpmens.net/2013/03/18/json-in-bind-9-s-statistics-server/
// https://ftp.isc.org/isc/bind/9.10.3/doc/arm/Bv9ARM.ch06.html#statistics
// example configuration in /etc/netdata/node.d/named.conf
// the module supports auto-detection if bind is running at localhost
/*
{
"enable_autodetect": true,
"update_every": 5,
"servers": [
{
"name": "bind1",
"url": "http://127.0.0.1:8888/json/v1/server",
"update_every": 1
},
{
"name": "bind2",
"url": "http://10.0.0.1:8888/xml/v3/server",
"update_every": 2
}
]
}
*/
// the following is the bind named.conf configuration required
/*
statistics-channels {
inet 127.0.0.1 port 8888 allow { 127.0.0.1; };
};
*/
require('url');
require('http');
var XML = require('pixl-xml');
var netdata = require('netdata');
if(netdata.options.DEBUG === true) netdata.debug('loaded', __filename, 'plugin');
var named = {
name: __filename,
enable_autodetect: true,
update_every: 1,
base_priority: 60000,
charts: {},
chartFromMembersCreate: function(service, obj, id, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor) {
var chart = {
id: id, // the unique id of the chart
name: '', // the unique name of the chart
title: service.name + ' ' + title_suffix, // the title of the chart
units: units, // the units of the chart dimensions
family: family, // the family of the chart
context: context, // the context of the chart
type: type, // the type of the chart
priority: priority, // the priority relative to others in the same family
update_every: service.update_every, // the expected update frequency of the chart
dimensions: {}
};
var found = 0;
var dims = Object.keys(obj);
var len = dims.length;
for(var i = 0; i < len ;i++) {
var x = dims[i];
if(typeof(obj[x]) !== 'undefined' && obj[x] !== 0) {
found++;
chart.dimensions[x] = {
id: x, // the unique id of the dimension
name: x, // the name of the dimension
algorithm: algorithm, // the id of the netdata algorithm
multiplier: multiplier, // the multiplier
divisor: divisor, // the divisor
hidden: false // is hidden (boolean)
};
}
}
if(!found)
return null;
chart = service.chart(id, chart);
this.charts[id] = chart;
return chart;
},
chartFromMembers: function(service, obj, id_suffix, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor) {
var id = 'named_' + service.name + '.' + id_suffix;
var chart = this.charts[id];
var dims, len, x, i;
if(typeof chart === 'undefined') {
chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor);
if(chart === null) return false;
}
else {
// check if we need to re-generate the chart
dims = Object.keys(obj);
len = dims.length;
for(i = 0; i < len ;i++) {
x = dims[i];
if(typeof(chart.dimensions[x]) === 'undefined') {
chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor);
if(chart === null) return false;
break;
}
}
}
service.begin(chart);
var found = 0;
dims = Object.keys(obj);
len = dims.length;
for(i = 0; i < len ;i++) {
x = dims[i];
if(typeof(chart.dimensions[x]) !== 'undefined') {
found++;
service.set(x, obj[x]);
}
}
service.end();
return (found > 0);
},
// an index to map values to different charts
lookups: {
nsstats: {},
resolver_stats: {},
numfetch: {}
},
// transform the XML response of bind
// to the JSON response of bind
xml2js: function(service, data_xml) {
var d = XML.parse(data_xml);
if(d === null) return null;
var a, aa, alen, alen2;
var data = {};
var len = d.server.counters.length;
while(len--) {
a = d.server.counters[len];
if(typeof a.counter === 'undefined') continue;
if(a.type === 'opcode') a.type = 'opcodes';
else if(a.type === 'qtype') a.type = 'qtypes';
else if(a.type === 'nsstat') a.type = 'nsstats';
aa = data[a.type] = {};
alen = 0;
alen2 = a.counter.length;
while(alen < alen2) {
aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data, 10);
alen++;
}
}
data.views = {};
var vlen = d.views.view.length;
while(vlen--) {
var vname = d.views.view[vlen].name;
data.views[vname] = { resolver: {} };
len = d.views.view[vlen].counters.length;
while(len--) {
a = d.views.view[vlen].counters[len];
if(typeof a.counter === 'undefined') continue;
if(a.type === 'resstats') a.type = 'stats';
else if(a.type === 'resqtype') a.type = 'qtypes';
else if(a.type === 'adbstat') a.type = 'adb';
aa = data.views[vname].resolver[a.type] = {};
alen = 0;
alen2 = a.counter.length;
while(alen < alen2) {
aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data, 10);
alen++;
}
}
}
return data;
},
processResponse: function(service, data) {
if(data !== null) {
var r, x, look, id, chart, keys, len;
// parse XML or JSON
// pepending on the URL given
if(service.request.path.match(/^\/xml/) !== null)
r = named.xml2js(service, data);
else
r = JSON.parse(data);
if(typeof r === 'undefined' || r === null) {
service.error("Cannot parse these data: " + data.toString());
return;
}
if(service.added !== true)
service.commit();
if(typeof r.nsstats !== 'undefined') {
// we split the nsstats object to several others
var global_requests = {}, global_requests_enable = false;
var global_failures = {}, global_failures_enable = false;
var global_failures_detail = {}, global_failures_detail_enable = false;
var global_updates = {}, global_updates_enable = false;
var protocol_queries = {}, protocol_queries_enable = false;
var global_queries = {}, global_queries_enable = false;
var global_queries_success = {}, global_queries_success_enable = false;
var default_enable = false;
var RecursClients = 0;
// RecursClients is an absolute value
if(typeof r.nsstats['RecursClients'] !== 'undefined') {
RecursClients = r.nsstats['RecursClients'];
delete r.nsstats['RecursClients'];
}
keys = Object.keys(r.nsstats);
len = keys.length;
while(len--) {
x = keys[len];
// we maintain an index of the values found
// mapping them to objects splitted
look = named.lookups.nsstats[x];
if(typeof look === 'undefined') {
// a new value, not found in the index
// index it:
if(x === 'Requestv4') {
named.lookups.nsstats[x] = {
name: 'IPv4',
type: 'global_requests'
};
}
else if(x === 'Requestv6') {
named.lookups.nsstats[x] = {
name: 'IPv6',
type: 'global_requests'
};
}
else if(x === 'QryFailure') {
named.lookups.nsstats[x] = {
name: 'failures',
type: 'global_failures'
};
}
else if(x === 'QryUDP') {
named.lookups.nsstats[x] = {
name: 'UDP',
type: 'protocol_queries'
};
}
else if(x === 'QryTCP') {
named.lookups.nsstats[x] = {
name: 'TCP',
type: 'protocol_queries'
};
}
else if(x === 'QrySuccess') {
named.lookups.nsstats[x] = {
name: 'queries',
type: 'global_queries_success'
};
}
else if(x.match(/QryRej$/) !== null) {
named.lookups.nsstats[x] = {
name: x,
type: 'global_failures_detail'
};
}
else if(x.match(/^Qry/) !== null) {
named.lookups.nsstats[x] = {
name: x,
type: 'global_queries'
};
}
else if(x.match(/^Update/) !== null) {
named.lookups.nsstats[x] = {
name: x,
type: 'global_updates'
};
}
else {
// values not mapped, will remain
// in the default map
named.lookups.nsstats[x] = {
name: x,
type: 'default'
};
}
look = named.lookups.nsstats[x];
// netdata.error('lookup nsstats value: ' + x + ' >>> ' + named.lookups.nsstats[x].type);
}
switch(look.type) {
case 'global_requests': global_requests[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_requests_enable = true; break;
case 'global_queries': global_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_enable = true; break;
case 'global_queries_success': global_queries_success[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_success_enable = true; break;
case 'global_updates': global_updates[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_updates_enable = true; break;
case 'protocol_queries': protocol_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; protocol_queries_enable = true; break;
case 'global_failures': global_failures[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_enable = true; break;
case 'global_failures_detail': global_failures_detail[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_detail_enable = true; break;
default: default_enable = true; break;
}
}
if(global_requests_enable === true)
service.module.chartFromMembers(service, global_requests, 'received_requests', 'Bind, Global Received Requests by IP version', 'requests/s', 'requests', 'named.requests', netdata.chartTypes.stacked, named.base_priority + 1, netdata.chartAlgorithms.incremental, 1, 1);
if(global_queries_success_enable === true)
service.module.chartFromMembers(service, global_queries_success, 'global_queries_success', 'Bind, Global Successful Queries', 'queries/s', 'queries', 'named.queries_succcess', netdata.chartTypes.line, named.base_priority + 2, netdata.chartAlgorithms.incremental, 1, 1);
if(protocol_queries_enable === true)
service.module.chartFromMembers(service, protocol_queries, 'protocols_queries', 'Bind, Global Queries by IP Protocol', 'queries/s', 'queries', 'named.protocol_queries', netdata.chartTypes.stacked, named.base_priority + 3, netdata.chartAlgorithms.incremental, 1, 1);
if(global_queries_enable === true)
service.module.chartFromMembers(service, global_queries, 'global_queries', 'Bind, Global Queries Analysis', 'queries/s', 'queries', 'named.global_queries', netdata.chartTypes.stacked, named.base_priority + 4, netdata.chartAlgorithms.incremental, 1, 1);
if(global_updates_enable === true)
service.module.chartFromMembers(service, global_updates, 'received_updates', 'Bind, Global Received Updates', 'updates/s', 'updates', 'named.global_updates', netdata.chartTypes.stacked, named.base_priority + 5, netdata.chartAlgorithms.incremental, 1, 1);
if(global_failures_enable === true)
service.module.chartFromMembers(service, global_failures, 'query_failures', 'Bind, Global Query Failures', 'failures/s', 'failures', 'named.global_failures', netdata.chartTypes.line, named.base_priority + 6, netdata.chartAlgorithms.incremental, 1, 1);
if(global_failures_detail_enable === true)
service.module.chartFromMembers(service, global_failures_detail, 'query_failures_detail', 'Bind, Global Query Failures Analysis', 'failures/s', 'failures', 'named.global_failures_detail', netdata.chartTypes.stacked, named.base_priority + 7, netdata.chartAlgorithms.incremental, 1, 1);
if(default_enable === true)
service.module.chartFromMembers(service, r.nsstats, 'nsstats', 'Bind, Other Global Server Statistics', 'operations/s', 'other', 'named.nsstats', netdata.chartTypes.line, named.base_priority + 8, netdata.chartAlgorithms.incremental, 1, 1);
// RecursClients chart
id = 'named_' + service.name + '.recursive_clients';
chart = named.charts[id];
if(typeof chart === 'undefined') {
chart = {
id: id, // the unique id of the chart
name: '', // the unique name of the chart
title: service.name + ' Bind, Current Recursive Clients', // the title of the chart
units: 'clients', // the units of the chart dimensions
family: 'clients', // the family of the chart
context: 'named.recursive_clients', // the context of the chart
type: netdata.chartTypes.line, // the type of the chart
priority: named.base_priority + 1, // the priority relative to others in the same family
update_every: service.update_every, // the expected update frequency of the chart
dimensions: {
'clients': {
id: 'clients', // the unique id of the dimension
name: '', // the name of the dimension
algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
multiplier: 1, // the multiplier
divisor: 1, // the divisor
hidden: false // is hidden (boolean)
}
}
};
chart = service.chart(id, chart);
named.charts[id] = chart;
}
service.begin(chart);
service.set('clients', RecursClients);
service.end();
}
if(typeof r.opcodes !== 'undefined')
service.module.chartFromMembers(service, r.opcodes, 'in_opcodes', 'Bind, Global Incoming Requests by OpCode', 'requests/s', 'requests', 'named.in_opcodes', netdata.chartTypes.stacked, named.base_priority + 9, netdata.chartAlgorithms.incremental, 1, 1);
if(typeof r.qtypes !== 'undefined')
service.module.chartFromMembers(service, r.qtypes, 'in_qtypes', 'Bind, Global Incoming Requests by Query Type', 'requests/s', 'requests', 'named.in_qtypes', netdata.chartTypes.stacked, named.base_priority + 10, netdata.chartAlgorithms.incremental, 1, 1);
if(typeof r.sockstats !== 'undefined')
service.module.chartFromMembers(service, r.sockstats, 'in_sockstats', 'Bind, Global Socket Statistics', 'operations/s', 'sockets', 'named.in_sockstats', netdata.chartTypes.line, named.base_priority + 11, netdata.chartAlgorithms.incremental, 1, 1);
if(typeof r.views !== 'undefined') {
keys = Object.keys(r.views);
len = keys.length;
while(len--) {
x = keys[len];
var resolver = r.views[x].resolver;
if(typeof resolver !== 'undefined') {
if(typeof resolver.stats !== 'undefined') {
var NumFetch = 0;
var key = service.name + '.' + x;
var rtt = {}, rtt_enable = false;
default_enable = false;
// NumFetch is an absolute value
if(typeof resolver.stats['NumFetch'] !== 'undefined') {
named.lookups.numfetch[key] = true;
NumFetch = resolver.stats['NumFetch'];
delete resolver.stats['NumFetch'];
}
if(typeof resolver.stats['BucketSize'] !== 'undefined') {
delete resolver.stats['BucketSize'];
}
// split the QryRTT* from the main chart
var ykeys = Object.keys(resolver.stats);
var ylen = ykeys.length;
while(ylen--) {
var y = ykeys[ylen];
// we maintain an index of the values found
// mapping them to objects splitted
look = named.lookups.resolver_stats[y];
if(typeof look === 'undefined') {
if(y.match(/^QryRTT/) !== null) {
named.lookups.resolver_stats[y] = {
name: y,
type: 'rtt'
};
}
else {
named.lookups.resolver_stats[y] = {
name: y,
type: 'default'
};
}
look = named.lookups.resolver_stats[y];
// netdata.error('lookup resolver stats value: ' + y + ' >>> ' + look.type);
}
switch(look.type) {
case 'rtt': rtt[look.name] = resolver.stats[y]; delete resolver.stats[y]; rtt_enable = true; break;
default: default_enable = true; break;
}
}
if(rtt_enable)
service.module.chartFromMembers(service, rtt, 'view_resolver_rtt_' + x, 'Bind, ' + x + ' View, Resolver Round Trip Timings', 'queries/s', 'view_' + x, 'named.resolver_rtt', netdata.chartTypes.stacked, named.base_priority + 12, netdata.chartAlgorithms.incremental, 1, 1);
if(default_enable)
service.module.chartFromMembers(service, resolver.stats, 'view_resolver_stats_' + x, 'Bind, ' + x + ' View, Resolver Statistics', 'operations/s', 'view_' + x, 'named.resolver_stats', netdata.chartTypes.line, named.base_priority + 13, netdata.chartAlgorithms.incremental, 1, 1);
// NumFetch chart
if(typeof named.lookups.numfetch[key] !== 'undefined') {
id = 'named_' + service.name + '.view_resolver_numfetch_' + x;
chart = named.charts[id];
if(typeof chart === 'undefined') {
chart = {
id: id, // the unique id of the chart
name: '', // the unique name of the chart
title: service.name + ' Bind, ' + x + ' View, Resolver Active Queries', // the title of the chart
units: 'queries', // the units of the chart dimensions
family: 'view_' + x, // the family of the chart
context: 'named.resolver_active_queries', // the context of the chart
type: netdata.chartTypes.line, // the type of the chart
priority: named.base_priority + 1001, // the priority relative to others in the same family
update_every: service.update_every, // the expected update frequency of the chart
dimensions: {
'queries': {
id: 'queries', // the unique id of the dimension
name: '', // the name of the dimension
algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
multiplier: 1, // the multiplier
divisor: 1, // the divisor
hidden: false // is hidden (boolean)
}
}
};
chart = service.chart(id, chart);
named.charts[id] = chart;
}
service.begin(chart);
service.set('queries', NumFetch);
service.end();
}
}
}
if(typeof resolver.qtypes !== 'undefined')
service.module.chartFromMembers(service, resolver.qtypes, 'view_resolver_qtypes_' + x, 'Bind, ' + x + ' View, Requests by Query Type', 'requests/s', 'view_' + x, 'named.resolver_qtypes', netdata.chartTypes.stacked, named.base_priority + 14, netdata.chartAlgorithms.incremental, 1, 1);
//if(typeof resolver.cache !== 'undefined')
// service.module.chartFromMembers(service, resolver.cache, 'view_resolver_cache_' + x, 'Bind, ' + x + ' View, Cache Entries', 'entries', 'view_' + x, 'named.resolver_cache', netdata.chartTypes.stacked, named.base_priority + 15, netdata.chartAlgorithms.absolute, 1, 1);
if(typeof resolver.cachestats['CacheHits'] !== 'undefined' && resolver.cachestats['CacheHits'] > 0) {
id = 'named_' + service.name + '.view_resolver_cachehits_' + x;
chart = named.charts[id];
if(typeof chart === 'undefined') {
chart = {
id: id, // the unique id of the chart
name: '', // the unique name of the chart
title: service.name + ' Bind, ' + x + ' View, Resolver Cache Hits', // the title of the chart
units: 'operations/s', // the units of the chart dimensions
family: 'view_' + x, // the family of the chart
context: 'named.resolver_cache_hits', // the context of the chart
type: netdata.chartTypes.area, // the type of the chart
priority: named.base_priority + 1100, // the priority relative to others in the same family
update_every: service.update_every, // the expected update frequency of the chart
dimensions: {
'CacheHits': {
id: 'CacheHits', // the unique id of the dimension
name: 'hits', // the name of the dimension
algorithm: netdata.chartAlgorithms.incremental,// the id of the netdata algorithm
multiplier: 1, // the multiplier
divisor: 1, // the divisor
hidden: false // is hidden (boolean)
},
'CacheMisses': {
id: 'CacheMisses', // the unique id of the dimension
name: 'misses', // the name of the dimension
algorithm: netdata.chartAlgorithms.incremental,// the id of the netdata algorithm
multiplier: -1, // the multiplier
divisor: 1, // the divisor
hidden: false // is hidden (boolean)
}
}
};
chart = service.chart(id, chart);
named.charts[id] = chart;
}
service.begin(chart);
service.set('CacheHits', resolver.cachestats['CacheHits']);
service.set('CacheMisses', resolver.cachestats['CacheMisses']);
service.end();
}
// this is wrong, it contains many types of info:
// 1. CacheHits, CacheMisses - incremental (added above)
// 2. QueryHits, QueryMisses - incremental
// 3. DeleteLRU, DeleteTTL - incremental
// 4. CacheNodes, CacheBuckets - absolute
// 5. TreeMemTotal, TreeMemInUse - absolute
// 6. HeapMemMax, HeapMemTotal, HeapMemInUse - absolute
//if(typeof resolver.cachestats !== 'undefined')
// service.module.chartFromMembers(service, resolver.cachestats, 'view_resolver_cachestats_' + x, 'Bind, ' + x + ' View, Cache Statistics', 'requests/s', 'view_' + x, 'named.resolver_cache_stats', netdata.chartTypes.line, named.base_priority + 1001, netdata.chartAlgorithms.incremental, 1, 1);
//if(typeof resolver.adb !== 'undefined')
// service.module.chartFromMembers(service, resolver.adb, 'view_resolver_adb_' + x, 'Bind, ' + x + ' View, ADB Statistics', 'entries', 'view_' + x, 'named.resolver_adb', netdata.chartTypes.line, named.base_priority + 1002, netdata.chartAlgorithms.absolute, 1, 1);
}
}
}
},
// module.serviceExecute()
// this function is called only from this module
// its purpose is to prepare the request and call
// netdata.serviceExecute()
serviceExecute: function(name, a_url, update_every) {
if(netdata.options.DEBUG === true) netdata.debug(this.name + ': ' + name + ': url: ' + a_url + ', update_every: ' + update_every);
var service = netdata.service({
name: name,
request: netdata.requestFromURL(a_url),
update_every: update_every,
module: this
});
service.execute(this.processResponse);
},
configure: function(config) {
var added = 0;
if(this.enable_autodetect === true) {
this.serviceExecute('local', 'http://localhost:8888/json/v1/server', this.update_every);
added++;
}
if(typeof(config.servers) !== 'undefined') {
var len = config.servers.length;
while(len--) {
if(typeof config.servers[len].update_every === 'undefined')
config.servers[len].update_every = this.update_every;
this.serviceExecute(config.servers[len].name, config.servers[len].url, config.servers[len].update_every);
added++;
}
}
return added;
},
// module.update()
// this is called repeatidly to collect data, by calling
// netdata.serviceExecute()
update: function(service, callback) {
service.execute(function(serv, data) {
service.module.processResponse(serv, data);
callback();
});
}
};
module.exports = named;
|