]> arthur.barton.de Git - netdata.git/commitdiff
reporting node.js errors once instead of always
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 2 Feb 2016 00:30:30 +0000 (02:30 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 2 Feb 2016 00:30:30 +0000 (02:30 +0200)
node.d/named.node.js
node.d/node_modules/netdata.js
node.d/sma_webbox.node.js

index 82728f4882b54b2d71d1de11e76e7da2adda629d..8b30352c7d5a4924e88db15893ef7ce958539c26 100755 (executable)
@@ -418,8 +418,6 @@ var named = {
                        name: name,\r
                        request: netdata.requestFromURL(a_url),\r
                        update_every: update_every,\r
-                       added: false,\r
-                       enabled: true,\r
                        module: this\r
                }, this.processResponse);\r
        },\r
index 1e594ba0b7801520f140463e5d9de226b7a555d7..f371f55d47fa35e4c6d5396656fee7f90d647e18 100755 (executable)
@@ -87,6 +87,9 @@ var netdata = {
        },\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
@@ -119,12 +122,12 @@ var netdata = {
                        // 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
@@ -139,7 +142,7 @@ var netdata = {
                                        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
@@ -152,12 +155,12 @@ var netdata = {
                        // 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
@@ -170,7 +173,7 @@ var netdata = {
                        // 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
@@ -189,7 +192,7 @@ var netdata = {
                        // 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
@@ -430,6 +433,32 @@ var netdata = {
                }\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
@@ -439,7 +468,7 @@ var netdata = {
 \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
@@ -451,7 +480,7 @@ var netdata = {
 \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
@@ -459,6 +488,7 @@ var netdata = {
 \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
@@ -467,6 +497,9 @@ var netdata = {
        },\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
@@ -476,13 +509,15 @@ var netdata = {
                });\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
index 7cc6ced4ec735537890b381b49d4fb4f7900f783..556c39db6686af35f9bb71762f7efacee2868153 100755 (executable)
@@ -194,8 +194,6 @@ var webbox = {
                        name: name,
                        request: netdata.requestFromURL('http://' + hostname + '/rpc'),
                        update_every: update_every,
-                       added: false,
-                       enabled: true,
                        module: this
                };
                service.postData = 'RPC={"proc":"GetPlantOverview","format":"JSON","version":"1.0","id":"1"}';