Added autonomy chart.
BrainDoctor committed
Jul 5, 2017 at 04:58 UTC
da459f238b574dd026cb8f2bde930614ac4fad2d
1 file changed
+41
-7
node.d/fronius.node.js
+41
-7
@@ -36,11 +36,13 @@ const power_grid_id = 'p_grid';
36
const power_pv_id = 'p_pv';
37
const power_accu_id = 'p_akku'; // not my typo! Using the ID from the API
38
const consumption_load_id = 'p_load';
39
+const autonomy_id = 'rel_autonomy';
40
+const consumption_self_id = 'rel_selfconsumption';
41
42
var fronius = {
41
- name: __filename,
43
+ name: "Fronius",
44
enable_autodetect: false,
43
- update_every: 3,
45
+ update_every: 5,
46
base_priority: 60000,
47
charts: {},
48
@@ -73,7 +75,7 @@ var fronius = {
75
units: 'W', // the units of the chart dimensions
76
family: 'Power', // the family of the chart
77
context: 'fronius.power', // the context of the chart
76
- type: netdata.chartTypes.line, // the type of the chart
78
+ type: netdata.chartTypes.area, // the type of the chart
79
priority: fronius.base_priority + 1, // the priority relative to others in the same family
80
update_every: service.update_every, // the expected update frequency of the chart
81
dimensions: dim
@@ -110,6 +112,33 @@ var fronius = {
112
return chart;
113
},
114
115
+
116
+ // Gets the site consumption chart. Will be created if not existing.
117
+ getSiteAutonomyChart: function (service, id) {
118
+ var chart = fronius.charts[id];
119
+ if (fronius.isDefined(chart)) return chart;
120
+ var dim = {};
121
+ dim[autonomy_id] = this.createBasicDimension(autonomy_id, "Autonomy");
122
+ dim[consumption_self_id] = this.createBasicDimension(consumption_self_id, "Self Consumption");
123
+
124
+ chart = {
125
+ id: id, // the unique id of the chart
126
+ name: '', // the unique name of the chart
127
+ title: service.name + ' Current Autonomy', // the title of the chart
128
+ units: '%', // the units of the chart dimensions
129
+ family: 'Autonomy', // the family of the chart
130
+ context: 'fronius.autonomy', // the context of the chart
131
+ type: netdata.chartTypes.area, // the type of the chart
132
+ priority: fronius.base_priority + 3, // the priority relative to others in the same family
133
+ update_every: service.update_every, // the expected update frequency of the chart
134
+ dimensions: dim
135
+ };
136
+ chart = service.chart(id, chart);
137
+ fronius.charts[id] = chart;
138
+
139
+ return chart;
140
+ },
141
+
142
// Gets the inverter power chart. Will be created if not existing.
143
// Needs the array of inverters in order to create a chart with all inverters as dimensions
144
getInverterPowerChart: function (service, chartId, inverters) {
@@ -139,7 +168,7 @@ var fronius = {
168
family: 'Inverters', // the family of the chart
169
context: 'fronius.inverter', // the context of the chart
170
type: netdata.chartTypes.stacked, // the type of the chart
142
- priority: fronius.base_priority + 3, // the priority relative to others in the same family
171
+ priority: fronius.base_priority + 4, // the priority relative to others in the same family
172
update_every: service.update_every, // the expected update frequency of the chart
173
dimensions: dim
174
};
@@ -185,7 +214,7 @@ var fronius = {
214
family: 'Inverters', // the family of the chart
215
context: 'fronius.inverter', // the context of the chart
216
type: netdata.chartTypes.stacked, // the type of the chart
188
- priority: fronius.base_priority + 4, // the priority relative to others in the same family
217
+ priority: fronius.base_priority + 5, // the priority relative to others in the same family
218
update_every: service.update_every, // the expected update frequency of the chart
219
dimensions: dim
220
};
@@ -206,8 +235,7 @@ var fronius = {
235
if (fronius.isUndefined(json.Body.Data.Inverters)) return;
236
237
// add the service
209
- if (service.added !== true)
210
- service.commit();
238
+ if (service.added !== true) service.commit();
239
240
var site = json.Body.Data.Site;
241
@@ -227,6 +255,12 @@ var fronius = {
255
service.set(consumption_load_id, Math.round(consumption));
256
service.end();
257
258
+ // Site Autonomy Chart
259
+ service.begin(fronius.getSiteAutonomyChart(service, 'fronius_' + service.name + '.autonomy'));
260
+ service.set(autonomy_id, Math.round(site.rel_Autonomy));
261
+ service.set(consumption_self_id, Math.round(site.rel_SelfConsumption));
262
+ service.end();
263
+
264
// Inverters
265
var inverters = json.Body.Data.Inverters;
266
var inverter_count = Object.keys(inverters).length;