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.1.2.3:8888/json/v1/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 netdata = require('netdata');
\r
43 if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plugin');
\r
47 enable_autodetect: true,
\r
52 chartFromMembersCreate: function(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor) {
\r
54 id: id, // the unique id of the chart
\r
55 name: '', // the unique name of the chart
\r
56 title: service.name + ' ' + title_suffix, // the title of the chart
\r
57 units: units, // the units of the chart dimensions
\r
58 family: family_prefix + '_' + service.name, // the family of the chart
\r
59 category: category_prefix + '_' + service.name, // the category of the chart
\r
60 type: type, // the type of the chart
\r
61 priority: priority, // the priority relative to others in the same family and category
\r
62 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
68 if(typeof(obj[x]) !== 'undefined' && obj[x] !== 0) {
\r
70 chart.dimensions[x] = {
\r
71 id: x, // the unique id of the dimension
\r
72 name: x, // the name of the dimension
\r
73 algorithm: algorithm, // the id of the netdata algorithm
\r
74 multiplier: multiplier, // the multiplier
\r
75 divisor: divisor, // the divisor
\r
76 hidden: false // is hidden (boolean)
\r
84 chart = service.chart(id, chart);
\r
85 this.charts[id] = chart;
\r
89 chartFromMembers: function(service, obj, id_suffix, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor) {
\r
90 var id = 'named_' + service.name + '.' + id_suffix;
\r
91 var chart = this.charts[id];
\r
93 if(typeof chart === 'undefined') {
\r
94 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor);
\r
95 if(chart === null) return false;
\r
98 // check if we need to re-generate the chart
\r
100 if(typeof(chart.dimensions[x]) === 'undefined') {
\r
101 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor);
\r
102 if(chart === null) return false;
\r
109 service.begin(chart);
\r
110 for(var x in obj) {
\r
111 if(typeof(chart.dimensions[x]) !== 'undefined') {
\r
113 service.set(x, obj[x]);
\r
118 if(found > 0) return true;
\r
122 // an index to map values to different charts
\r
125 resolver_stats: {},
\r
129 processResponse: function(service, data) {
\r
130 if(data !== null) {
\r
131 var r = JSON.parse(data);
\r
133 if(service.added !== true)
\r
134 netdata.serviceAdd(service);
\r
136 if(typeof r.nsstats !== 'undefined') {
\r
137 // we split the nsstats object to several others
\r
138 var global_requests = {}, global_requests_enable = false;
\r
139 var global_failures = {}, global_failures_enable = false;
\r
140 var global_failures_detail = {}, global_failures_detail_enable = false;
\r
141 var global_updates = {}, global_updates_enable = false;
\r
142 var protocol_queries = {}, protocol_queries_enable = false;
\r
143 var global_queries = {}, global_queries_enable = false;
\r
144 var global_queries_success = {}, global_queries_success_enable = false;
\r
145 var default_enable = false;
\r
146 var RecursClients = 0;
\r
148 // RecursClients is an absolute value
\r
149 if(typeof r.nsstats['RecursClients'] !== 'undefined') {
\r
150 RecursClients = r.nsstats['RecursClients'];
\r
151 delete r.nsstats['RecursClients'];
\r
154 for( var x in r.nsstats ) {
\r
155 // we maintain an index of the values found
\r
156 // mapping them to objects splitted
\r
158 var look = named.lookups.nsstats[x];
\r
159 if(typeof look === 'undefined') {
\r
160 // a new value, not found in the index
\r
162 if(x === 'Requestv4') {
\r
163 named.lookups.nsstats[x] = {
\r
165 type: 'global_requests'
\r
168 else if(x === 'Requestv6') {
\r
169 named.lookups.nsstats[x] = {
\r
171 type: 'global_requests'
\r
174 else if(x === 'QryFailure') {
\r
175 named.lookups.nsstats[x] = {
\r
177 type: 'global_failures'
\r
180 else if(x === 'QryUDP') {
\r
181 named.lookups.nsstats[x] = {
\r
183 type: 'protocol_queries'
\r
186 else if(x === 'QryTCP') {
\r
187 named.lookups.nsstats[x] = {
\r
189 type: 'protocol_queries'
\r
192 else if(x === 'QrySuccess') {
\r
193 named.lookups.nsstats[x] = {
\r
195 type: 'global_queries_success'
\r
198 else if(x.match(/QryRej$/) !== null) {
\r
199 named.lookups.nsstats[x] = {
\r
201 type: 'global_failures_detail'
\r
204 else if(x.match(/^Qry/) !== null) {
\r
205 named.lookups.nsstats[x] = {
\r
207 type: 'global_queries'
\r
210 else if(x.match(/^Update/) !== null) {
\r
211 named.lookups.nsstats[x] = {
\r
213 type: 'global_updates'
\r
217 // values not mapped, will remain
\r
218 // in the default map
\r
219 named.lookups.nsstats[x] = {
\r
225 look = named.lookups.nsstats[x];
\r
226 // netdata.error('lookup nsstats value: ' + x + ' >>> ' + named.lookups.nsstats[x].type);
\r
229 switch(look.type) {
\r
230 case 'global_requests': global_requests[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_requests_enable = true; break;
\r
231 case 'global_queries': global_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_enable = true; break;
\r
232 case 'global_queries_success': global_queries_success[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_success_enable = true; break;
\r
233 case 'global_updates': global_updates[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_updates_enable = true; break;
\r
234 case 'protocol_queries': protocol_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; protocol_queries_enable = true; break;
\r
235 case 'global_failures': global_failures[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_enable = true; break;
\r
236 case 'global_failures_detail': global_failures_detail[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_detail_enable = true; break;
\r
237 default: default_enable = true; break;
\r
241 if(global_requests_enable == true)
\r
242 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
244 if(global_queries_success_enable == true)
\r
245 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
247 if(protocol_queries_enable == true)
\r
248 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
250 if(global_queries_enable == true)
\r
251 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
253 if(global_updates_enable == true)
\r
254 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
256 if(global_failures_enable == true)
\r
257 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
259 if(global_failures_detail_enable == true)
\r
260 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
262 if(default_enable === true)
\r
263 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
265 // RecursClients chart
\r
267 var id = 'named_' + service.name + '.recursive_clients';
\r
268 var chart = named.charts[id];
\r
270 if(typeof chart === 'undefined') {
\r
272 id: id, // the unique id of the chart
\r
273 name: '', // the unique name of the chart
\r
274 title: service.name + ' Bind, Current Recursive Clients', // the title of the chart
\r
275 units: 'clients', // the units of the chart dimensions
\r
276 family: 'named', // the family of the chart
\r
277 category: 'named', // the category of the chart
\r
278 type: netdata.chartTypes.line, // the type of the chart
\r
279 priority: 150, // the priority relative to others in the same family and category
\r
280 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
283 id: 'clients', // the unique id of the dimension
\r
284 name: '', // the name of the dimension
\r
285 algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
\r
286 multiplier: 1, // the multiplier
\r
287 divisor: 1, // the divisor
\r
288 hidden: false // is hidden (boolean)
\r
293 chart = service.chart(id, chart);
\r
294 named.charts[id] = chart;
\r
297 service.begin(chart);
\r
298 service.set('clients', RecursClients);
\r
303 if(typeof r.opcodes !== 'undefined')
\r
304 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
306 if(typeof r.qtypes !== 'undefined')
\r
307 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
309 if(typeof r.sockstats !== 'undefined')
\r
310 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
312 if(typeof r.views !== 'undefined') {
\r
313 for( var x in r.views ) {
\r
314 var resolver = r.views[x].resolver;
\r
316 if(typeof resolver !== 'undefined') {
\r
317 if(typeof resolver.stats !== 'undefined') {
\r
319 var key = service.name + '.' + x;
\r
320 var default_enable = false;
\r
321 var rtt = {}, rtt_enable = false;
\r
323 // NumFetch is an absolute value
\r
324 if(typeof resolver.stats['NumFetch'] !== 'undefined') {
\r
325 named.lookups.numfetch[key] = true;
\r
326 NumFetch = resolver.stats['NumFetch'];
\r
327 delete resolver.stats['NumFetch'];
\r
329 if(typeof resolver.stats['BucketSize'] !== 'undefined') {
\r
330 delete resolver.stats['BucketSize'];
\r
333 // split the QryRTT* from the main chart
\r
334 for( var y in resolver.stats ) {
\r
335 // we maintain an index of the values found
\r
336 // mapping them to objects splitted
\r
338 var look = named.lookups.resolver_stats[y];
\r
339 if(typeof look === 'undefined') {
\r
340 if(y.match(/^QryRTT/) !== null) {
\r
341 named.lookups.resolver_stats[y] = {
\r
347 named.lookups.resolver_stats[y] = {
\r
353 look = named.lookups.resolver_stats[y];
\r
354 // netdata.error('lookup resolver stats value: ' + y + ' >>> ' + look.type);
\r
357 switch(look.type) {
\r
358 case 'rtt': rtt[look.name] = resolver.stats[y]; delete resolver.stats[y]; rtt_enable = true; break;
\r
359 default: default_enable = true; break;
\r
364 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
367 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
370 if(typeof named.lookups.numfetch[key] !== 'undefined') {
\r
371 var id = 'named_' + service.name + '.view_resolver_numfetch_' + x;
\r
372 var chart = named.charts[id];
\r
374 if(typeof chart === 'undefined') {
\r
376 id: id, // the unique id of the chart
\r
377 name: '', // the unique name of the chart
\r
378 title: service.name + ' Bind, ' + x + ' View, Resolver Active Queries', // the title of the chart
\r
379 units: 'queries', // the units of the chart dimensions
\r
380 family: 'named', // the family of the chart
\r
381 category: 'named', // the category of the chart
\r
382 type: netdata.chartTypes.line, // the type of the chart
\r
383 priority: 5000, // the priority relative to others in the same family and category
\r
384 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
387 id: 'queries', // the unique id of the dimension
\r
388 name: '', // the name of the dimension
\r
389 algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
\r
390 multiplier: 1, // the multiplier
\r
391 divisor: 1, // the divisor
\r
392 hidden: false // is hidden (boolean)
\r
397 chart = service.chart(id, chart);
\r
398 named.charts[id] = chart;
\r
401 service.begin(chart);
\r
402 service.set('queries', NumFetch);
\r
408 if(typeof resolver.qtypes !== 'undefined')
\r
409 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
411 //if(typeof resolver.cache !== 'undefined')
\r
412 // 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
414 if(typeof resolver.cachestats['CacheHits'] !== 'undefined' && resolver.cachestats['CacheHits'] > 0) {
\r
415 var id = 'named_' + service.name + '.view_resolver_cachehits_' + x;
\r
416 var chart = named.charts[id];
\r
418 if(typeof chart === 'undefined') {
\r
420 id: id, // the unique id of the chart
\r
421 name: '', // the unique name of the chart
\r
422 title: service.name + ' Bind, ' + x + ' View, Resolver Cache Hits', // the title of the chart
\r
423 units: 'operations/s', // the units of the chart dimensions
\r
424 family: 'named', // the family of the chart
\r
425 category: 'named', // the category of the chart
\r
426 type: netdata.chartTypes.area, // the type of the chart
\r
427 priority: 8000, // the priority relative to others in the same family and category
\r
428 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
431 id: 'CacheHits', // the unique id of the dimension
\r
432 name: 'hits', // the name of the dimension
\r
433 algorithm: netdata.chartAlgorithms.incremental,// the id of the netdata algorithm
\r
434 multiplier: 1, // the multiplier
\r
435 divisor: 1, // the divisor
\r
436 hidden: false // is hidden (boolean)
\r
439 id: 'CacheMisses', // the unique id of the dimension
\r
440 name: 'misses', // the name of the dimension
\r
441 algorithm: netdata.chartAlgorithms.incremental,// the id of the netdata algorithm
\r
442 multiplier: -1, // the multiplier
\r
443 divisor: 1, // the divisor
\r
444 hidden: false // is hidden (boolean)
\r
449 chart = service.chart(id, chart);
\r
450 named.charts[id] = chart;
\r
453 service.begin(chart);
\r
454 service.set('CacheHits', resolver.cachestats['CacheHits']);
\r
455 service.set('CacheMisses', resolver.cachestats['CacheMisses']);
\r
459 // this is wrong, it contains many types of info:
\r
460 // 1. CacheHits, CacheMisses - incremental (added above)
\r
461 // 2. QueryHits, QueryMisses - incremental
\r
462 // 3. DeleteLRU, DeleteTTL - incremental
\r
463 // 4. CacheNodes, CacheBuckets - absolute
\r
464 // 5. TreeMemTotal, TreeMemInUse - absolute
\r
465 // 6. HeapMemMax, HeapMemTotal, HeapMemInUse - absolute
\r
466 //if(typeof resolver.cachestats !== 'undefined')
\r
467 // 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
469 //if(typeof resolver.adb !== 'undefined')
\r
470 // 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
476 // module.serviceExecute()
\r
477 // this function is called only from this module
\r
478 // its purpose is to prepare the request and call
\r
479 // netdata.serviceExecute()
\r
480 serviceExecute: function(name, a_url, update_every) {
\r
481 if(netdata.options.DEBUG === true) netdata.debug(this.name + ': ' + name + ': url: ' + a_url + ', update_every: ' + update_every);
\r
482 netdata.serviceExecute({
\r
484 request: netdata.requestFromURL(a_url),
\r
485 update_every: update_every,
\r
487 }, this.processResponse);
\r
490 configure: function(config) {
\r
493 if(this.enable_autodetect === true) {
\r
494 this.serviceExecute('local', 'http://localhost:8888/json/v1/server', this.update_every);
\r
498 if(typeof(config.servers) !== 'undefined') {
\r
499 var len = config.servers.length;
\r
501 if(typeof config.servers[len].update_every === 'undefined')
\r
502 config.servers[len].update_every = this.update_every;
\r
504 config.servers[len].update_every = config.servers[len].update_every * 1000;
\r
506 this.serviceExecute(config.servers[len].name, config.servers[len].url, config.servers[len].update_every);
\r
515 // this is called repeatidly to collect data, by calling
\r
516 // netdata.serviceExecute()
\r
517 update: function(service, callback) {
\r
518 netdata.serviceExecute(service, function(serv, data) {
\r
519 service.module.processResponse(serv, data);
\r
525 module.exports = named;
\r