]> arthur.barton.de Git - netdata.git/blob - web/index.html
html fine tunes
[netdata.git] / web / index.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5     <meta 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">
12  
13         <title>NetData</title>
14
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>
18
19         <!-- Bootstrap -->
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">
24
25         <!-- NetData -->
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">
29         
30         // Set a callback to run when the Google Visualization API is loaded.
31         google.setOnLoadCallback(initCharts);
32         
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;
38
39         var MODE_THUMBS = 1;
40         var MODE_MAIN = 2;
41         var mode; // one of the MODE_* values
42
43         var mycharts = new Array();
44         var mainchart;
45
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>"; }
47
48         function showChartIsLoading(id, width, height) { document.getElementById(id).innerHTML = chartIsLoadingHTML(width, height); }
49
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();
54
55                 mainchart = $.extend(true, {}, c);
56
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;
61                 
62                 mainchart.group = 5;
63                 mainchart.div = 'maingraph';
64                 mainchart.last_updated = 0;
65
66                 if(mainchart.chartOptions.isStacked) mainchart.group = 15;
67                 //mainchart.chartOptions.titlePosition = 'none';
68
69                 // initialize the div
70                 showChartIsLoading(mainchart.div, mainchart.chartOptions.width, mainchart.chartOptions.height);
71
72                 document.getElementById('maingraph_title').innerHTML = " " + mainchart.title + " ";
73
74                 // set the radio buttons
75                 if(mainchart.group_method == 'average') $('#groupaverage').trigger('click');
76                 else $('#groupmax').trigger('click');
77
78                 $('#group' + mainchart.group).trigger('click');
79
80                 $('#chartnormal').trigger('click');
81
82                 showMainGraph();
83         }
84
85         function setMainChart(i) {
86                 mainChart(mycharts[i]);
87         }
88
89         function setMainChartMax(m) {
90                 if(!mainchart) return;
91
92                 if(m == "maximized") {
93                         mainchart.chartOptions.theme = 'maximized';
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';
99                 }
100                 else {
101                         mainchart.chartOptions.theme = null;
102                         mainchart.chartOptions.hAxis.viewWindowMode = null;
103                         mainchart.chartOptions.vAxis.viewWindowMode = null;
104                 }
105                 mainchart.last_updated = 0;
106         }
107
108         function setMainChartGroup(g) {
109                 if(!mainchart) return;
110
111                 mainchart.group = g;
112                 mainchart.last_updated = 0;
113
114                 chartsRefresh();
115         }
116
117         function setMainChartGroupMethod(g) {
118                 if(!mainchart) return;
119
120                 mainchart.group_method = g;
121                 mainchart.last_updated = 0;
122
123                 chartsRefresh();
124         }
125
126         // refresh the main chart
127         // make sure it gets updated frequently
128         function mainChartRefresh() {
129                 if(!mainchart || mode != MODE_MAIN) {
130                         if(mainchart) mainchart.clearChart();
131                         showThumbGraphs();
132                         return;
133                 }
134
135                 mainchart.points_to_show = Math.round(mainchart.entries / mainchart.group) - 1;
136
137                 if(mainchart.points_to_show * mainchart.group > MAINCHART_MAX_TIME_TO_SHOW)
138                         mainchart.points_to_show = MAINCHART_MAX_TIME_TO_SHOW / mainchart.group;
139
140                 if(!refreshChart(mainchart, triggerRefresh)) triggerRefresh();
141         }
142
143         function screenWidth() {
144                 return (($(window).width() * 0.95) - 40);
145         }
146
147         // calculate the proper width for the thumb charts
148         function thumbWidth() {
149                 var cwidth = screenWidth();
150                 var items = Math.round(cwidth / TARGET_THUMB_GRAPH_WIDTH);
151                 if(items < 1) items = 1;
152
153                 if(items > 1 && (cwidth / items) < MINIMUM_THUMB_GRAPH_WIDTH) items--;
154
155                 return Math.round(cwidth / items) - 1;
156         }
157
158         // resize all charts
159         // if the thumb charts need resize in their width, reset them
160         function resizeCharts() {
161                 var width = screenWidth();
162
163                 if(mainchart) {
164                         mainchart.chartOptions.width = width;
165                         mainchart.chartOptions.height = $(window).height() - 200;
166                         mainchart.last_updated = 0;
167                 }
168
169                 width = thumbWidth();
170                 $.each(mycharts, function(i, c) {
171                         if(c.enabled && c.chartOptions.width != width) {
172                                 if(c.chart) c.chart.clearChart();
173                                 c.chart = null;
174                                 c.chartOptions.width = width;
175                                 showChartIsLoading(c.div, c.chartOptions.width, c.chartOptions.height);
176                                 c.last_updated = 0;
177                         }
178                 });
179         }
180
181         // load the charts from the server
182         // generate html for the thumbgraphs to support them
183         function initCharts() {
184                 var width = thumbWidth();
185                 var height = TARGET_THUMB_GRAPH_HEIGHT;
186
187                 loadCharts(null, function(c) {
188                         mycharts = c;
189
190                         if(mycharts == null || mycharts.length == 0) {
191                                 alert("Cannot load data from server.");
192                                 return;
193                         }
194
195                         var thumbsContainer = document.getElementById("thumbgraphs");
196                         if(!thumbsContainer) {
197                                 alert("Cannot find the thumbsContainer");
198                                 return;
199                         }
200
201                         function chartssort(a, b) {
202                                 if(a.userpriority < b.userpriority) return -1;
203                                 return 1;
204                         }
205                         mycharts.sort(chartssort);
206
207                         document.getElementById('hostname_id').innerHTML = mycharts[0].hostname;
208                         document.title = mycharts[0].hostname;
209
210                         // create an array for grouping all same-type graphs together
211                         var categories = new Array();
212                         $.each(mycharts, function(i, c) {
213                                 c.chartOptions.width = width;
214                                 c.chartOptions.height = height;
215
216                                 // calculate how many point to show for each chart
217                                 c.points_to_show = Math.round(c.entries / c.group) - 1;
218
219                                 // show max 10 mins of data
220                                 if(c.points_to_show * c.group > THUMBS_MAX_TIME_TO_SHOW) c.points_to_show = THUMBS_MAX_TIME_TO_SHOW / c.group;
221
222                                 if(c.enabled) {
223                                         var j;
224                                         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 +");\">&nbsp;&nbsp;select " + c.name + " for zoom&nbsp;&nbsp;</button></div></td></tr></table></div>";
225
226                                         // find the categories object for this type
227                                         for(j = 0; j < categories.length ;j++) {
228                                                 if(categories[j].name == c.type) {
229                                                         categories[j].html += h;
230                                                         categories[j].count++;
231                                                         break;
232                                                 }
233                                         }
234
235                                         if(j == categories.length) {
236                                                 var t = "(as " + c.group_method + " every " + (c.group * c.update_every) + " seconds)";
237                                                 categories.push({name: c.type, title: c.category, description: t, priority: 0, count: 1, glyphicon: c.glyphicon, html: h});
238                                         }
239                                 }
240                         });
241
242                         $.each(categories, function(i, a) {
243                                      if(a.name == "net") a.priority = 1;
244                                 else if(a.name == "tc") a.priority = 2;
245                                 else if(a.name == "conntrack") a.priority = 3;
246                                 else if(a.name == "ipvs") a.priority = 4;
247                                 else if(a.name == "ipv4") a.priority = 5;
248                                 else if(a.name == "cpu") a.priority = 6;
249                                 else if(a.name == "disk") a.priority = 7;
250                                 else a.priority = 99;
251
252                                 a.html = "<tr><td id=\"" + a.name + "\"><ol class=\"breadcrumb graphs\"><li class=\"active\"><span class=\"glyphicon " + a.glyphicon + "\"></span> &nbsp; <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                         });
254
255                         function categoriessort(a, b) {
256                                 if(a.priority < b.priority) return -1;
257                                 return 1;
258                         }
259                         categories.sort(categoriessort);
260
261                         // combine all the htmls into one
262                         var allcategories = "<table width=\"100%\">";
263                         $.each(categories, function(i, a) {
264                                 allcategories += a.html;
265                         });
266                         allcategories += "</table>";
267
268                         thumbsContainer.innerHTML = allcategories;
269                         showThumbGraphs();
270                 });
271         }
272
273         var last_thumb_updated = 0;
274         function thumbChartsRefresh() {
275                 if(mycharts.length == 0 || mode != MODE_THUMBS) return;
276
277                 // find a chart to refresh
278                 var orig = last_thumb_updated;
279                 last_thumb_updated++;
280                 if(last_thumb_updated >= mycharts.length) last_thumb_updated = 0;
281
282                 while(last_thumb_updated != orig) {
283                         if(refreshChart(mycharts[last_thumb_updated], chartsRefresh)) break;
284
285                         last_thumb_updated++;
286                         if(last_thumb_updated >= mycharts.length) last_thumb_updated = 0;
287                 }
288
289                 // no chart refreshed
290                 if(last_thumb_updated == orig) triggerRefresh();
291         }
292
293         // refresh the proper chart
294         var timeout;
295         function chartsRefresh() {
296                 if(timeout) {
297                         clearTimeout(timeout);
298                         timeout = null;
299                 }
300
301                      if(mode == MODE_THUMBS) thumbChartsRefresh();
302                 else if(mode == MODE_MAIN)   mainChartRefresh();
303                 else                         timeout = setTimeout(triggerRefresh, 1000);
304         }
305
306         // callback for refreshing the charts later
307         function triggerRefresh() {
308                      if(mode == MODE_THUMBS) timeout = setTimeout(chartsRefresh, 200);
309                 else if(mode == MODE_MAIN)   timeout = setTimeout(chartsRefresh, 500);
310                 else                         timeout = setTimeout(triggerRefresh, 1000);
311         }
312
313         window.onresize = function(event) {
314                 resizeCharts();
315         };
316
317         var thumbsScrollPosition = null;
318         function showMainGraph() {
319                 if(!mainchart) return;
320
321                 thumbsScrollPosition = window.pageYOffset;
322
323                 mode = MODE_MAIN;
324
325                 document.getElementById('maingraph_container').style.display = 'block';
326                 document.getElementById('thumbgraphs_container').style.display = 'none';
327
328                 chartsRefresh();
329         }
330
331         function showThumbGraphs() {
332                 mode = MODE_THUMBS;
333
334                 document.getElementById('maingraph_container').style.display = 'none';
335                 document.getElementById('thumbgraphs_container').style.display = 'block';
336
337                 if(thumbsScrollPosition) window.scrollTo(0, thumbsScrollPosition);
338
339                 if(mainchart) {
340                         if(mainchart.chart) mainchart.chart.clearChart();
341                         mainchart = null;
342                 }
343
344                 chartsRefresh();
345         }
346
347         </script>
348 </head>
349
350 <body role="document">
351     <nav id="mynav" class="navbar navbar-inverse navbar-fixed-top" role="navigation">
352       <div class="container">
353         <div class="navbar-header">
354           <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
355             <span class="sr-only">Toggle navigation</span>
356             <span class="icon-bar"></span>
357             <span class="icon-bar"></span>
358             <span class="icon-bar"></span>
359           </button>
360           <a class="navbar-brand" href="#" id="hostname_id">NetData</a>
361         </div>
362         <div class="collapse navbar-collapse">
363           <ul class="nav navbar-nav">
364             <li class="active"><a href="#">Home</a></li>
365             <li><a href="#net">Network</a></li>
366             <li><a href="#tc">QoS</a></li>
367             <li><a href="#conntrack">Netfilter</a></li>
368             <li><a href="#ipv4">IPv4</a></li>
369             <li><a href="#ipvs">IPVS</a></li>
370             <li><a href="#cpu">CPU</a></li>
371             <li><a href="#disk">Disk</a></li>
372           </ul>
373         </div><!--/.nav-collapse -->
374       </div>
375     </nav>
376
377     <div class="container graphs" id="maingraph_container" style="display: none">
378                 <table>
379                         <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"> &larr; Back </button></div><a id="maingraph_title" href="#maingraph"><b> Maingraph </b></a></li></ol></td></tr>
380                         <tr><td>
381                         <div class="maingraph">
382                                         <table>
383                                                 <tr><td><div class="maingraph" id="maingraph"></div></td></tr>
384                                                 <tr><td align="center">
385                                                         <div class="btn-group">
386                                                                 <form id="mainchartform">
387                                                                         <div class="btn-group" data-toggle="buttons">
388                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="show the MAX point among all points grouped">
389                                                                                         <input type="radio" name="groupmethod" id="groupmax" onChange="setMainChartGroupMethod('max');">
390                                                                                         <span class="glyphicon glyphicon-signal"></span>
391                                                                                 </label>
392                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="show the AVERAGE of all points grouped">
393                                                                                         <input type="radio" name="groupmethod" id="groupaverage" onChange="setMainChartGroupMethod('average');">
394                                                                                         <span class="glyphicon glyphicon-align-justify"></span>
395                                                                                 </label>
396                                                                         </div>
397                                                                         <div class="btn-group" data-toggle="buttons" >
398                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="do not group points, show the raw data">
399                                                                                         <input type="radio" name="group" id="group1" onChange="setMainChartGroup(1);">1
400                                                                                 </label>
401                                                                                 
402                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group in half, show 1 every 2 points of data">
403                                                                                         <input type="radio" name="group" id="group2" onChange="setMainChartGroup(2);">2
404                                                                                 </label>
405
406                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 5 points of data">
407                                                                                         <input type="radio" name="group" id="group5" onChange="setMainChartGroup(5);">5
408                                                                                 </label>
409                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 10 points of data">
410                                                                                         <input type="radio" name="group" id="group10" onChange="setMainChartGroup(10);">10
411                                                                                 </label>
412                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 15 points of data">
413                                                                                         <input type="radio" name="group" id="group15" onChange="setMainChartGroup(15);">15
414                                                                                 </label>
415                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 20 points of data">
416                                                                                         <input type="radio" name="group" id="group20" onChange="setMainChartGroup(20);">20
417                                                                                 </label>
418                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 30 points of data">
419                                                                                         <input type="radio" name="group" id="group30" onChange="setMainChartGroup(30);">30
420                                                                                 </label>
421                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 45 points of data">
422                                                                                         <input type="radio" name="group" id="group45" onChange="setMainChartGroup(45);">45
423                                                                                 </label>
424                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="group every 60 points of data">
425                                                                                         <input type="radio" name="group" id="group60" onChange="setMainChartGroup(60);">60
426                                                                                 </label>
427                                                                         </div>
428                                                                         <div class="btn-group" data-toggle="buttons" >
429                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="NORMAL chart size">
430                                                                                         <input type="radio" name="chartmax" id="chartnormal" onChange="setMainChartMax('normal');">
431                                                                                         <span class="glyphicon glyphicon-resize-small"></span>
432                                                                                 </label>
433                                                                                 <label class="btn btn-primary" data-toggle="tooltip" title="MAXIMIZED chart size">
434                                                                                         <input type="radio" name="chartmax" id="chartmax" onChange="setMainChartMax('maximized');">
435                                                                                         <span class="glyphicon glyphicon-fullscreen"></span>
436                                                                                 </label>
437                                                                         </div>
438                                                                 </form>
439                                                         </div>
440                                                         </td></tr>
441                                         </table>
442                            </div><!-- /.maingraph -->
443                         </td></tr>
444                 </table>
445         </div>
446
447     <div class="container graphs" id="thumbgraphs_container">
448         <div class="allgraphs" id="thumbgraphs">
449                 <table width="100%">
450                         <tr><td id="splash" align="center" style="vertical-align:middle">
451                                 <h1>
452                                 Welcome to <b>NetData</b>!
453                                 <br/><br/>
454                                 <span class="glyphicon glyphicon-off"></span>
455                                 <br/><br/>
456                                 loading charts
457                                 <br/><br/>
458                                 <span class="label label-default">Please wait...</span>
459                                 </h1>
460                         </td></tr>
461                 </table>
462         </div>
463         </div>
464
465         <script type='text/javascript'>
466                 
467
468                 $(document).ready(function(){
469                         document.getElementById('splash').height = $(window).height();
470
471                         $('[data-toggle="tooltip"]').tooltip({'placement': 'top', 'container': 'body'});
472                 });
473
474         </script>
475 </html>