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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
<!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>RRD Charts</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
body {
font-family: sans;
}
form div {
text-align: center;
}
h2 {
width: 750px;
padding: 0 0 0 50px;
margin: 10px auto 5px auto;
}
.loading {
background-repeat: no-repeat;
background-position: 0 50%;
background-image: url(/assets/icons/loading.gif);
}
.range-preview {
width: 800px;
height:50px;
margin: 0 auto 0 auto;
position: relative;
}
.chart {
width:800px;
height:200px;
margin: 0 auto 0 auto;
}
.chart canvas {
}
.tickLabel {
width:50px;
overflow:hidden;
}
.legendColorBox, .legendLabel {
cursor: pointer;
}
input[type=checkbox] {
margin: 0;
padding: 0;
border: none;
}
</style>
<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 baseOptions = {
grid: {
clickable: true,
borderWidth: 1,
borderColor: "#000",
color: "#000",
backgroundColor: "#fff",
tickColor: "#eee"
},
selection: {
mode: 'x'
},
series: {
points: { show: false },
lines: {
show: true,
steps: false,
shadowSize: 0,
lineWidth: 1
},
shadowSize: 0
},
xaxis: {
mode: "time"
}
};
var fillOptions = jQuery.extend(true, {
series: {
stack: true,
lines: {
fill: 0.5
}
}
}, baseOptions);
function cpuChartFactory(title, template) {
template.find('.title').text(title);
var c = new jrrd.Chart(template.find('.chart'), fillOptions);
data = 'cpu-user.rrd cpu-system.rrd cpu-wait.rrd'.split(' ').reverse();
jQuery.each(data, function(i, el) {
var label = el.split('.')[0].split('-')[1];
c.addData('cpu0-' + label, new jrrd.RrdQueryRemote('data/cpu-0/' + el));
c.addData('cpu1-' + label, new jrrd.RrdQueryRemote('data/cpu-1/' + el));
});
return c;
}
function memoryChartFactory(title, template) {
template.find('.title').text(title);
var c = new jrrd.Chart(template.find('.chart'), fillOptions);
data = 'memory-free.rrd memory-cached.rrd memory-used.rrd memory-buffered.rrd'.split(' ').reverse();
jQuery.each(data, function(i, el) {
var url = 'data/memory/' + el;
var label = el.split('.')[0].split('-')[1];
c.addData(label, new jrrd.RrdQueryRemote(url));
});
return c;
}
function dnsChartFactory(title, template) {
template.find('.title').text(title);
var c = new jrrd.Chart(template.find('.chart'), baseOptions);
data = 'dns_opcode-Query.rrd dns_qtype-A.rrd dns_qtype-PTR.rrd dns_rcode-NOERROR.rrd'.split(' ').reverse();
jQuery.each(data, function(i, el) {
var url = 'data/dns/' + el;
var label = el.split('.')[0].split('_')[1];
c.addData(label, new jrrd.RrdQueryRemote(url));
});
return c;
}
function loadChartFactory(title, template) {
template.find('.title').text(title);
var c = new jrrd.Chart(template.find('.chart'), baseOptions);
var data = new jrrd.RrdQueryRemote('data/load/load.rrd');
var rrdDSs = ['shortterm', 'midterm', 'longterm'];
jQuery.each(rrdDSs, function(i, rrdDS) {
c.addData(rrdDS, new jrrd.RrdQueryDsProxy(data, rrdDS));
});
return c;
}
function nicChartFactory(title, template, nicname) {
template.find('.title').text(title);
var c = new jrrd.Chart(template.find('.chart'), baseOptions);
var data = new jrrd.RrdQueryRemote('data/interface/if_octets-' + nicname + '.rrd');
var rrdDSs = ['tx', 'rx'];
jQuery.each(rrdDSs, function(i, rrdDS) {
c.addData(rrdDS, new jrrd.RrdQueryDsProxy(data, rrdDS));
});
return c;
}
$(function() {
var cc = new jrrd.ChartCoordinator($('.chartRangeControl'));
var chartTemplate = $('.chart-container').remove();
cc.charts = [
loadChartFactory('Load Average',
chartTemplate.clone().appendTo('.charts')),
nicChartFactory('Wlan0 Throughput',
chartTemplate.clone().appendTo('.charts'), 'wlan0'),
cpuChartFactory('CPU',
chartTemplate.clone().appendTo('.charts')),
memoryChartFactory('Memory',
chartTemplate.clone().appendTo('.charts'))
];
$('.charts').bind("plotselected", function(event, ranges) {
cc.setTimeRange(new Date(ranges.xaxis.from),
new Date(ranges.xaxis.to));
});
$('.chart-container').live('chart_loading', function(e) {
$(this).find('.title').addClass('loading');
});
$('.chart-container').live('chart_loaded', function(e) {
$(this).find('.title').removeClass('loading');
});
cc.reset();
});
</script>
</head>
<body>
<form method="GET" class="chartRangeControl">
<div>
<label>Start: <input type="text" name="startTime" /></label>
<label>End: <input type="text" name="endTime" /></label>
<input type="submit" value="Update" />
<input type="reset" value="Reset" />
</div>
<div class="range-preview"></div>
</form>
<div class="charts">
<div class="chart-container">
<h2 class="title"></h2>
<div class="chart"></div>
</div>
</div>
</body>
</html>
|