]> arthur.barton.de Git - netdata.git/blob - web/index.html
mainchart options added
[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
68                 // initialize the div
69                 showChartIsLoading(mainchart.div, mainchart.chartOptions.width, mainchart.chartOptions.height);
70
71                 document.getElementById('maingraph_title').innerHTML = " " + mainchart.title + " ";
72
73                 // set the radio buttons
74                 if(mainchart.group_method == 'average') $('#groupaverage').trigger('click');
75                 else $('#groupmax').trigger('click');
76
77                 $('#group' + mainchart.group).trigger('click');
78
79                 $('#chartnormal').trigger('click');
80
81                 showMainGraph();
82         }
83
84         function setMainChart(i) {
85                 mainChart(mycharts[i]);
86         }
87
88         function setMainChartMax(m) {
89                 if(!mainchart) return;
90
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';
99                 }
100                 else {
101                         mainchart.chartOptions.theme = null;
102                 }
103                 mainchart.last_updated = 0;
104         }
105
106         function setMainChartGroup(g) {
107                 if(!mainchart) return;
108
109                 mainchart.group = g;
110                 mainchart.last_updated = 0;
111
112                 chartsRefresh();
113         }
114
115         function setMainChartGroupMethod(g) {
116                 if(!mainchart) return;
117
118                 mainchart.group_method = g;
119                 mainchart.last_updated = 0;
120
121                 chartsRefresh();
122         }
123
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();
129                         showThumbGraphs();
130                         return;
131                 }
132
133                 mainchart.points_to_show = Math.round(mainchart.entries / mainchart.group) - 1;
134
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;
137
138                 if(!refreshChart(mainchart, triggerRefresh)) triggerRefresh();
139         }
140
141         function screenWidth() {
142                 return (($(window).width() * 0.95) - 40);
143         }
144
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;
150
151                 if(items > 1 && (cwidth / items) < MINIMUM_THUMB_GRAPH_WIDTH) items--;
152
153                 return Math.round(cwidth / items) - 1;
154         }
155
156         // resize all charts
157         // if the thumb charts need resize in their width, reset them
158         function resizeCharts() {
159                 var width = screenWidth();
160
161                 if(mainchart) {
162                         mainchart.chartOptions.width = width;
163                         mainchart.chartOptions.height = $(window).height() - 200;
164                         mainchart.last_updated = 0;
165                 }
166
167                 width = thumbWidth();
168                 $.each(mycharts, function(i, c) {
169                         if(c.enabled && c.chartOptions.width != width) {
170                                 if(c.chart) c.chart.clearChart();
171                                 c.chart = null;
172                                 c.chartOptions.width = width;
173                                 showChartIsLoading(c.div, c.chartOptions.width, c.chartOptions.height);
174                                 c.last_updated = 0;
175                         }
176                 });
177         }
178
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;
184
185                 loadCharts(null, function(c) {
186                         mycharts = c;
187
188                         if(mycharts == null || mycharts.length == 0) {
189                                 alert("Cannot load data from server.");
190                                 return;
191                         }
192
193                         var thumbsContainer = document.getElementById("thumbgraphs");
194                         if(!thumbsContainer) {
195                                 alert("Cannot find the thumbsContainer");
196                                 return;
197                         }
198
199                         function chartssort(a, b) {
200                                 if(a.userpriority < b.userpriority) return -1;
201                                 return 1;
202                         }
203                         mycharts.sort(chartssort);
204
205                         document.getElementById('hostname_id').innerHTML = mycharts[0].hostname;
206                         document.title = mycharts[0].hostname;
207
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;
213
214                                 // calculate how many point to show for each chart
215                                 c.points_to_show = Math.round(c.entries / c.group) - 1;
216
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;
219
220                                 if(c.enabled) {
221                                         var j;
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 +");\">&nbsp;&nbsp;select " + c.name + " for zoom&nbsp;&nbsp;</button></div></td></tr></table></div>";
223
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++;
229                                                         break;
230                                                 }
231                                         }
232
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});
236                                         }
237                                 }
238                         });
239
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;
249
250                                 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>";
251                         });
252
253                         function categoriessort(a, b) {
254                                 if(a.priority < b.priority) return -1;
255                                 return 1;
256                         }
257                         categories.sort(categoriessort);
258
259                         // combine all the htmls into one
260                         var allcategories = "<table width=\"100%\">";
261                         $.each(categories, function(i, a) {
262                                 allcategories += a.html;
263                         });
264                         allcategories += "</table>";
265
266                         thumbsContainer.innerHTML = allcategories;
267                         showThumbGraphs();
268                 });
269         }
270
271         var last_thumb_updated = 0;
272         function thumbChartsRefresh() {
273                 if(mycharts.length == 0 || mode != MODE_THUMBS) return;
274
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;
279
280                 while(last_thumb_updated != orig) {
281                         if(refreshChart(mycharts[last_thumb_updated], chartsRefresh)) break;
282
283                         last_thumb_updated++;
284                         if(last_thumb_updated >= mycharts.length) last_thumb_updated = 0;
285                 }
286
287                 // no chart refreshed
288                 if(last_thumb_updated == orig) triggerRefresh();
289         }
290
291         // refresh the proper chart
292         var timeout;
293         function chartsRefresh() {
294                 if(timeout) {
295                         clearTimeout(timeout);
296                         timeout = null;
297                 }
298
299                      if(mode == MODE_THUMBS) thumbChartsRefresh();
300                 else if(mode == MODE_MAIN)   mainChartRefresh();
301                 else                         timeout = setTimeout(triggerRefresh, 1000);
302         }
303
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);
309         }
310
311         window.onresize = function(event) {
312                 resizeCharts();
313         };
314
315         var thumbsScrollPosition = null;
316         function showMainGraph() {
317                 if(!mainchart) return;
318
319                 thumbsScrollPosition = window.pageYOffset;
320
321                 mode = MODE_MAIN;
322
323                 document.getElementById('maingraph_container').style.display = 'block';
324                 document.getElementById('thumbgraphs_container').style.display = 'none';
325
326                 chartsRefresh();
327         }
328
329         function showThumbGraphs() {
330                 mode = MODE_THUMBS;
331
332                 document.getElementById('maingraph_container').style.display = 'none';
333                 document.getElementById('thumbgraphs_container').style.display = 'block';
334
335                 if(thumbsScrollPosition) window.scrollTo(0, thumbsScrollPosition);
336
337                 if(mainchart) {
338                         if(mainchart.chart) mainchart.chart.clearChart();
339                         mainchart = null;
340                 }
341
342                 chartsRefresh();
343         }
344
345         </script>
346 </head>
347
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>
357           </button>
358           <a class="navbar-brand" href="#" id="hostname_id">NetData</a>
359         </div>
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>
370           </ul>
371         </div><!--/.nav-collapse -->
372       </div>
373     </nav>
374
375     <div class="container graphs" id="maingraph_container" style="display: none">
376                 <table>
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."> &larr; Back </button></div><a id="maingraph_title" href="#maingraph"><b> Maingraph </b></a></li></ol></td></tr>
378                         <tr><td>
379                         <div class="maingraph">
380                                         <table>
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>
389                                                                         </div>
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>
400                                                                         </div>
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>
405                                                                         </div>
406                                                                 </form>
407                                                         </div>
408                                                         </td></tr>
409                                         </table>
410                            </div><!-- /.maingraph -->
411                         </td></tr>
412                 </table>
413         </div>
414
415     <div class="container graphs" id="thumbgraphs_container">
416         <div class="allgraphs" id="thumbgraphs">
417                 <table width="100%">
418                         <tr><td id="splash" align="center" style="vertical-align:middle">
419                                 <h1>
420                                 Welcome to <b>NetData</b>!
421                                 <br/><br/>
422                                 <span class="glyphicon glyphicon-off"></span>
423                                 <br/><br/>
424                                 loading charts
425                                 <br/><br/>
426                                 <span class="label label-default">Please wait...</span>
427                                 </h1>
428                         </td></tr>
429                 </table>
430         </div>
431         </div>
432
433         <script type='text/javascript'>
434                 
435
436                 $(document).ready(function(){
437                         document.getElementById('splash').height = $(window).height();
438
439                         $('[data-toggle="tooltip"]').tooltip({'placement': 'top', 'container': 'body'});
440                 });
441
442         </script>
443 </html>