},\r
\r
serviceAdd: function(service) {\r
+ if(netdata.serviceIsInitialized(service) === false)\r
+ netdata.serviceInit(service);\r
+\r
if(service.added !== true) {\r
service.updates = 0;\r
service.enabled = true;\r
// begin data collection for a chart\r
service.begin = function(chart) {\r
if(this._current_chart !== null && this._current_chart !== chart) {\r
- netdata.error('Called begin() for chart ' + chart.id + ' while chart ' + this._current_chart.id + ' is still open. Closing it.');\r
+ netdata.serviceError(this, 'Called begin() for chart ' + chart.id + ' while chart ' + this._current_chart.id + ' is still open. Closing it.');\r
this.end();\r
}\r
\r
if(typeof(chart.id) === 'undefined' || netdata.charts[chart.id] != chart) {\r
- netdata.error('Called begin() for chart ' + chart.id + ' that is not mine. Where did you find it? Ignoring it.');\r
+ netdata.serviceError(this, 'Called begin() for chart ' + chart.id + ' that is not mine. Where did you find it? Ignoring it.');\r
return false;\r
}\r
\r
var now = this.ended;\r
this.queue('BEGIN ' + this._current_chart.id + ' ' + ((this._current_chart._last_updated > 0)?((now - this._current_chart._last_updated) * 1000):'').toString());\r
}\r
- // else netdata.error('Called begin() for chart ' + chart.id + ' which is empty.');\r
+ // else netdata.serviceError(this, 'Called begin() for chart ' + chart.id + ' which is empty.');\r
\r
this._current_chart._last_updated = now;\r
this._current_chart._began = true;\r
// we do most things on the first value we attempt to set\r
service.set = function(dimension, value) {\r
if(this._current_chart === null) {\r
- netdata.error('Called set(' + dimension + ', ' + value + ') without an open chart.');\r
+ netdata.serviceError(this, 'Called set(' + dimension + ', ' + value + ') without an open chart.');\r
return false;\r
}\r
\r
if(typeof(this._current_chart.dimensions[dimension]) === 'undefined') {\r
- netdata.error('Called set(' + dimension + ', ' + value + ') but dimension "' + dimension + '" does not exist in chart "' + this._current_chart.id + '".');\r
+ netdata.serviceError(this, 'Called set(' + dimension + ', ' + value + ') but dimension "' + dimension + '" does not exist in chart "' + this._current_chart.id + '".');\r
return false;\r
}\r
\r
// end data collection for the current chart - after calling begin()\r
service.end = function() {\r
if(this._current_chart !== null && this._current_chart._began === false) {\r
- netdata.error('Called end() without an open chart.');\r
+ netdata.serviceError(this, 'Called end() without an open chart.');\r
return false;\r
}\r
\r
// discard the collected values for the current chart - after calling begin()\r
service.flush = function() {\r
if(this._current_chart === null || this._current_chart._began === false) {\r
- netdata.error('Called flush() without an open chart.');\r
+ netdata.serviceError(this, 'Called flush() without an open chart.');\r
return false;\r
}\r
\r
}\r
},\r
\r
+ serviceError: function(service, message) {\r
+ if(service.error_reported === false) {\r
+ netdata.error(service.module.name + ': ' + service.name + ': ' + message);\r
+ service.error_reported = true;\r
+ }\r
+ else if(netdata.options.DEBUG === true)\r
+ netdata.debug(service.module.name + ': ' + service.name + ': ' + message);\r
+ },\r
+\r
+ serviceErrorClear: function(service) {\r
+ service.error_reported = false;\r
+ },\r
+\r
+ serviceInit: function(service) {\r
+ service.error_reported = false;\r
+ service.added = false;\r
+ service.enabled = true;\r
+ },\r
+\r
+ serviceIsInitialized: function(service) {\r
+ if(typeof service.error_reported === 'undefined')\r
+ return false;\r
+\r
+ return true;\r
+ },\r
+\r
getResponse: function(service, response, callback) {\r
if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got response...');\r
\r
\r
if(response.statusCode !== 200) {\r
if(end === false) {\r
- if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got HTTP code ' + response.statusCode + ', failed to get data.');\r
+ netdata.serviceError(service, ': got HTTP code ' + response.statusCode + ', failed to get data.');\r
end = true;\r
netdata.processResponse(service, null, callback);\r
}\r
\r
response.on('error', function() {\r
if(end === false) {\r
- if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': Read error, failed to get data.');\r
+ netdata.serviceError(service, ': Read error, failed to get data.');\r
end = true;\r
netdata.processResponse(service, null, callback);\r
}\r
\r
response.on('end', function() {\r
if(end === false) {\r
+ netdata.serviceErrorClear(service);\r
if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': read completed.');\r
end = true;\r
netdata.processResponse(service, data, callback);\r
},\r
\r
serviceExecute: function(service, callback) {\r
+ if(netdata.serviceIsInitialized(service) === false)\r
+ netdata.serviceInit(service);\r
+\r
service.module.running++;\r
\r
if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': making request: ' + netdata.stringify(service.request));\r
});\r
\r
req.on('error', function(e) {\r
- netdata.error(service.module.name + ': ' + service.name + ': failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);\r
+ netdata.serviceError(service, ': failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);\r
netdata.processResponse(service, null, callback);\r
});\r
\r
// write data to request body\r
- if(typeof service.postData !== 'undefined' && service.request.method === 'POST')\r
+ if(typeof service.postData !== 'undefined' && service.request.method === 'POST') {\r
+ if(netdata.options.DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': posting data: ' + service.postData);\r
req.write(service.postData);\r
+ }\r
\r
req.end();\r
},\r