]> arthur.barton.de Git - netdata.git/blobdiff - node.d/sma_webbox.node.js
Merge pull request #138 from clickthisnick/chore-remove-trailing-spaces
[netdata.git] / node.d / sma_webbox.node.js
index 556c39db6686af35f9bb71762f7efacee2868153..5ed1c55a7c8e1e37dc29362bc5a30d2d37c1310e 100755 (executable)
@@ -32,8 +32,8 @@ if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plug
 var webbox = {
        name: __filename,
        enable_autodetect: true,
-       update_every: 1000,
-
+       update_every: 1,
+       base_priority: 60000,
        charts: {},
 
        processResponse: function(service, data) {
@@ -70,7 +70,7 @@ var webbox = {
 
                        // add the service
                        if(found > 0 && service.added !== true)
-                               netdata.serviceAdd(service);
+                               service.commit();
 
                        // Grid Current Power Chart
                        if(d['GriPwr'].value !== null) {
@@ -83,11 +83,11 @@ var webbox = {
                                                name: '',                                                                               // the unique name of the chart
                                                title: service.name + ' Current Grid Power',    // the title of the chart
                                                units: d['GriPwr'].unit,                                                // the units of the chart dimensions
-                                               family: 'sma_webbox_' + service.name,                   // the family of the chart
-                                               category: 'sma_webbox_' + service.name,                 // the category of the chart
+                                               family: 'now',                                                                  // the family of the chart
+                                               context: 'sma_webbox.grid.power',                               // the context of the chart
                                                type: netdata.chartTypes.area,                                  // the type of the chart
-                                               priority: 1000,                                                                 // the priority relative to others in the same family and category
-                                               update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
+                                               priority: webbox.base_priority + 1,                             // the priority relative to others in the same family
+                                               update_every: service.update_every,                             // the expected update frequency of the chart
                                                dimensions: {
                                                        'GriPwr': {
                                                                id: 'GriPwr',                                                           // the unique id of the dimension
@@ -119,11 +119,11 @@ var webbox = {
                                                name: '',                                                                               // the unique name of the chart
                                                title: service.name + ' Today Grid Power',              // the title of the chart
                                                units: d['GriEgyTdy'].unit,                                             // the units of the chart dimensions
-                                               family: 'sma_webbox_' + service.name,                   // the family of the chart
-                                               category: 'sma_webbox_' + service.name,                 // the category of the chart
+                                               family: 'today',                                                                // the family of the chart
+                                               context: 'sma_webbox.grid.power.today',                 // the context of the chart
                                                type: netdata.chartTypes.area,                                  // the type of the chart
-                                               priority: 1000,                                                                 // the priority relative to others in the same family and category
-                                               update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
+                                               priority: webbox.base_priority + 2,                             // the priority relative to others in the same family
+                                               update_every: service.update_every,                             // the expected update frequency of the chart
                                                dimensions: {
                                                        'GriEgyTdy': {
                                                                id: 'GriEgyTdy',                                                                // the unique id of the dimension
@@ -155,11 +155,11 @@ var webbox = {
                                                name: '',                                                                               // the unique name of the chart
                                                title: service.name + ' Total Grid Power',              // the title of the chart
                                                units: d['GriEgyTot'].unit,                                             // the units of the chart dimensions
-                                               family: 'sma_webbox_' + service.name,                   // the family of the chart
-                                               category: 'sma_webbox_' + service.name,                 // the category of the chart
+                                               family: 'total',                                                                // the family of the chart
+                                               context: 'sma_webbox.grid.power.total',                 // the context of the chart
                                                type: netdata.chartTypes.area,                                  // the type of the chart
-                                               priority: 1000,                                                                 // the priority relative to others in the same family and category
-                                               update_every: Math.round(service.update_every / 1000), // the expected update frequency of the chart
+                                               priority: webbox.base_priority + 3,                             // the priority relative to others in the same family
+                                               update_every: service.update_every,                             // the expected update frequency of the chart
                                                dimensions: {
                                                        'GriEgyTot': {
                                                                id: 'GriEgyTot',                                                                // the unique id of the dimension
@@ -190,17 +190,17 @@ var webbox = {
        serviceExecute: function(name, hostname, update_every) {
                if(netdata.options.DEBUG === true) netdata.debug(this.name + ': ' + name + ': hostname: ' + hostname + ', update_every: ' + update_every);
 
-               var service = {
+               var service = netdata.service({
                        name: name,
                        request: netdata.requestFromURL('http://' + hostname + '/rpc'),
                        update_every: update_every,
                        module: this
-               };
+               });
                service.postData = 'RPC={"proc":"GetPlantOverview","format":"JSON","version":"1.0","id":"1"}';
                service.request.method = 'POST';
                service.request.headers['Content-Length'] = service.postData.length;
 
-               netdata.serviceExecute(service, this.processResponse);
+               service.execute(this.processResponse);
        },
 
        configure: function(config) {
@@ -211,11 +211,9 @@ var webbox = {
                        while(len--) {
                                if(typeof config.servers[len].update_every === 'undefined')
                                        config.servers[len].update_every = this.update_every;
-                               else
-                                       config.servers[len].update_every = config.servers[len].update_every * 1000;
 
-                               if(config.servers[len].update_every < 5000)
-                                       config.servers[len].update_every = 5000;
+                               if(config.servers[len].update_every < 5)
+                                       config.servers[len].update_every = 5;
 
                                this.serviceExecute(config.servers[len].name, config.servers[len].hostname, config.servers[len].update_every);
                                added++;
@@ -229,7 +227,7 @@ var webbox = {
        // this is called repeatidly to collect data, by calling
        // netdata.serviceExecute()
        update: function(service, callback) {
-               netdata.serviceExecute(service, function(serv, data) {
+               service.execute(function(serv, data) {
                        service.module.processResponse(serv, data);
                        callback();
                });