3 // collect statistics from bind (named) v9.10+
\r
5 // bind statistics documentation at:
\r
6 // http://jpmens.net/2013/03/18/json-in-bind-9-s-statistics-server/
\r
7 // https://ftp.isc.org/isc/bind/9.10.3/doc/arm/Bv9ARM.ch06.html#statistics
\r
9 // example configuration in /etc/netdata/named.conf
\r
10 // the module supports auto-detection if bind is running in localhost
\r
14 "enable_autodetect": true,
\r
19 "url": "http://127.0.0.1:8888/json/v1/server",
\r
24 "url": "http://10.0.0.1:8888/xml/v3/server",
\r
31 // the following is the bind named.conf configuration required
\r
34 statistics-channels {
\r
35 inet 127.0.0.1 port 8888 allow { 127.0.0.1; };
\r
39 var url = require('url');
\r
40 var http = require('http');
\r
41 var XML = require('pixl-xml');
\r
42 var netdata = require('netdata');
\r
44 if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plugin');
\r
48 enable_autodetect: true,
\r
53 chartFromMembersCreate: function(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor) {
\r
55 id: id, // the unique id of the chart
\r
56 name: '', // the unique name of the chart
\r
57 title: service.name + ' ' + title_suffix, // the title of the chart
\r
58 units: units, // the units of the chart dimensions
\r
59 family: family_prefix + '_' + service.name, // the family of the chart
\r
60 category: category_prefix + '_' + service.name, // the category of the chart
\r
61 type: type, // the type of the chart
\r
62 priority: priority, // the priority relative to others in the same family and category
\r
63 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
69 if(typeof(obj[x]) !== 'undefined' && obj[x] !== 0) {
\r
71 chart.dimensions[x] = {
\r
72 id: x, // the unique id of the dimension
\r
73 name: x, // the name of the dimension
\r
74 algorithm: algorithm, // the id of the netdata algorithm
\r
75 multiplier: multiplier, // the multiplier
\r
76 divisor: divisor, // the divisor
\r
77 hidden: false // is hidden (boolean)
\r
85 chart = service.chart(id, chart);
\r
86 this.charts[id] = chart;
\r
90 chartFromMembers: function(service, obj, id_suffix, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor) {
\r
91 var id = 'named_' + service.name + '.' + id_suffix;
\r
92 var chart = this.charts[id];
\r
94 if(typeof chart === 'undefined') {
\r
95 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor);
\r
96 if(chart === null) return false;
\r
99 // check if we need to re-generate the chart
\r
100 for(var x in obj) {
\r
101 if(typeof(chart.dimensions[x]) === 'undefined') {
\r
102 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor);
\r
103 if(chart === null) return false;
\r
110 service.begin(chart);
\r
111 for(var x in obj) {
\r
112 if(typeof(chart.dimensions[x]) !== 'undefined') {
\r
114 service.set(x, obj[x]);
\r
119 if(found > 0) return true;
\r
123 // an index to map values to different charts
\r
126 resolver_stats: {},
\r
130 // transform the XML response of bind
\r
131 // to the JSON response of bind
\r
132 xml2js: function(service, data_xml) {
\r
133 var d = XML.parse(data_xml);
\r
134 if(d === null) return null;
\r
137 var len = d.server.counters.length;
\r
139 var a = d.server.counters[len];
\r
140 if(typeof a.counter === 'undefined') continue;
\r
141 if(a.type === 'opcode') a.type = 'opcodes';
\r
142 else if(a.type === 'qtype') a.type = 'qtypes';
\r
143 else if(a.type === 'nsstat') a.type = 'nsstats';
\r
144 var aa = data[a.type] = {};
\r
146 var alen2 = a.counter.length;
\r
147 while(alen < alen2) {
\r
148 aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data);
\r
154 var vlen = d.views.view.length;
\r
156 var vname = d.views.view[vlen].name;
\r
157 data.views[vname] = { resolver: {} };
\r
158 var len = d.views.view[vlen].counters.length;
\r
160 var a = d.views.view[vlen].counters[len];
\r
161 if(typeof a.counter === 'undefined') continue;
\r
162 if(a.type === 'resstats') a.type = 'stats';
\r
163 else if(a.type === 'resqtype') a.type = 'qtypes';
\r
164 else if(a.type === 'adbstat') a.type = 'adb';
\r
165 var aa = data.views[vname].resolver[a.type] = {};
\r
167 var alen2 = a.counter.length;
\r
168 while(alen < alen2) {
\r
169 aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data);
\r
178 processResponse: function(service, data) {
\r
179 if(data !== null) {
\r
182 // parse XML or JSON
\r
183 // pepending on the URL given
\r
184 if(service.request.path.match(/^\/xml/) !== null)
\r
185 r = named.xml2js(service, data);
\r
187 r = JSON.parse(data);
\r
189 if(typeof r === 'undefined' || r === null) {
\r
190 netdata.serviceError(service, "Cannot parse these data: " + data);
\r
194 if(service.added !== true)
\r
195 netdata.serviceAdd(service);
\r
197 if(typeof r.nsstats !== 'undefined') {
\r
198 // we split the nsstats object to several others
\r
199 var global_requests = {}, global_requests_enable = false;
\r
200 var global_failures = {}, global_failures_enable = false;
\r
201 var global_failures_detail = {}, global_failures_detail_enable = false;
\r
202 var global_updates = {}, global_updates_enable = false;
\r
203 var protocol_queries = {}, protocol_queries_enable = false;
\r
204 var global_queries = {}, global_queries_enable = false;
\r
205 var global_queries_success = {}, global_queries_success_enable = false;
\r
206 var default_enable = false;
\r
207 var RecursClients = 0;
\r
209 // RecursClients is an absolute value
\r
210 if(typeof r.nsstats['RecursClients'] !== 'undefined') {
\r
211 RecursClients = r.nsstats['RecursClients'];
\r
212 delete r.nsstats['RecursClients'];
\r
215 for( var x in r.nsstats ) {
\r
216 // we maintain an index of the values found
\r
217 // mapping them to objects splitted
\r
219 var look = named.lookups.nsstats[x];
\r
220 if(typeof look === 'undefined') {
\r
221 // a new value, not found in the index
\r
223 if(x === 'Requestv4') {
\r
224 named.lookups.nsstats[x] = {
\r
226 type: 'global_requests'
\r
229 else if(x === 'Requestv6') {
\r
230 named.lookups.nsstats[x] = {
\r
232 type: 'global_requests'
\r
235 else if(x === 'QryFailure') {
\r
236 named.lookups.nsstats[x] = {
\r
238 type: 'global_failures'
\r
241 else if(x === 'QryUDP') {
\r
242 named.lookups.nsstats[x] = {
\r
244 type: 'protocol_queries'
\r
247 else if(x === 'QryTCP') {
\r
248 named.lookups.nsstats[x] = {
\r
250 type: 'protocol_queries'
\r
253 else if(x === 'QrySuccess') {
\r
254 named.lookups.nsstats[x] = {
\r
256 type: 'global_queries_success'
\r
259 else if(x.match(/QryRej$/) !== null) {
\r
260 named.lookups.nsstats[x] = {
\r
262 type: 'global_failures_detail'
\r
265 else if(x.match(/^Qry/) !== null) {
\r
266 named.lookups.nsstats[x] = {
\r
268 type: 'global_queries'
\r
271 else if(x.match(/^Update/) !== null) {
\r
272 named.lookups.nsstats[x] = {
\r
274 type: 'global_updates'
\r
278 // values not mapped, will remain
\r
279 // in the default map
\r
280 named.lookups.nsstats[x] = {
\r
286 look = named.lookups.nsstats[x];
\r
287 // netdata.error('lookup nsstats value: ' + x + ' >>> ' + named.lookups.nsstats[x].type);
\r
290 switch(look.type) {
\r
291 case 'global_requests': global_requests[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_requests_enable = true; break;
\r
292 case 'global_queries': global_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_enable = true; break;
\r
293 case 'global_queries_success': global_queries_success[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_success_enable = true; break;
\r
294 case 'global_updates': global_updates[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_updates_enable = true; break;
\r
295 case 'protocol_queries': protocol_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; protocol_queries_enable = true; break;
\r
296 case 'global_failures': global_failures[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_enable = true; break;
\r
297 case 'global_failures_detail': global_failures_detail[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_detail_enable = true; break;
\r
298 default: default_enable = true; break;
\r
302 if(global_requests_enable == true)
\r
303 service.module.chartFromMembers(service, global_requests, 'received_requests', 'Bind, Global Received Requests by IP version', 'requests/s', 'named', 'named', netdata.chartTypes.stacked, 100, netdata.chartAlgorithms.incremental, 1, 1);
\r
305 if(global_queries_success_enable == true)
\r
306 service.module.chartFromMembers(service, global_queries_success, 'global_queries_success', 'Bind, Global Successful Queries', 'queries/s', 'named', 'named', netdata.chartTypes.line, 150, netdata.chartAlgorithms.incremental, 1, 1);
\r
308 if(protocol_queries_enable == true)
\r
309 service.module.chartFromMembers(service, protocol_queries, 'protocols_queries', 'Bind, Global Queries by IP Protocol', 'queries/s', 'named', 'named', netdata.chartTypes.stacked, 200, netdata.chartAlgorithms.incremental, 1, 1);
\r
311 if(global_queries_enable == true)
\r
312 service.module.chartFromMembers(service, global_queries, 'global_queries', 'Bind, Global Queries Analysis', 'queries/s', 'named', 'named', netdata.chartTypes.stacked, 300, netdata.chartAlgorithms.incremental, 1, 1);
\r
314 if(global_updates_enable == true)
\r
315 service.module.chartFromMembers(service, global_updates, 'received_updates', 'Bind, Global Received Updates', 'updates/s', 'named', 'named', netdata.chartTypes.stacked, 900, netdata.chartAlgorithms.incremental, 1, 1);
\r
317 if(global_failures_enable == true)
\r
318 service.module.chartFromMembers(service, global_failures, 'query_failures', 'Bind, Global Query Failures', 'failures/s', 'named', 'named', netdata.chartTypes.line, 950, netdata.chartAlgorithms.incremental, 1, 1);
\r
320 if(global_failures_detail_enable == true)
\r
321 service.module.chartFromMembers(service, global_failures_detail, 'query_failures_detail', 'Bind, Global Query Failures Analysis', 'failures/s', 'named', 'named', netdata.chartTypes.stacked, 960, netdata.chartAlgorithms.incremental, 1, 1);
\r
323 if(default_enable === true)
\r
324 service.module.chartFromMembers(service, r.nsstats, 'nsstats', 'Bind, Other Global Server Statistics', 'operations/s', 'named', 'named', netdata.chartTypes.line, 999, netdata.chartAlgorithms.incremental, 1, 1);
\r
326 // RecursClients chart
\r
328 var id = 'named_' + service.name + '.recursive_clients';
\r
329 var chart = named.charts[id];
\r
331 if(typeof chart === 'undefined') {
\r
333 id: id, // the unique id of the chart
\r
334 name: '', // the unique name of the chart
\r
335 title: service.name + ' Bind, Current Recursive Clients', // the title of the chart
\r
336 units: 'clients', // the units of the chart dimensions
\r
337 family: 'named', // the family of the chart
\r
338 category: 'named', // the category of the chart
\r
339 type: netdata.chartTypes.line, // the type of the chart
\r
340 priority: 150, // the priority relative to others in the same family and category
\r
341 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
344 id: 'clients', // the unique id of the dimension
\r
345 name: '', // the name of the dimension
\r
346 algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
\r
347 multiplier: 1, // the multiplier
\r
348 divisor: 1, // the divisor
\r
349 hidden: false // is hidden (boolean)
\r
354 chart = service.chart(id, chart);
\r
355 named.charts[id] = chart;
\r
358 service.begin(chart);
\r
359 service.set('clients', RecursClients);
\r
364 if(typeof r.opcodes !== 'undefined')
\r
365 service.module.chartFromMembers(service, r.opcodes, 'in_opcodes', 'Bind, Global Incoming Requests by OpCode', 'requests/s', 'named', 'named', netdata.chartTypes.stacked, 1000, netdata.chartAlgorithms.incremental, 1, 1);
\r
367 if(typeof r.qtypes !== 'undefined')
\r
368 service.module.chartFromMembers(service, r.qtypes, 'in_qtypes', 'Bind, Global Incoming Requests by Query Type', 'requests/s', 'named', 'named', netdata.chartTypes.stacked, 2000, netdata.chartAlgorithms.incremental, 1, 1);
\r
370 if(typeof r.sockstats !== 'undefined')
\r
371 service.module.chartFromMembers(service, r.sockstats, 'in_sockstats', 'Bind, Global Socket Statistics', 'operations/s', 'named', 'named', netdata.chartTypes.line, 2500, netdata.chartAlgorithms.incremental, 1, 1);
\r
373 if(typeof r.views !== 'undefined') {
\r
374 for( var x in r.views ) {
\r
375 var resolver = r.views[x].resolver;
\r
377 if(typeof resolver !== 'undefined') {
\r
378 if(typeof resolver.stats !== 'undefined') {
\r
380 var key = service.name + '.' + x;
\r
381 var default_enable = false;
\r
382 var rtt = {}, rtt_enable = false;
\r
384 // NumFetch is an absolute value
\r
385 if(typeof resolver.stats['NumFetch'] !== 'undefined') {
\r
386 named.lookups.numfetch[key] = true;
\r
387 NumFetch = resolver.stats['NumFetch'];
\r
388 delete resolver.stats['NumFetch'];
\r
390 if(typeof resolver.stats['BucketSize'] !== 'undefined') {
\r
391 delete resolver.stats['BucketSize'];
\r
394 // split the QryRTT* from the main chart
\r
395 for( var y in resolver.stats ) {
\r
396 // we maintain an index of the values found
\r
397 // mapping them to objects splitted
\r
399 var look = named.lookups.resolver_stats[y];
\r
400 if(typeof look === 'undefined') {
\r
401 if(y.match(/^QryRTT/) !== null) {
\r
402 named.lookups.resolver_stats[y] = {
\r
408 named.lookups.resolver_stats[y] = {
\r
414 look = named.lookups.resolver_stats[y];
\r
415 // netdata.error('lookup resolver stats value: ' + y + ' >>> ' + look.type);
\r
418 switch(look.type) {
\r
419 case 'rtt': rtt[look.name] = resolver.stats[y]; delete resolver.stats[y]; rtt_enable = true; break;
\r
420 default: default_enable = true; break;
\r
425 service.module.chartFromMembers(service, rtt, 'view_resolver_rtt_' + x, 'Bind, ' + x + ' View, Resolver Round Trip Timings', 'queries/s', 'named', 'named', netdata.chartTypes.stacked, 5600, netdata.chartAlgorithms.incremental, 1, 1);
\r
428 service.module.chartFromMembers(service, resolver.stats, 'view_resolver_stats_' + x, 'Bind, ' + x + ' View, Resolver Statistics', 'operations/s', 'named', 'named', netdata.chartTypes.line, 5500, netdata.chartAlgorithms.incremental, 1, 1);
\r
431 if(typeof named.lookups.numfetch[key] !== 'undefined') {
\r
432 var id = 'named_' + service.name + '.view_resolver_numfetch_' + x;
\r
433 var chart = named.charts[id];
\r
435 if(typeof chart === 'undefined') {
\r
437 id: id, // the unique id of the chart
\r
438 name: '', // the unique name of the chart
\r
439 title: service.name + ' Bind, ' + x + ' View, Resolver Active Queries', // the title of the chart
\r
440 units: 'queries', // the units of the chart dimensions
\r
441 family: 'named', // the family of the chart
\r
442 category: 'named', // the category of the chart
\r
443 type: netdata.chartTypes.line, // the type of the chart
\r
444 priority: 5000, // the priority relative to others in the same family and category
\r
445 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
448 id: 'queries', // the unique id of the dimension
\r
449 name: '', // the name of the dimension
\r
450 algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
\r
451 multiplier: 1, // the multiplier
\r
452 divisor: 1, // the divisor
\r
453 hidden: false // is hidden (boolean)
\r
458 chart = service.chart(id, chart);
\r
459 named.charts[id] = chart;
\r
462 service.begin(chart);
\r
463 service.set('queries', NumFetch);
\r
469 if(typeof resolver.qtypes !== 'undefined')
\r
470 service.module.chartFromMembers(service, resolver.qtypes, 'view_resolver_qtypes_' + x, 'Bind, ' + x + ' View, Requests by Query Type', 'requests/s', 'named', 'named', netdata.chartTypes.stacked, 6000, netdata.chartAlgorithms.incremental, 1, 1);
\r
472 //if(typeof resolver.cache !== 'undefined')
\r
473 // service.module.chartFromMembers(service, resolver.cache, 'view_resolver_cache_' + x, 'Bind, ' + x + ' View, Cache Entries', 'entries', 'named', 'named', netdata.chartTypes.stacked, 7000, netdata.chartAlgorithms.absolute, 1, 1);
\r
475 if(typeof resolver.cachestats['CacheHits'] !== 'undefined' && resolver.cachestats['CacheHits'] > 0) {
\r
476 var id = 'named_' + service.name + '.view_resolver_cachehits_' + x;
\r
477 var chart = named.charts[id];
\r
479 if(typeof chart === 'undefined') {
\r
481 id: id, // the unique id of the chart
\r
482 name: '', // the unique name of the chart
\r
483 title: service.name + ' Bind, ' + x + ' View, Resolver Cache Hits', // the title of the chart
\r
484 units: 'operations/s', // the units of the chart dimensions
\r
485 family: 'named', // the family of the chart
\r
486 category: 'named', // the category of the chart
\r
487 type: netdata.chartTypes.area, // the type of the chart
\r
488 priority: 8000, // the priority relative to others in the same family and category
\r
489 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
492 id: 'CacheHits', // the unique id of the dimension
\r
493 name: 'hits', // the name of the dimension
\r
494 algorithm: netdata.chartAlgorithms.incremental,// the id of the netdata algorithm
\r
495 multiplier: 1, // the multiplier
\r
496 divisor: 1, // the divisor
\r
497 hidden: false // is hidden (boolean)
\r
500 id: 'CacheMisses', // the unique id of the dimension
\r
501 name: 'misses', // the name of the dimension
\r
502 algorithm: netdata.chartAlgorithms.incremental,// the id of the netdata algorithm
\r
503 multiplier: -1, // the multiplier
\r
504 divisor: 1, // the divisor
\r
505 hidden: false // is hidden (boolean)
\r
510 chart = service.chart(id, chart);
\r
511 named.charts[id] = chart;
\r
514 service.begin(chart);
\r
515 service.set('CacheHits', resolver.cachestats['CacheHits']);
\r
516 service.set('CacheMisses', resolver.cachestats['CacheMisses']);
\r
520 // this is wrong, it contains many types of info:
\r
521 // 1. CacheHits, CacheMisses - incremental (added above)
\r
522 // 2. QueryHits, QueryMisses - incremental
\r
523 // 3. DeleteLRU, DeleteTTL - incremental
\r
524 // 4. CacheNodes, CacheBuckets - absolute
\r
525 // 5. TreeMemTotal, TreeMemInUse - absolute
\r
526 // 6. HeapMemMax, HeapMemTotal, HeapMemInUse - absolute
\r
527 //if(typeof resolver.cachestats !== 'undefined')
\r
528 // service.module.chartFromMembers(service, resolver.cachestats, 'view_resolver_cachestats_' + x, 'Bind, ' + x + ' View, Cache Statistics', 'requests/s', 'named', 'named', netdata.chartTypes.line, 8000, netdata.chartAlgorithms.incremental, 1, 1);
\r
530 //if(typeof resolver.adb !== 'undefined')
\r
531 // service.module.chartFromMembers(service, resolver.adb, 'view_resolver_adb_' + x, 'Bind, ' + x + ' View, ADB Statistics', 'entries', 'named', 'named', netdata.chartTypes.line, 8500, netdata.chartAlgorithms.absolute, 1, 1);
\r
537 // module.serviceExecute()
\r
538 // this function is called only from this module
\r
539 // its purpose is to prepare the request and call
\r
540 // netdata.serviceExecute()
\r
541 serviceExecute: function(name, a_url, update_every) {
\r
542 if(netdata.options.DEBUG === true) netdata.debug(this.name + ': ' + name + ': url: ' + a_url + ', update_every: ' + update_every);
\r
543 netdata.serviceExecute({
\r
545 request: netdata.requestFromURL(a_url),
\r
546 update_every: update_every,
\r
548 }, this.processResponse);
\r
551 configure: function(config) {
\r
554 if(this.enable_autodetect === true) {
\r
555 this.serviceExecute('local', 'http://localhost:8888/json/v1/server', this.update_every);
\r
559 if(typeof(config.servers) !== 'undefined') {
\r
560 var len = config.servers.length;
\r
562 if(typeof config.servers[len].update_every === 'undefined')
\r
563 config.servers[len].update_every = this.update_every;
\r
565 config.servers[len].update_every = config.servers[len].update_every * 1000;
\r
567 this.serviceExecute(config.servers[len].name, config.servers[len].url, config.servers[len].update_every);
\r
576 // this is called repeatidly to collect data, by calling
\r
577 // netdata.serviceExecute()
\r
578 update: function(service, callback) {
\r
579 netdata.serviceExecute(service, function(serv, data) {
\r
580 service.module.processResponse(serv, data);
\r
586 module.exports = named;
\r