4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
7 <meta name="viewport" content="width=device-width, initial-scale=1">
8 <meta name="apple-mobile-web-app-capable" content="yes">
9 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
10 <meta name="description" content="">
11 <meta name="author" content="costa@tsaousis.gr">
13 <title>NetData</title>
15 <!-- Google AJAX API -->
16 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
17 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
20 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
21 <!-- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"> -->
22 <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
23 <link href="/file/theme.css" rel="stylesheet">
26 <script type="text/javascript" src="/file/netdata.js"></script>
27 <script type="text/javascript" src="/file/jquery.visible.js"></script>
28 <script type="text/javascript">
30 // Set a callback to run when the Google Visualization API is loaded.
31 google.setOnLoadCallback(initCharts);
33 var TARGET_THUMB_GRAPH_WIDTH = 500; // chart width will range from 0.5 to 1.5 of that
34 var MINIMUM_THUMB_GRAPH_WIDTH = 400; // chart will generally try to be wider than that
35 var TARGET_THUMB_GRAPH_HEIGHT = 220;
36 var MAINCHART_MAX_TIME_TO_SHOW = 1200;
37 var THUMBS_MAX_TIME_TO_SHOW = 600;
41 var mode; // one of the MODE_* values
43 var mycharts = new Array();
46 function chartIsLoadingHTML(width, height) { return "<table><tr><td align=\"center\" width=\"" + width + "\" height=\"" + height + "\" style=\"vertical-align:middle\"><h4><span class=\"glyphicon glyphicon-refresh\"></span><br/><br/>loading chart<br/><br/><span class=\"label label-default\">Please wait...</span></h4></td></tr></table>"; }
48 function showChartIsLoading(id, width, height) { document.getElementById(id).innerHTML = chartIsLoadingHTML(width, height); }
50 // copy the chart c to mainchart
51 // switch to main graphs screen
52 function mainChart(c) {
53 if(mainchart && mainchart.chart) mainchart.chart.clearChart();
55 mainchart = $.extend(true, {}, c);
57 mainchart.chart = null;
58 mainchart.chartOptions.width = screenWidth();
59 mainchart.chartOptions.height = $(window).height() - 200;
60 if(mainchart.chartOptions.height < 300) mainchart.chartOptions.height = 300;
63 mainchart.div = 'maingraph';
64 mainchart.last_updated = 0;
66 if(mainchart.chartOptions.isStacked) mainchart.group = 15;
69 showChartIsLoading(mainchart.div, mainchart.chartOptions.width, mainchart.chartOptions.height);
71 document.getElementById('maingraph_title').innerHTML = " " + mainchart.title + " ";
73 // set the radio buttons
74 if(mainchart.group_method == 'average') $('#groupaverage').trigger('click');
75 else $('#groupmax').trigger('click');
77 $('#group' + mainchart.group).trigger('click');
79 $('#chartnormal').trigger('click');
84 function setMainChart(i) {
85 mainChart(mycharts[i]);
88 function setMainChartMax(m) {
89 if(!mainchart) return;
91 if(m == "maximized") {
92 mainchart.chartOptions.theme = 'maximized';
93 //mainchart.chartOptions.titlePosition = 'none';
94 //mainchart.chartOptions.axisTitlesPosition = 'in';
95 //mainchart.chartOptions.legend = {position: 'none'};
96 //mainchart.chartOptions.hAxis.title = null;
97 //mainchart.chartOptions.hAxis.viewWindowMode = 'maximized';
98 //mainchart.chartOptions.vAxis.viewWindowMode = 'maximized';
101 mainchart.chartOptions.theme = null;
103 mainchart.last_updated = 0;
106 function setMainChartGroup(g) {
107 if(!mainchart) return;
110 mainchart.last_updated = 0;
115 function setMainChartGroupMethod(g) {
116 if(!mainchart) return;
118 mainchart.group_method = g;
119 mainchart.last_updated = 0;
124 // refresh the main chart
125 // make sure it gets updated frequently
126 function mainChartRefresh() {
127 if(!mainchart || mode != MODE_MAIN) {
128 if(mainchart) mainchart.clearChart();
133 mainchart.points_to_show = Math.round(mainchart.entries / mainchart.group) - 1;
135 if(mainchart.points_to_show * mainchart.group > MAINCHART_MAX_TIME_TO_SHOW)
136 mainchart.points_to_show = MAINCHART_MAX_TIME_TO_SHOW / mainchart.group;
138 if(!refreshChart(mainchart, triggerRefresh)) triggerRefresh();
141 function screenWidth() {
142 return (($(window).width() * 0.95) - 40);
145 // calculate the proper width for the thumb charts
146 function thumbWidth() {
147 var cwidth = screenWidth();
148 var items = Math.round(cwidth / TARGET_THUMB_GRAPH_WIDTH);
149 if(items < 1) items = 1;
151 if(items > 1 && (cwidth / items) < MINIMUM_THUMB_GRAPH_WIDTH) items--;
153 return Math.round(cwidth / items) - 1;
157 // if the thumb charts need resize in their width, reset them
158 function resizeCharts() {
159 var width = screenWidth();
162 mainchart.chartOptions.width = width;
163 mainchart.chartOptions.height = $(window).height() - 200;
164 mainchart.last_updated = 0;
167 width = thumbWidth();
168 $.each(mycharts, function(i, c) {
169 if(c.enabled && c.chartOptions.width != width) {
170 if(c.chart) c.chart.clearChart();
172 c.chartOptions.width = width;
173 showChartIsLoading(c.div, c.chartOptions.width, c.chartOptions.height);
179 // load the charts from the server
180 // generate html for the thumbgraphs to support them
181 function initCharts() {
182 var width = thumbWidth();
183 var height = TARGET_THUMB_GRAPH_HEIGHT;
185 loadCharts(null, function(c) {
188 if(mycharts == null || mycharts.length == 0) {
189 alert("Cannot load data from server.");
193 var thumbsContainer = document.getElementById("thumbgraphs");
194 if(!thumbsContainer) {
195 alert("Cannot find the thumbsContainer");
199 function chartssort(a, b) {
200 if(a.userpriority < b.userpriority) return -1;
203 mycharts.sort(chartssort);
205 document.getElementById('hostname_id').innerHTML = mycharts[0].hostname;
206 document.title = mycharts[0].hostname;
208 // create an array for grouping all same-type graphs together
209 var categories = new Array();
210 $.each(mycharts, function(i, c) {
211 c.chartOptions.width = width;
212 c.chartOptions.height = height;
214 // calculate how many point to show for each chart
215 c.points_to_show = Math.round(c.entries / c.group) - 1;
217 // show max 10 mins of data
218 if(c.points_to_show * c.group > THUMBS_MAX_TIME_TO_SHOW) c.points_to_show = THUMBS_MAX_TIME_TO_SHOW / c.group;
222 var h = "<div class=\"thumbgraph\"><table><tr><td><div class=\"thumbgraph\" id=\"" + c.div + "\">" + chartIsLoadingHTML(c.chartOptions.width, c.chartOptions.height) + "</div></td></tr><tr><td align=\"center\"><div class=\"btn-group-xs\"><button type=\"button\" class=\"btn btn-default\" onclick=\"setMainChart(" + i +");\"> select " + c.name + " for zoom </button></div></td></tr></table></div>";
224 // find the categories object for this type
225 for(j = 0; j < categories.length ;j++) {
226 if(categories[j].name == c.type) {
227 categories[j].html += h;
228 categories[j].count++;
233 if(j == categories.length) {
234 var t = "(as " + c.group_method + " every " + (c.group * c.update_every) + " seconds)";
235 categories.push({name: c.type, title: c.category, description: t, priority: 0, count: 1, glyphicon: c.glyphicon, html: h});
240 $.each(categories, function(i, a) {
241 if(a.name == "net") a.priority = 1;
242 else if(a.name == "tc") a.priority = 2;
243 else if(a.name == "conntrack") a.priority = 3;
244 else if(a.name == "ipvs") a.priority = 4;
245 else if(a.name == "ipv4") a.priority = 5;
246 else if(a.name == "cpu") a.priority = 6;
247 else if(a.name == "disk") a.priority = 7;
248 else a.priority = 99;
250 a.html = "<tr><td id=\"" + a.name + "\"><ol class=\"breadcrumb graphs\"><li class=\"active\"><span class=\"glyphicon " + a.glyphicon + "\"></span> <a id=\"" + a.name + "\" href=\"#" + a.name + "\"><b>" + a.title + "</b> " + a.description + " </a></li></ol></td></tr><tr><td><div class=\"thumbgraphs\">" + a.html + "</td></tr>";
253 function categoriessort(a, b) {
254 if(a.priority < b.priority) return -1;
257 categories.sort(categoriessort);
259 // combine all the htmls into one
260 var allcategories = "<table width=\"100%\">";
261 $.each(categories, function(i, a) {
262 allcategories += a.html;
264 allcategories += "</table>";
266 thumbsContainer.innerHTML = allcategories;
271 var last_thumb_updated = 0;
272 function thumbChartsRefresh() {
273 if(mycharts.length == 0 || mode != MODE_THUMBS) return;
275 // find a chart to refresh
276 var orig = last_thumb_updated;
277 last_thumb_updated++;
278 if(last_thumb_updated >= mycharts.length) last_thumb_updated = 0;
280 while(last_thumb_updated != orig) {
281 if(refreshChart(mycharts[last_thumb_updated], chartsRefresh)) break;
283 last_thumb_updated++;
284 if(last_thumb_updated >= mycharts.length) last_thumb_updated = 0;
287 // no chart refreshed
288 if(last_thumb_updated == orig) triggerRefresh();
291 // refresh the proper chart
293 function chartsRefresh() {
295 clearTimeout(timeout);
299 if(mode == MODE_THUMBS) thumbChartsRefresh();
300 else if(mode == MODE_MAIN) mainChartRefresh();
301 else timeout = setTimeout(triggerRefresh, 1000);
304 // callback for refreshing the charts later
305 function triggerRefresh() {
306 if(mode == MODE_THUMBS) timeout = setTimeout(chartsRefresh, 200);
307 else if(mode == MODE_MAIN) timeout = setTimeout(chartsRefresh, 500);
308 else timeout = setTimeout(triggerRefresh, 1000);
311 window.onresize = function(event) {
315 var thumbsScrollPosition = null;
316 function showMainGraph() {
317 if(!mainchart) return;
319 thumbsScrollPosition = window.pageYOffset;
323 document.getElementById('maingraph_container').style.display = 'block';
324 document.getElementById('thumbgraphs_container').style.display = 'none';
329 function showThumbGraphs() {
332 document.getElementById('maingraph_container').style.display = 'none';
333 document.getElementById('thumbgraphs_container').style.display = 'block';
335 if(thumbsScrollPosition) window.scrollTo(0, thumbsScrollPosition);
338 if(mainchart.chart) mainchart.chart.clearChart();
348 <body role="document">
349 <nav id="mynav" class="navbar navbar-inverse navbar-fixed-top" role="navigation">
350 <div class="container">
351 <div class="navbar-header">
352 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
353 <span class="sr-only">Toggle navigation</span>
354 <span class="icon-bar"></span>
355 <span class="icon-bar"></span>
356 <span class="icon-bar"></span>
358 <a class="navbar-brand" href="#" id="hostname_id">NetData</a>
360 <div class="collapse navbar-collapse">
361 <ul class="nav navbar-nav">
362 <li class="active"><a href="#">Home</a></li>
363 <li><a href="#net">Network</a></li>
364 <li><a href="#tc">QoS</a></li>
365 <li><a href="#conntrack">Netfilter</a></li>
366 <li><a href="#ipv4">IPv4</a></li>
367 <li><a href="#ipvs">IPVS</a></li>
368 <li><a href="#cpu">CPU</a></li>
369 <li><a href="#disk">Disk</a></li>
371 </div><!--/.nav-collapse -->
375 <div class="container graphs" id="maingraph_container" style="display: none">
377 <tr><td><ol class="breadcrumb graphs"><li class="active"><div class="btn-group btn-group-sm"><button type="button" onclick="showThumbGraphs();" class="btn btn-default" data-toggle="tooltip" title="Close this chart and return to the index page."> ← Back </button></div><a id="maingraph_title" href="#maingraph"><b> Maingraph </b></a></li></ol></td></tr>
379 <div class="maingraph">
381 <tr><td><div class="maingraph" id="maingraph"></div></td></tr>
382 <tr><td align="center">
383 <div class="btn-group">
384 <form id="mainchartform">
385 <div class="btn-group" data-toggle="buttons">
386 <button type="button" class="btn btn-default disabled"> Group </button>
387 <label class="btn btn-primary" data-toggle="tooltip" title="show the MAX point among all points grouped"><input type="radio" name="groupmethod" id="groupmax" onChange="setMainChartGroupMethod('max');"><span class="glyphicon glyphicon-signal"></span></label>
388 <label class="btn btn-primary" data-toggle="tooltip" title="show the AVERAGE of all points grouped"><input type="radio" name="groupmethod" id="groupaverage" onChange="setMainChartGroupMethod('average');"><span class="glyphicon glyphicon-align-justify"></span></label>
390 <div class="btn-group" data-toggle="buttons" >
391 <label class="btn btn-primary" data-toggle="tooltip" title="do not group points, show the raw data"><input type="radio" name="group" id="group1" onChange="setMainChartGroup(1);">1</label>
392 <label class="btn btn-primary" data-toggle="tooltip" title="group in half, show 1 every 2 points of data"><input type="radio" name="group" id="group2" onChange="setMainChartGroup(2);">2</label>
393 <label class="btn btn-primary" data-toggle="tooltip" title="group every 5 points of data"><input type="radio" name="group" id="group5" onChange="setMainChartGroup(5);">5</label>
394 <label class="btn btn-primary" data-toggle="tooltip" title="group every 10 points of data"><input type="radio" name="group" id="group10" onChange="setMainChartGroup(10);">10</label>
395 <label class="btn btn-primary" data-toggle="tooltip" title="group every 15 points of data"><input type="radio" name="group" id="group15" onChange="setMainChartGroup(15);">15</label>
396 <label class="btn btn-primary" data-toggle="tooltip" title="group every 20 points of data"><input type="radio" name="group" id="group20" onChange="setMainChartGroup(20);">20</label>
397 <label class="btn btn-primary" data-toggle="tooltip" title="group every 30 points of data"><input type="radio" name="group" id="group30" onChange="setMainChartGroup(30);">30</label>
398 <label class="btn btn-primary" data-toggle="tooltip" title="group every 45 points of data"><input type="radio" name="group" id="group45" onChange="setMainChartGroup(45);">45</label>
399 <label class="btn btn-primary" data-toggle="tooltip" title="group every 60 points of data"><input type="radio" name="group" id="group60" onChange="setMainChartGroup(60);">60</label>
401 <div class="btn-group" data-toggle="buttons" >
402 <button type="button" class="btn btn-default disabled" > Chart </button>
403 <label class="btn btn-primary" data-toggle="tooltip" title="NORMAL chart size"><input type="radio" name="chartmax" id="chartnormal" onChange="setMainChartMax('normal');"><span class="glyphicon glyphicon-resize-small"></span></label>
404 <label class="btn btn-primary" data-toggle="tooltip" title="MAXIMIZED chart size"><input type="radio" name="chartmax" id="chartmax" onChange="setMainChartMax('maximized');"><span class="glyphicon glyphicon-fullscreen"></span></label>
410 </div><!-- /.maingraph -->
415 <div class="container graphs" id="thumbgraphs_container">
416 <div class="allgraphs" id="thumbgraphs">
418 <tr><td id="splash" align="center" style="vertical-align:middle">
420 Welcome to <b>NetData</b>!
422 <span class="glyphicon glyphicon-off"></span>
426 <span class="label label-default">Please wait...</span>
433 <script type='text/javascript'>
436 $(document).ready(function(){
437 document.getElementById('splash').height = $(window).height();
439 $('[data-toggle="tooltip"]').tooltip({'placement': 'top', 'container': 'body'});