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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="assets/javascript/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="assets/javascript/flot/excanvas.min.js"></script>
<script type="text/javascript" src="assets/javascript/flot/jquery.flot.js"></script>
<script type="text/javascript" src="assets/javascript/flot/jquery.flot.stack.js"></script>
<script type="text/javascript" src="assets/javascript/flot/jquery.flot.selection.js"></script>
<script type="text/javascript" src="assets/javascript/javascriptrrd/binaryXHR.js"></script>
<script type="text/javascript" src="assets/javascript/javascriptrrd/rrdFile.js"></script>
<script type="text/javascript" src="assets/javascript/MochiKit/Base.js"></script>
<script type="text/javascript" src="assets/javascript/MochiKit/Async.js"></script>
<script type="text/javascript" src="jrrd.js"></script>
<script type="text/javascript">
var graphOptions = {
grid: {
clickable: true
},
selection: {
mode: 'x'
},
series: {
stack: true,
points: { show: false },
lines: {
show: true,
steps: false,
fill: 0.5,
shadowSize: 0,
lineWidth: 1
},
shadowSize: 0
},
xaxis: {
mode: "time"
}
};
var Chart = function(template) {
var self = this;
this.template = template;
this.data = [];
this.template.bind('plotclick', function(event, pos, item) {
if (item) {
console.log(['X: ' + new Date(item.datapoint[0]),
'Y: ' + item.datapoint[1]]);
}
});
this.template.bind("plotselected", function(event, ranges) {
var startTime = new Date(ranges.xaxis.from);
var endTime = new Date(ranges.xaxis.to);
self.draw(startTime, endTime);
console.log("You selected " + startTime + " to " + endTime);
});
};
Chart.prototype.addData = function(label, db) {
this.data.push([label, db]);
};
Chart.prototype.draw = function(startTime, endTime) {
var self = this;
var results = [];
for(var i=0; i<this.data.length; i++) {
results.push(this.data[i][1].getData(startTime, endTime));
}
return MochiKit.Async.gatherResults(results)
.addCallback(
function(data) {
for(var i=0; i<data.length; i++) {
data[i].label = self.data[i][0];
}
var plot = $.plot(self.template, data, graphOptions);
})
.addErrback(
function(failure) {
$('.container').text('error: ' + failure.message);
});
};
$(function() {
var c = new Chart($('.container'));
//data = 'memory-free.rrd memory-cached.rrd memory-used.rrd memory-buffered.rrd'.split(' ').reverse();
data = 'cpu-user.rrd cpu-system.rrd cpu-wait.rrd'.split(' ').reverse();
jQuery.each(data, function(i, el) {
var url = 'data/localhost/cpu-0/' + el;
var label = el.split('.')[0].split('-')[1];
c.addData(label, new jrrd.RrdQueryRemote(url));
});
c.draw(new Date('7 April 2010 09:30:00'),
new Date('7 April 2010 15:00:00'));
});
</script>
</head>
<body>
<div class="container" style="width:100%; height:200px;"></div>
</body>
</html>
|