X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=node.d%2Fnode_modules%2Fnetdata.js;h=f371f55d47fa35e4c6d5396656fee7f90d647e18;hb=28d959d98dfd2a02810a5e184a602d6da9abfd5c;hp=1e594ba0b7801520f140463e5d9de226b7a555d7;hpb=933d181e0d94f35ae29cd6aa10b1d9ef4eedcbb7;p=netdata.git diff --git a/node.d/node_modules/netdata.js b/node.d/node_modules/netdata.js index 1e594ba0..f371f55d 100755 --- a/node.d/node_modules/netdata.js +++ b/node.d/node_modules/netdata.js @@ -87,6 +87,9 @@ var netdata = { }, serviceAdd: function(service) { + if(netdata.serviceIsInitialized(service) === false) + netdata.serviceInit(service); + if(service.added !== true) { service.updates = 0; service.enabled = true; @@ -119,12 +122,12 @@ var netdata = { // begin data collection for a chart service.begin = function(chart) { if(this._current_chart !== null && this._current_chart !== chart) { - netdata.error('Called begin() for chart ' + chart.id + ' while chart ' + this._current_chart.id + ' is still open. Closing it.'); + netdata.serviceError(this, 'Called begin() for chart ' + chart.id + ' while chart ' + this._current_chart.id + ' is still open. Closing it.'); this.end(); } if(typeof(chart.id) === 'undefined' || netdata.charts[chart.id] != chart) { - netdata.error('Called begin() for chart ' + chart.id + ' that is not mine. Where did you find it? Ignoring it.'); + netdata.serviceError(this, 'Called begin() for chart ' + chart.id + ' that is not mine. Where did you find it? Ignoring it.'); return false; } @@ -139,7 +142,7 @@ var netdata = { var now = this.ended; this.queue('BEGIN ' + this._current_chart.id + ' ' + ((this._current_chart._last_updated > 0)?((now - this._current_chart._last_updated) * 1000):'').toString()); } - // else netdata.error('Called begin() for chart ' + chart.id + ' which is empty.'); + // else netdata.serviceError(this, 'Called begin() for chart ' + chart.id + ' which is empty.'); this._current_chart._last_updated = now; this._current_chart._began = true; @@ -152,12 +155,12 @@ var netdata = { // we do most things on the first value we attempt to set service.set = function(dimension, value) { if(this._current_chart === null) { - netdata.error('Called set(' + dimension + ', ' + value + ') without an open chart.'); + netdata.serviceError(this, 'Called set(' + dimension + ', ' + value + ') without an open chart.'); return false; } if(typeof(this._current_chart.dimensions[dimension]) === 'undefined') { - netdata.error('Called set(' + dimension + ', ' + value + ') but dimension "' + dimension + '" does not exist in chart "' + this._current_chart.id + '".'); + netdata.serviceError(this, 'Called set(' + dimension + ', ' + value + ') but dimension "' + dimension + '" does not exist in chart "' + this._current_chart.id + '".'); return false; } @@ -170,7 +173,7 @@ var netdata = { // end data collection for the current chart - after calling begin() service.end = function() { if(this._current_chart !== null && this._current_chart._began === false) { - netdata.error('Called end() without an open chart.'); + netdata.serviceError(this, 'Called end() without an open chart.'); return false; } @@ -189,7 +192,7 @@ var netdata = { // discard the collected values for the current chart - after calling begin() service.flush = function() { if(this._current_chart === null || this._current_chart._began === false) { - netdata.error('Called flush() without an open chart.'); + netdata.serviceError(this, 'Called flush() without an open chart.'); return false; } @@ -430,6 +433,32 @@ var netdata = { } }, + serviceError: function(service, message) { + if(service.error_reported === false) { + netdata.error(service.module.name + ': ' + service.name + ': ' + message); + service.error_reported = true; + } + else if(netdata.options.DEBUG === true) + netdata.debug(service.module.name + ': ' + service.name + ': ' + message); + }, + + serviceErrorClear: function(service) { + service.error_reported = false; + }, + + serviceInit: function(service) { + service.error_reported = false; + service.added = false; + service.enabled = true; + }, + + serviceIsInitialized: function(service) { + if(typeof service.error_reported === 'undefined') + return false; + + return true; + }, + getResponse: function(service, response, callback) { if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got response...'); @@ -439,7 +468,7 @@ var netdata = { if(response.statusCode !== 200) { if(end === false) { - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got HTTP code ' + response.statusCode + ', failed to get data.'); + netdata.serviceError(service, ': got HTTP code ' + response.statusCode + ', failed to get data.'); end = true; netdata.processResponse(service, null, callback); } @@ -451,7 +480,7 @@ var netdata = { response.on('error', function() { if(end === false) { - if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': Read error, failed to get data.'); + netdata.serviceError(service, ': Read error, failed to get data.'); end = true; netdata.processResponse(service, null, callback); } @@ -459,6 +488,7 @@ var netdata = { response.on('end', function() { if(end === false) { + netdata.serviceErrorClear(service); if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': read completed.'); end = true; netdata.processResponse(service, data, callback); @@ -467,6 +497,9 @@ var netdata = { }, serviceExecute: function(service, callback) { + if(netdata.serviceIsInitialized(service) === false) + netdata.serviceInit(service); + service.module.running++; if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': making request: ' + netdata.stringify(service.request)); @@ -476,13 +509,15 @@ var netdata = { }); req.on('error', function(e) { - netdata.error(service.module.name + ': ' + service.name + ': failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message); + netdata.serviceError(service, ': failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message); netdata.processResponse(service, null, callback); }); // write data to request body - if(typeof service.postData !== 'undefined' && service.request.method === 'POST') + if(typeof service.postData !== 'undefined' && service.request.method === 'POST') { + if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': posting data: ' + service.postData); req.write(service.postData); + } req.end(); },