-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRRDGraph.js
65 lines (57 loc) · 1.47 KB
/
RRDGraph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*jslint esversion:6*/
"use strict";
function RRDGraph() {
this.rrdFiles = [];
}
RRDGraph.prototype.addRrdFile = function(rrdFile) {
// FIXME: check already exists
this.rrdFiles.push(rrdFile);
};
RRDGraph.prototype.getFlotData = function() {
var r = [];
var rrd = this.rrdFiles[0];
for (var ds of rrd.ds) {
var data = [];
var x,y;
var rra;
// calculate start, end and resolution for each rra
var rraRange = [];
for (y = 0; y < rrd.rra.length; y++) {
rra = rrd.rra[y];
rraRange[y] = [
(rrd.lastUpdate - (rra.nrRows-1)* rra.step)*1000,
rrd.lastUpdate * 1000,
rra.step
];
}
// if there is a higher resolution rra change cutoff the lowres one
for (y = 0; y < rrd.rra.length; y++) {
for (x = 0; x < rrd.rra.length; x++) {
if ((rraRange[y][2] > rraRange[x][2]) &&
(rraRange[y][1] > rraRange[x][2])) {
rraRange[y][1] = rraRange[x][0];
}
}
}
// push the values into data
for (y = 0; y < rrd.rra.length; y++) {
rra = rrd.rra[y];
for (x = rra.nrRows-1; x > 0; x--) {
// FIXME: do this smarter and faster
var time = (rrd.lastUpdate - (rra.nrRows-1-x) * rra.step) * 1000;
if (time < rraRange[y][1]) {
data.push([time, rra.data[rrd.ds.indexOf(ds)][x]]);
}
}
}
r.push( { label: ds.name,
data: data,
lines: { show:true, fill: true }
});
}
return r;
};
// this will export the module to nodejs
if(typeof(exports) !== 'undefined' && exports !== null) {
exports.RRDGraph = RRDGraph;
}