3 // collect statistics from bind (named) v9.10+
\r
5 // bind statistics documentation at:
\r
6 // https://ftp.isc.org/isc/bind/9.10.3/doc/arm/Bv9ARM.ch06.html#statistics
\r
8 // example configuration in /etc/netdata/named.conf
\r
9 // the module supports auto-detection if bind is running in localhost
\r
13 "enable_autodetect": true,
\r
18 "url": "http://127.0.0.1:8888/json/v1",
\r
23 "url": "http://10.1.2.3:8888/json/v1",
\r
30 // the following is the bind named.conf configuration required
\r
33 statistics-channels {
\r
34 inet 127.0.0.1 port 8888 allow { 127.0.0.1; };
\r
38 var url = require('url');
\r
39 var http = require('http');
\r
40 var netdata = require('netdata');
\r
42 if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plugin');
\r
46 enable_autodetect: true,
\r
51 chartFromMembersCreate: function(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor) {
\r
53 id: id, // the unique id of the chart
\r
54 name: '', // the unique name of the chart
\r
55 title: service.name + ' ' + title_suffix, // the title of the chart
\r
56 units: units, // the units of the chart dimensions
\r
57 family: family_prefix + '_' + service.name, // the family of the chart
\r
58 category: category_prefix + '_' + service.name, // the category of the chart
\r
59 type: type, // the type of the chart
\r
60 priority: priority, // the priority relative to others in the same family and category
\r
61 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
67 if(typeof(obj[x]) !== 'undefined' && obj[x] !== 0) {
\r
69 chart.dimensions[x] = {
\r
70 id: x, // the unique id of the dimension
\r
71 name: x, // the name of the dimension
\r
72 algorithm: algorithm, // the id of the netdata algorithm
\r
73 multiplier: multiplier, // the multiplier
\r
74 divisor: divisor, // the divisor
\r
75 hidden: false // is hidden (boolean)
\r
83 chart = service.chart(id, chart);
\r
84 this.charts[id] = chart;
\r
88 chartFromMembers: function(service, obj, id_suffix, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor) {
\r
89 var id = 'named_' + service.name + '.' + id_suffix;
\r
90 var chart = this.charts[id];
\r
92 if(typeof chart === 'undefined') {
\r
93 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor);
\r
94 if(chart === null) return false;
\r
97 // check if we need to re-generate the chart
\r
99 if(typeof(chart.dimensions[x]) === 'undefined') {
\r
100 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family_prefix, category_prefix, type, priority, algorithm, multiplier, divisor);
\r
101 if(chart === null) return false;
\r
108 service.begin(chart);
\r
109 for(var x in obj) {
\r
110 if(typeof(chart.dimensions[x]) !== 'undefined') {
\r
112 service.set(x, obj[x]);
\r
117 if(found > 0) return true;
\r
121 // an index to map values to different charts
\r
124 resolver_stats: {},
\r
128 processResponse: function(service, data) {
\r
129 if(data !== null) {
\r
130 var r = JSON.parse(data);
\r
132 if(service.added !== true)
\r
133 netdata.serviceAdd(service);
\r
135 if(typeof r.nsstats !== 'undefined') {
\r
136 // we split the nsstats object to several others
\r
137 var global_requests = {}, global_requests_enable = false;
\r
138 var global_failures = {}, global_failures_enable = false;
\r
139 var global_failures_detail = {}, global_failures_detail_enable = false;
\r
140 var global_updates = {}, global_updates_enable = false;
\r
141 var protocol_queries = {}, protocol_queries_enable = false;
\r
142 var global_queries = {}, global_queries_enable = false;
\r
143 var global_queries_success = {}, global_queries_success_enable = false;
\r
144 var default_enable = false;
\r
145 var RecursClients = 0;
\r
147 // RecursClients is an absolute value
\r
148 if(typeof r.nsstats['RecursClients'] !== 'undefined') {
\r
149 RecursClients = r.nsstats['RecursClients'];
\r
150 delete r.nsstats['RecursClients'];
\r
153 for( var x in r.nsstats ) {
\r
154 // we maintain an index of the values found
\r
155 // mapping them to objects splitted
\r
157 var look = named.lookups.nsstats[x];
\r
158 if(typeof look === 'undefined') {
\r
159 // a new value, not found in the index
\r
161 if(x === 'Requestv4') {
\r
162 named.lookups.nsstats[x] = {
\r
164 type: 'global_requests'
\r
167 else if(x === 'Requestv6') {
\r
168 named.lookups.nsstats[x] = {
\r
170 type: 'global_requests'
\r
173 else if(x === 'QryFailure') {
\r
174 named.lookups.nsstats[x] = {
\r
176 type: 'global_failures'
\r
179 else if(x === 'QryUDP') {
\r
180 named.lookups.nsstats[x] = {
\r
182 type: 'protocol_queries'
\r
185 else if(x === 'QryTCP') {
\r
186 named.lookups.nsstats[x] = {
\r
188 type: 'protocol_queries'
\r
191 else if(x === 'QrySuccess') {
\r
192 named.lookups.nsstats[x] = {
\r
194 type: 'global_queries_success'
\r
197 else if(x.match(/QryRej$/) !== null) {
\r
198 named.lookups.nsstats[x] = {
\r
200 type: 'global_failures_detail'
\r
203 else if(x.match(/^Qry/) !== null) {
\r
204 named.lookups.nsstats[x] = {
\r
206 type: 'global_queries'
\r
209 else if(x.match(/^Update/) !== null) {
\r
210 named.lookups.nsstats[x] = {
\r
212 type: 'global_updates'
\r
216 // values not mapped, will remain
\r
217 // in the default map
\r
218 named.lookups.nsstats[x] = {
\r
224 look = named.lookups.nsstats[x];
\r
225 // netdata.error('lookup nsstats value: ' + x + ' >>> ' + named.lookups.nsstats[x].type);
\r
228 switch(look.type) {
\r
229 case 'global_requests': global_requests[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_requests_enable = true; break;
\r
230 case 'global_queries': global_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_enable = true; break;
\r
231 case 'global_queries_success': global_queries_success[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_queries_success_enable = true; break;
\r
232 case 'global_updates': global_updates[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_updates_enable = true; break;
\r
233 case 'protocol_queries': protocol_queries[look.name] = r.nsstats[x]; delete r.nsstats[x]; protocol_queries_enable = true; break;
\r
234 case 'global_failures': global_failures[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_enable = true; break;
\r
235 case 'global_failures_detail': global_failures_detail[look.name] = r.nsstats[x]; delete r.nsstats[x]; global_failures_detail_enable = true; break;
\r
236 default: default_enable = true; break;
\r
240 if(global_requests_enable == true)
\r
241 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
243 if(global_queries_success_enable == true)
\r
244 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
246 if(protocol_queries_enable == true)
\r
247 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
249 if(global_queries_enable == true)
\r
250 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
252 if(global_updates_enable == true)
\r
253 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
255 if(global_failures_enable == true)
\r
256 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
258 if(global_failures_detail_enable == true)
\r
259 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
261 if(default_enable === true)
\r
262 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
264 // RecursClients chart
\r
266 var id = 'named_' + service.name + '.recursive_clients';
\r
267 var chart = named.charts[id];
\r
269 if(typeof chart === 'undefined') {
\r
271 id: id, // the unique id of the chart
\r
272 name: '', // the unique name of the chart
\r
273 title: service.name + ' Bind, Current Recursive Clients', // the title of the chart
\r
274 units: 'clients', // the units of the chart dimensions
\r
275 family: 'named', // the family of the chart
\r
276 category: 'named', // the category of the chart
\r
277 type: netdata.chartTypes.line, // the type of the chart
\r
278 priority: 150, // the priority relative to others in the same family and category
\r
279 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
282 id: 'clients', // the unique id of the dimension
\r
283 name: '', // the name of the dimension
\r
284 algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
\r
285 multiplier: 1, // the multiplier
\r
286 divisor: 1, // the divisor
\r
287 hidden: false // is hidden (boolean)
\r
292 chart = service.chart(id, chart);
\r
293 named.charts[id] = chart;
\r
296 service.begin(chart);
\r
297 service.set('clients', RecursClients);
\r
302 if(typeof r.opcodes !== 'undefined')
\r
303 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
305 if(typeof r.qtypes !== 'undefined')
\r
306 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
308 if(typeof r.views !== 'undefined') {
\r
309 for( var x in r.views ) {
\r
310 var resolver = r.views[x].resolver;
\r
312 if(typeof resolver !== 'undefined') {
\r
313 if(typeof resolver.stats !== 'undefined') {
\r
315 var key = service.name + '.' + x;
\r
316 var default_enable = false;
\r
317 var rtt = {}, rtt_enable = false;
\r
319 // NumFetch is an absolute value
\r
320 if(typeof resolver.stats['NumFetch'] !== 'undefined') {
\r
321 named.lookups.numfetch[key] = true;
\r
322 NumFetch = resolver.stats['NumFetch'];
\r
323 delete resolver.stats['NumFetch'];
\r
325 if(typeof resolver.stats['BucketSize'] !== 'undefined') {
\r
326 delete resolver.stats['BucketSize'];
\r
329 // split the QryRTT* from the main chart
\r
330 for( var y in resolver.stats ) {
\r
331 // we maintain an index of the values found
\r
332 // mapping them to objects splitted
\r
334 var look = named.lookups.resolver_stats[y];
\r
335 if(typeof look === 'undefined') {
\r
336 if(y.match(/^QryRTT/) !== null) {
\r
337 named.lookups.resolver_stats[y] = {
\r
343 named.lookups.resolver_stats[y] = {
\r
349 look = named.lookups.resolver_stats[y];
\r
350 // netdata.error('lookup resolver stats value: ' + y + ' >>> ' + look.type);
\r
353 switch(look.type) {
\r
354 case 'rtt': rtt[look.name] = resolver.stats[y]; delete resolver.stats[y]; rtt_enable = true; break;
\r
355 default: default_enable = true; break;
\r
360 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
363 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
366 if(typeof named.lookups.numfetch[key] !== 'undefined') {
\r
367 var id = 'named_' + service.name + '.view_resolver_numfetch_' + x;
\r
368 var chart = named.charts[id];
\r
370 if(typeof chart === 'undefined') {
\r
372 id: id, // the unique id of the chart
\r
373 name: '', // the unique name of the chart
\r
374 title: service.name + ' Bind, ' + x + ' View, Resolver Active Queries', // the title of the chart
\r
375 units: 'queries', // the units of the chart dimensions
\r
376 family: 'named', // the family of the chart
\r
377 category: 'named', // the category of the chart
\r
378 type: netdata.chartTypes.line, // the type of the chart
\r
379 priority: 5000, // the priority relative to others in the same family and category
\r
380 update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
\r
383 id: 'queries', // the unique id of the dimension
\r
384 name: '', // the name of the dimension
\r
385 algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
\r
386 multiplier: 1, // the multiplier
\r
387 divisor: 1, // the divisor
\r
388 hidden: false // is hidden (boolean)
\r
393 chart = service.chart(id, chart);
\r
394 named.charts[id] = chart;
\r
397 service.begin(chart);
\r
398 service.set('queries', NumFetch);
\r
403 if(typeof resolver.qtypes !== 'undefined')
\r
404 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 // module.serviceExecute()
\r
412 // this function is called only from this module
\r
413 // its purpose is to prepare the request and call
\r
414 // netdata.serviceExecute()
\r
415 serviceExecute: function(name, a_url, update_every) {
\r
416 if(netdata.options.DEBUG === true) netdata.debug(this.name + ': ' + name + ': url: ' + a_url + ', update_every: ' + update_every);
\r
417 netdata.serviceExecute({
\r
419 request: netdata.requestFromURL(a_url),
\r
420 update_every: update_every,
\r
424 }, this.processResponse);
\r
427 configure: function(config) {
\r
430 if(this.enable_autodetect === true) {
\r
431 this.serviceExecute('local', 'http://localhost:8888/json/v1', this.update_every);
\r
435 if(typeof(config.servers) !== 'undefined') {
\r
436 var len = config.servers.length;
\r
438 if(typeof config.servers[len].update_every === 'undefined')
\r
439 config.servers[len].update_every = this.update_every;
\r
441 config.servers[len].update_every = config.servers[len].update_every * 1000;
\r
443 this.serviceExecute(config.servers[len].name, config.servers[len].url, config.servers[len].update_every);
\r
452 // this is called repeatidly to collect data, by calling
\r
453 // netdata.serviceExecute()
\r
454 update: function(service, callback) {
\r
455 netdata.serviceExecute(service, function(serv, data) {
\r
456 service.module.processResponse(serv, data);
\r
462 module.exports = named;
\r