var RRDManager function rrdFile this rrdFile rrdFile This function ret

 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var RRDManager = function(rrdFile) {
this.rrdFile = rrdFile;
};
/*
This function returns an object outputData of following format:
outputData = {
dsNames : [{
CFVariants : [[timestamp, value]]
}]
}
*/
RRDManager.prototype.getData = function(timeFrom, timeTo) {
if (timeFrom > timeTo || lastUpdate < timeFrom) return {};
var CFVariants = this.getCFVariants();
var rraArchives = this.getRRAs();
var lastUpdate = this.rrdFile.getLastUpdate();
var dsNames = this.rrdFile.getDSNames();
var outputData = {};
for (var i = 0, len = dsNames.length; i < len; i++) {
outputData[dsNames[i]] = {};
var dataByDsName = outputData[dsNames[i]];
for (var j = 0, CFCount = CFVariants.length; j < CFCount; j++) {
dataByDsName[CFVariants[j]] = {};
}
}
var fittedArchives = this.getFittedArchives(rraArchives, timeFrom);
for (var i = 0, CFNumber = CFVariants.length; i < CFNumber; i++) {
var currentArchive = fittedArchives[i];
for (var j = 0, dsNumber = dsNames.length; j < dsNumber; j++) {
outputData[dsNames[j]][CFVariants[i]] = [];
var startIndex = (currentArchive.row_cnt - 1) - (lastUpdate - timeFrom)/currentArchive.getStep();
var endIndex = (lastUpdate - timeTo > 0)
? currentArchive.row_cnt - (lastUpdate - timeTo)/currentArchive.getStep();
: currentArchive.row_cnt;
var startIndex = (lastUpdate - timeFrom > 0)
? (currentArchive.row_cnt*(1 - (lastUpdate - timeFrom)/this.calculateMaxTimeBack(currentArchive)))
: currentArchive.row_cnt;
var endIndex = (lastUpdate - timeTo > 0)
? (currentArchive.row_cnt*(lastUpdate - timeFrom)/this.calculateMaxTimeBack(currentArchive))
: currentArchive.row_cnt;
for (var k = startIndex; i < endIndex; i++) {
outputData[dsNames[j]][CFVariants[i]].push([lastUpdate - this.calculateTimeBack(currentArchive, k), currentArchive.getEl(k, j)]);
}
}
}
return outputData;
}
RRDManager.prototype.getFittedArchives = function(archives, timeFrom) {
var lastUpdate = this.rrdFile.getLastUpdate();
var CFVariantsNumber = this.getCFVariants().length;
var output = [];
for (var i = 0, len = archives.length; i < len; i += CFVariantsNumber) {
if (this.calculateMaxTimeBack(archives[i]) >= timeFrom) continue;
for (var j = 0; j < CFVariantsNumber; j++) {
output.push(archives[i + j]);
}
return output;
}
for (var j = 0; j < CFVariantsNumber; j++) {
output.push(archives[len - CFVariantsNumber + j]);
}
return output;
}
RRDManager.prototype.getCFVariants = function() {
var CFVariants = [];
for (var i = 0, cnt = this.rrdFile.getNrRRAs(); i < cnt; i++) {
var CFName = this.rrdFile.getRRA(i).rra_info.getCFName();
if (CFVariants.indexOf(CFName) === -1) CFVariants.push(CFName);
}
return CFVariants;
}
RRDManager.prototype.getRRAs = function() {
var RRAs = [];
for (var i = 0, cnt = this.rrdFile.getNrRRAs(); i < cnt; i++) {
RRAs.push(this.rrdFile.getRRA(i));
}
return RRAs;
}
RRDManager.prototype.calculateMaxTimeBack = function(RRA) {
return RRA.getStep()*RRA.row_cnt;
}
RRDManager.prototype.calculateTimeBack = function(RRA, row_index) {
return RRA.getStep()*row_index;
}