@cryptotaxi247 / netdata-1 / commits / be5b69fcd

changes suggested by codeclimate

Costa Tsaousis (ktsaou) committed Jan 7, 2017 at 01:23 UTC be5b69fcd142bb7698d98ddfb0e6c912f6d6667a
3 files changed +181 -122
.codeclimate.yml
+12 -1
@@ -10,14 +10,25 @@ engines:
10 - javascript
11 - python
12 - php
13 + checks:
14 + Similar code:
15 + enabled: false
16 eslint:
17 enabled: true
18 + checks:
19 + max-statements:
20 + enabled: false
21 + complexity:
22 + enabled: false
23 fixme:
16 - enabled: true
24 + enabled: false
25 phpmd:
26 enabled: true
27 radon:
28 enabled: true
29 + checks:
30 + Complexity:
31 + enabled: false
32 ratings:
33 paths:
34 - "**.css"
node.d/named.node.js
+93 -70
@@ -41,7 +41,7 @@ var http = require('http');
41 var XML = require('pixl-xml');
42 var netdata = require('netdata');
43
44 -if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plugin');
44 +if(netdata.options.DEBUG === true) netdata.debug('loaded', __filename, 'plugin');
45
46 var named = {
47 name: __filename,
@@ -62,10 +62,14 @@ var named = {
62 priority: priority, // the priority relative to others in the same family
63 update_every: service.update_every, // the expected update frequency of the chart
64 dimensions: {}
65 - }
65 + };
66
67 var found = 0;
68 - for(var x in obj) {
68 + var dims = Object.keys(obj);
69 + var len = dims.length;
70 + for(var i = 0; i < len ;i++) {
71 + var x = dims[i];
72 +
73 if(typeof(obj[x]) !== 'undefined' && obj[x] !== 0) {
74 found++;
75 chart.dimensions[x] = {
@@ -90,6 +94,7 @@ var named = {
94 chartFromMembers: function(service, obj, id_suffix, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor) {
95 var id = 'named_' + service.name + '.' + id_suffix;
96 var chart = this.charts[id];
97 + var dims, len, x, i;
98
99 if(typeof chart === 'undefined') {
100 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor);
@@ -97,7 +102,10 @@ var named = {
102 }
103 else {
104 // check if we need to re-generate the chart
100 - for(var x in obj) {
105 + dims = Object.keys(obj);
106 + len = dims.length;
107 + for(i = 0; i < len ;i++) {
108 + x = dims[i];
109 if(typeof(chart.dimensions[x]) === 'undefined') {
110 chart = this.chartFromMembersCreate(service, obj, id, title_suffix, units, family, context, type, priority, algorithm, multiplier, divisor);
111 if(chart === null) return false;
@@ -106,18 +114,22 @@ var named = {
114 }
115 }
116
109 - var found = 0;
117 service.begin(chart);
111 - for(var x in obj) {
118 +
119 + var found = 0;
120 + dims = Object.keys(obj);
121 + len = dims.length;
122 + for(i = 0; i < len ;i++) {
123 + x = dims[i];
124 if(typeof(chart.dimensions[x]) !== 'undefined') {
125 found++;
126 service.set(x, obj[x]);
127 }
128 }
129 +
130 service.end();
131
119 - if(found > 0) return true;
120 - return false;
132 + return (found > 0);
133 },
134
135 // an index to map values to different charts
@@ -133,19 +145,21 @@ var named = {
145 var d = XML.parse(data_xml);
146 if(d === null) return null;
147
148 + var a, aa, alen, alen2;
149 +
150 var data = {};
151 var len = d.server.counters.length;
152 while(len--) {
139 - var a = d.server.counters[len];
153 + a = d.server.counters[len];
154 if(typeof a.counter === 'undefined') continue;
155 if(a.type === 'opcode') a.type = 'opcodes';
156 else if(a.type === 'qtype') a.type = 'qtypes';
157 else if(a.type === 'nsstat') a.type = 'nsstats';
144 - var aa = data[a.type] = {};
145 - var alen = 0
146 - var alen2 = a.counter.length;
158 + aa = data[a.type] = {};
159 + alen = 0;
160 + alen2 = a.counter.length;
161 while(alen < alen2) {
148 - aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data);
162 + aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data, 10);
163 alen++;
164 }
165 }
@@ -155,18 +169,18 @@ var named = {
169 while(vlen--) {
170 var vname = d.views.view[vlen].name;
171 data.views[vname] = { resolver: {} };
158 - var len = d.views.view[vlen].counters.length;
172 + len = d.views.view[vlen].counters.length;
173 while(len--) {
160 - var a = d.views.view[vlen].counters[len];
174 + a = d.views.view[vlen].counters[len];
175 if(typeof a.counter === 'undefined') continue;
176 if(a.type === 'resstats') a.type = 'stats';
177 else if(a.type === 'resqtype') a.type = 'qtypes';
178 else if(a.type === 'adbstat') a.type = 'adb';
165 - var aa = data.views[vname].resolver[a.type] = {};
166 - var alen = 0;
167 - var alen2 = a.counter.length;
179 + aa = data.views[vname].resolver[a.type] = {};
180 + alen = 0;
181 + alen2 = a.counter.length;
182 while(alen < alen2) {
169 - aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data);
183 + aa[a.counter[alen].name] = parseInt(a.counter[alen]._Data, 10);
184 alen++;
185 }
186 }
@@ -177,7 +191,7 @@ var named = {
191
192 processResponse: function(service, data) {
193 if(data !== null) {
180 - var r;
194 + var r, x, look, id, chart, keys, len;
195
196 // parse XML or JSON
197 // pepending on the URL given
@@ -212,11 +226,15 @@ var named = {
226 delete r.nsstats['RecursClients'];
227 }
228
215 - for( var x in r.nsstats ) {
229 + keys = Object.keys(r.nsstats);
230 + len = keys.length;
231 + while(len--) {
232 + x = keys[len];
233 +
234 // we maintain an index of the values found
235 // mapping them to objects splitted
236
219 - var look = named.lookups.nsstats[x];
237 + look = named.lookups.nsstats[x];
238 if(typeof look === 'undefined') {
239 // a new value, not found in the index
240 // index it:
@@ -299,66 +317,64 @@ var named = {
317 }
318 }
319
302 - if(global_requests_enable == true)
320 + if(global_requests_enable === true)
321 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);
322
305 - if(global_queries_success_enable == true)
323 + if(global_queries_success_enable === true)
324 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);
325
308 - if(protocol_queries_enable == true)
326 + if(protocol_queries_enable === true)
327 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);
328
311 - if(global_queries_enable == true)
329 + if(global_queries_enable === true)
330 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);
331
314 - if(global_updates_enable == true)
332 + if(global_updates_enable === true)
333 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);
334
317 - if(global_failures_enable == true)
335 + if(global_failures_enable === true)
336 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);
337
320 - if(global_failures_detail_enable == true)
338 + if(global_failures_detail_enable === true)
339 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);
340
341 if(default_enable === true)
342 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);
343
344 // RecursClients chart
327 - {
328 - var id = 'named_' + service.name + '.recursive_clients';
329 - var chart = named.charts[id];
330 -
331 - if(typeof chart === 'undefined') {
332 - chart = {
333 - id: id, // the unique id of the chart
334 - name: '', // the unique name of the chart
335 - title: service.name + ' Bind, Current Recursive Clients', // the title of the chart
336 - units: 'clients', // the units of the chart dimensions
337 - family: 'clients', // the family of the chart
338 - context: 'named.recursive_clients', // the context of the chart
339 - type: netdata.chartTypes.line, // the type of the chart
340 - priority: named.base_priority + 1, // the priority relative to others in the same family
341 - update_every: service.update_every, // the expected update frequency of the chart
342 - dimensions: {
343 - 'clients': {
344 - id: 'clients', // the unique id of the dimension
345 - name: '', // the name of the dimension
346 - algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
347 - multiplier: 1, // the multiplier
348 - divisor: 1, // the divisor
349 - hidden: false // is hidden (boolean)
350 - }
345 + id = 'named_' + service.name + '.recursive_clients';
346 + chart = named.charts[id];
347 +
348 + if(typeof chart === 'undefined') {
349 + chart = {
350 + id: id, // the unique id of the chart
351 + name: '', // the unique name of the chart
352 + title: service.name + ' Bind, Current Recursive Clients', // the title of the chart
353 + units: 'clients', // the units of the chart dimensions
354 + family: 'clients', // the family of the chart
355 + context: 'named.recursive_clients', // the context of the chart
356 + type: netdata.chartTypes.line, // the type of the chart
357 + priority: named.base_priority + 1, // the priority relative to others in the same family
358 + update_every: service.update_every, // the expected update frequency of the chart
359 + dimensions: {
360 + 'clients': {
361 + id: 'clients', // the unique id of the dimension
362 + name: '', // the name of the dimension
363 + algorithm: netdata.chartAlgorithms.absolute,// the id of the netdata algorithm
364 + multiplier: 1, // the multiplier
365 + divisor: 1, // the divisor
366 + hidden: false // is hidden (boolean)
367 }
352 - };
353 -
354 - chart = service.chart(id, chart);
355 - named.charts[id] = chart;
356 - }
368 + }
369 + };
370
358 - service.begin(chart);
359 - service.set('clients', RecursClients);
360 - service.end();
371 + chart = service.chart(id, chart);
372 + named.charts[id] = chart;
373 }
374 +
375 + service.begin(chart);
376 + service.set('clients', RecursClients);
377 + service.end();
378 }
379
380 if(typeof r.opcodes !== 'undefined')
@@ -371,15 +387,18 @@ var named = {
387 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);
388
389 if(typeof r.views !== 'undefined') {
374 - for( var x in r.views ) {
390 + keys = Object.keys(r.views);
391 + len = keys.length;
392 + while(len--) {
393 + x = keys[len];
394 var resolver = r.views[x].resolver;
395
396 if(typeof resolver !== 'undefined') {
397 if(typeof resolver.stats !== 'undefined') {
398 var NumFetch = 0;
399 var key = service.name + '.' + x;
381 - var default_enable = false;
400 var rtt = {}, rtt_enable = false;
401 + default_enable = false;
402
403 // NumFetch is an absolute value
404 if(typeof resolver.stats['NumFetch'] !== 'undefined') {
@@ -392,11 +411,15 @@ var named = {
411 }
412
413 // split the QryRTT* from the main chart
395 - for( var y in resolver.stats ) {
414 + var ykeys = Object.keys(resolver.stats);
415 + var ylen = ykeys.length;
416 + while(ylen--) {
417 + var y = ykeys[ylen];
418 +
419 // we maintain an index of the values found
420 // mapping them to objects splitted
421
399 - var look = named.lookups.resolver_stats[y];
422 + look = named.lookups.resolver_stats[y];
423 if(typeof look === 'undefined') {
424 if(y.match(/^QryRTT/) !== null) {
425 named.lookups.resolver_stats[y] = {
@@ -429,8 +452,8 @@ var named = {
452
453 // NumFetch chart
454 if(typeof named.lookups.numfetch[key] !== 'undefined') {
432 - var id = 'named_' + service.name + '.view_resolver_numfetch_' + x;
433 - var chart = named.charts[id];
455 + id = 'named_' + service.name + '.view_resolver_numfetch_' + x;
456 + chart = named.charts[id];
457
458 if(typeof chart === 'undefined') {
459 chart = {
@@ -473,8 +496,8 @@ var named = {
496 // 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);
497
498 if(typeof resolver.cachestats['CacheHits'] !== 'undefined' && resolver.cachestats['CacheHits'] > 0) {
476 - var id = 'named_' + service.name + '.view_resolver_cachehits_' + x;
477 - var chart = named.charts[id];
499 + id = 'named_' + service.name + '.view_resolver_cachehits_' + x;
500 + chart = named.charts[id];
501
502 if(typeof chart === 'undefined') {
503 chart = {
@@ -580,7 +603,7 @@ var named = {
603 service.module.processResponse(serv, data);
604 callback();
605 });
583 - },
606 + }
607 };
608
609 module.exports = named;
node.d/node_modules/netdata.js
+76 -51
@@ -48,7 +48,7 @@ var netdata = {
48 options: {
49 filename: __filename,
50 DEBUG: false,
51 - update_every: 1,
51 + update_every: 1
52 },
53
54 chartAlgorithms: {
@@ -74,10 +74,13 @@ var netdata = {
74 name: 'http',
75
76 process: function(service, callback) {
77 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': making ' + this.name + ' request: ' + netdata.stringify(service.request));
77 + var __DEBUG = netdata.options.DEBUG;
78 +
79 + if(__DEBUG === true)
80 + netdata.debug(service.module.name + ': ' + service.name + ': making ' + this.name + ' request: ' + netdata.stringify(service.request));
81
82 var req = http.request(service.request, function(response) {
80 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got server response...');
83 + if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got server response...');
84
85 var end = false;
86 var data = '';
@@ -87,7 +90,7 @@ var netdata = {
90 if(end === false) {
91 service.error('Got HTTP code ' + response.statusCode + ', failed to get data.');
92 end = true;
90 - callback(null);
93 + return callback(null);
94 }
95 }
96
@@ -99,28 +102,28 @@ var netdata = {
102 if(end === false) {
103 service.error(': Read error, failed to get data.');
104 end = true;
102 - callback(null);
105 + return callback(null);
106 }
107 });
108
109 response.on('end', function() {
110 if(end === false) {
108 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': read completed.');
111 + if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': read completed.');
112 end = true;
110 - callback(data);
113 + return callback(data);
114 }
115 });
116 });
117
118 req.on('error', function(e) {
116 - if(netdata.options.DEBUG === true) netdata.debug('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);
119 + if(__DEBUG === true) netdata.debug('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);
120 service.error('Failed to make request, message: ' + e.message);
118 - callback(null);
121 + return callback(null);
122 });
123
124 // write data to request body
125 if(typeof service.postData !== 'undefined' && service.request.method === 'POST') {
123 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': posting data: ' + service.postData);
126 + if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': posting data: ' + service.postData);
127 req.write(service.postData);
128 }
129
@@ -215,18 +218,18 @@ var netdata = {
218 }
219 };
220
218 - service.execute = function(callback) {
219 - if(service.enabled === false) {
220 - callback(null);
221 - return;
222 - }
221 + service.execute = function(responseProcessor) {
222 + var __DEBUG = netdata.options.DEBUG;
223 +
224 + if(service.enabled === false)
225 + return responseProcessor(null);
226
227 this.module.active++;
228 this.running = true;
229 this.started = Date.now();
230 this.updates++;
231
229 - if(netdata.options.DEBUG === true)
232 + if(__DEBUG === true)
233 netdata.debug(this.module.name + ': ' + this.name + ': making ' + this.processor.name + ' request: ' + netdata.stringify(this));
234
235 this.processor.process(this, function(response) {
@@ -239,35 +242,40 @@ var netdata = {
242 if(response !== null)
243 service.errorClear();
244
242 - if(netdata.options.DEBUG === true)
245 + if(__DEBUG === true)
246 netdata.debug(service.module.name + ': ' + service.name + ': processing ' + service.processor.name + ' response (received in ' + (service.ended - service.started).toString() + ' ms)');
247
245 - callback(service, response);
248 + responseProcessor(service, response);
249
250 service.running = false;
251 service.module.active--;
252 if(service.module.active < 0) {
253 service.module.active = 0;
251 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': active module counter below zero.');
254 + if(__DEBUG === true)
255 + netdata.debug(service.module.name + ': active module counter below zero.');
256 }
257
258 if(service.module.active === 0) {
259 // check if we run under configure
260 if(service.module.configure_callback !== null) {
257 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': configuration finish callback called from processResponse().');
258 - var ccallback = service.module.configure_callback;
261 + if(__DEBUG === true)
262 + netdata.debug(service.module.name + ': configuration finish callback called from processResponse().');
263 +
264 + var configure_callback = service.module.configure_callback;
265 service.module.configure_callback = null;
260 - ccallback();
266 + configure_callback();
267 }
268 }
269 });
270 };
271
272 service.update = function() {
267 - if(netdata.options.DEBUG === true) netdata.debug(this.module.name + ': ' + this.name + ': starting data collection...');
273 + if(netdata.options.DEBUG === true)
274 + netdata.debug(this.module.name + ': ' + this.name + ': starting data collection...');
275
276 this.module.update(this, function() {
270 - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': data collection ended in ' + service.duration.toString() + ' ms.');
277 + if(netdata.options.DEBUG === true)
278 + netdata.debug(service.module.name + ': ' + service.name + ': data collection ended in ' + service.duration.toString() + ' ms.');
279 });
280 };
281
@@ -291,13 +299,17 @@ var netdata = {
299 service._send_chart_to_netdata = function(chart) {
300 // internal function to send a chart to netdata
301 this.queue('CHART "' + chart.id + '" "' + chart.name + '" "' + chart.title + '" "' + chart.units + '" "' + chart.family + '" "' + chart.context + '" "' + chart.type + '" ' + chart.priority.toString() + ' ' + chart.update_every.toString());
294 -
295 - for(var dim in chart.dimensions) {
296 - var d = chart.dimensions[dim];
302
298 - this.queue('DIMENSION "' + d.id + '" "' + d.name + '" "' + d.algorithm + '" ' + d.multiplier.toString() + ' ' + d.divisor.toString() + ' ' + ((d.hidden === true)?'hidden':'').toString());
299 - d._created = true;
300 - d._updated = false;
303 + if(typeof(chart.dimensions) !== 'undefined') {
304 + var dims = Object.keys(chart.dimensions);
305 + var len = dims.length;
306 + while(len--) {
307 + var d = chart.dimensions[dims[len]];
308 +
309 + this.queue('DIMENSION "' + d.id + '" "' + d.name + '" "' + d.algorithm + '" ' + d.multiplier.toString() + ' ' + d.divisor.toString() + ' ' + ((d.hidden === true) ? 'hidden' : '').toString());
310 + d._created = true;
311 + d._updated = false;
312 + }
313 }
314
315 chart._created = true;
@@ -311,7 +323,7 @@ var netdata = {
323 this.end();
324 }
325
314 - if(typeof(chart.id) === 'undefined' || netdata.charts[chart.id] != chart) {
326 + if(typeof(chart.id) === 'undefined' || netdata.charts[chart.id] !== chart) {
327 this.error('Called begin() for chart ' + chart.id + ' that is not mine. Where did you find it? Ignoring it.');
328 return false;
329 }
@@ -396,6 +408,8 @@ var netdata = {
408
409 // create a netdata chart
410 service.chart = function(id, chart) {
411 + var __DEBUG = netdata.options.DEBUG;
412 +
413 if(typeof(netdata.charts[id]) === 'undefined') {
414 netdata.charts[id] = {
415 _created: false,
@@ -420,55 +434,59 @@ var netdata = {
434 var c = netdata.charts[id];
435
436 if(typeof(chart.name) !== 'undefined' && chart.name !== c.name) {
423 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its name');
437 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its name');
438 c.name = chart.name;
439 c._updated = true;
440 }
441
442 if(typeof(chart.title) !== 'undefined' && chart.title !== c.title) {
429 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its title');
443 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its title');
444 c.title = chart.title;
445 c._updated = true;
446 }
447
448 if(typeof(chart.units) !== 'undefined' && chart.units !== c.units) {
435 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its units');
449 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its units');
450 c.units = chart.units;
451 c._updated = true;
452 }
453
454 if(typeof(chart.family) !== 'undefined' && chart.family !== c.family) {
441 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its family');
455 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its family');
456 c.family = chart.family;
457 c._updated = true;
458 }
459
460 if(typeof(chart.context) !== 'undefined' && chart.context !== c.context) {
447 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its context');
461 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its context');
462 c.context = chart.context;
463 c._updated = true;
464 }
465
466 if(typeof(chart.type) !== 'undefined' && chart.type !== c.type) {
453 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its type');
467 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its type');
468 c.type = chart.type;
469 c._updated = true;
470 }
471
472 if(typeof(chart.priority) !== 'undefined' && chart.priority !== c.priority) {
459 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its priority');
473 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its priority');
474 c.priority = chart.priority;
475 c._updated = true;
476 }
477
478 if(typeof(chart.update_every) !== 'undefined' && chart.update_every !== c.update_every) {
465 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' updated its update_every from ' + c.update_every + ' to ' + chart.update_every);
479 + if(__DEBUG === true) netdata.debug('chart ' + id + ' updated its update_every from ' + c.update_every + ' to ' + chart.update_every);
480 c.update_every = chart.update_every;
481 c._updated = true;
482 }
483
484 if(typeof(chart.dimensions) !== 'undefined') {
471 - for(var x in chart.dimensions) {
485 + var dims = Object.keys(chart.dimensions);
486 + var len = dims.length;
487 + while(len--) {
488 + var x = dims[len];
489 +
490 if(typeof(c.dimensions[x]) === 'undefined') {
491 c._dimensions_count++;
492
@@ -480,10 +498,10 @@ var netdata = {
498 algorithm: netdata.chartAlgorithms.absolute, // the id of the netdata algorithm
499 multiplier: 1, // the multiplier
500 divisor: 1, // the divisor
483 - hidden: false, // is hidden (boolean)
501 + hidden: false // is hidden (boolean)
502 };
503
486 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ' created dimension ' + x);
504 + if(__DEBUG === true) netdata.debug('chart ' + id + ' created dimension ' + x);
505 c._updated = true;
506 }
507
@@ -491,31 +509,31 @@ var netdata = {
509 var d = c.dimensions[x];
510
511 if(typeof(dim.name) !== 'undefined' && d.name !== dim.name) {
494 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its name');
512 + if(__DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its name');
513 d.name = dim.name;
514 d._updated = true;
515 }
516
517 if(typeof(dim.algorithm) !== 'undefined' && d.algorithm !== dim.algorithm) {
500 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its algorithm from ' + d.algorithm + ' to ' + dim.algorithm);
518 + if(__DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its algorithm from ' + d.algorithm + ' to ' + dim.algorithm);
519 d.algorithm = dim.algorithm;
520 d._updated = true;
521 }
522
523 if(typeof(dim.multiplier) !== 'undefined' && d.multiplier !== dim.multiplier) {
506 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its multiplier');
524 + if(__DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its multiplier');
525 d.multiplier = dim.multiplier;
526 d._updated = true;
527 }
528
529 if(typeof(dim.divisor) !== 'undefined' && d.divisor !== dim.divisor) {
512 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its divisor');
530 + if(__DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its divisor');
531 d.divisor = dim.divisor;
532 d._updated = true;
533 }
534
535 if(typeof(dim.hidden) !== 'undefined' && d.hidden !== dim.hidden) {
518 - if(netdata.options.DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its hidden status');
536 + if(__DEBUG === true) netdata.debug('chart ' + id + ', dimension ' + x + ' updated its hidden status');
537 d.hidden = dim.hidden;
538 d._updated = true;
539 }
@@ -557,7 +575,10 @@ var netdata = {
575
576 if(this.services.length === 0) {
577 this.disableNodePlugin();
560 - process.exit(1);
578 +
579 + // eslint suggested way to exit
580 + var exit = process.exit;
581 + exit(1);
582 }
583 else this.runAllServices();
584 },
@@ -565,7 +586,10 @@ var netdata = {
586 // disable the whole node.js plugin
587 disableNodePlugin: function() {
588 this.send('DISABLE');
568 - process.exit(1);
589 +
590 + // eslint suggested way to exit
591 + var exit = process.exit;
592 + exit(1);
593 },
594
595 requestFromParams: function(protocol, hostname, port, path, method) {
@@ -616,13 +640,14 @@ var netdata = {
640
641 if(module.configure_callback !== null && added === 0) {
642 if(netdata.options.DEBUG === true) this.debug(module.name + ': configuration finish callback called from configure().');
643 + var configure_callback = module.configure_callback;
644 module.configure_callback = null;
620 - callback();
645 + configure_callback();
646 }
647
648 return added;
649 }
650 };
651
627 -if(netdata.options.DEBUG === true) netdata.debug('loaded netdata from: ' + __filename);
652 +if(netdata.options.DEBUG === true) netdata.debug('loaded netdata from:', __filename);
653 module.exports = netdata;