load.htm 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <%#
  2. Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  3. Licensed to the public under the Apache License 2.0.
  4. -%>
  5. <%+header%>
  6. <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
  7. <script type="text/javascript">//<![CDATA[
  8. var bwxhr = new XHR();
  9. var G;
  10. var TIME = 0;
  11. var L01 = 1;
  12. var L05 = 2;
  13. var L15 = 3;
  14. var width = 760;
  15. var height = 300;
  16. var step = 5;
  17. var data_wanted = Math.floor(width / step);
  18. var data_fill = 0;
  19. var data_stamp = 0;
  20. var data_01 = [ ];
  21. var data_05 = [ ];
  22. var data_15 = [ ];
  23. var line_01;
  24. var line_05;
  25. var line_15;
  26. var label_25;
  27. var label_050;
  28. var label_75;
  29. var label_01_cur;
  30. var label_01_avg;
  31. var label_01_peak;
  32. var label_05_cur;
  33. var label_05_avg;
  34. var label_05_peak;
  35. var label_15_cur;
  36. var label_15_avg;
  37. var label_15_peak;
  38. var label_scale;
  39. /* wait for SVG */
  40. window.setTimeout(
  41. function() {
  42. var svg = document.getElementById('bwsvg');
  43. try {
  44. G = svg.getSVGDocument
  45. ? svg.getSVGDocument() : svg.contentDocument;
  46. }
  47. catch(e) {
  48. G = document.embeds['bwsvg'].getSVGDocument();
  49. }
  50. if (!G)
  51. {
  52. window.setTimeout(arguments.callee, 1000);
  53. }
  54. else
  55. {
  56. /* find sizes */
  57. width = svg.offsetWidth - 2;
  58. height = svg.offsetHeight - 2;
  59. data_wanted = Math.ceil(width / step);
  60. /* prefill datasets */
  61. for (var i = 0; i < data_wanted; i++)
  62. {
  63. data_01[i] = 0;
  64. data_05[i] = 0;
  65. data_15[i] = 0;
  66. }
  67. /* find svg elements */
  68. line_01 = G.getElementById('load01');
  69. line_05 = G.getElementById('load05');
  70. line_15 = G.getElementById('load15');
  71. label_25 = G.getElementById('label_25');
  72. label_50 = G.getElementById('label_50');
  73. label_75 = G.getElementById('label_75');
  74. label_01_cur = document.getElementById('lb_load01_cur');
  75. label_01_avg = document.getElementById('lb_load01_avg');
  76. label_01_peak = document.getElementById('lb_load01_peak');
  77. label_05_cur = document.getElementById('lb_load05_cur');
  78. label_05_avg = document.getElementById('lb_load05_avg');
  79. label_05_peak = document.getElementById('lb_load05_peak');
  80. label_15_cur = document.getElementById('lb_load15_cur');
  81. label_15_avg = document.getElementById('lb_load15_avg');
  82. label_15_peak = document.getElementById('lb_load15_peak');
  83. label_scale = document.getElementById('scale');
  84. /* plot horizontal time interval lines */
  85. for (var i = width % (step * 60); i < width; i += step * 60)
  86. {
  87. var line = G.createElementNS('http://www.w3.org/2000/svg', 'line');
  88. line.setAttribute('x1', i);
  89. line.setAttribute('y1', 0);
  90. line.setAttribute('x2', i);
  91. line.setAttribute('y2', '100%');
  92. line.setAttribute('style', 'stroke:black;stroke-width:0.1');
  93. var text = G.createElementNS('http://www.w3.org/2000/svg', 'text');
  94. text.setAttribute('x', i + 5);
  95. text.setAttribute('y', 15);
  96. text.setAttribute('style', 'fill:#999999; font-size:9pt');
  97. text.appendChild(G.createTextNode(Math.round((width - i) / step / 60) + 'm'));
  98. label_25.parentNode.appendChild(line);
  99. label_25.parentNode.appendChild(text);
  100. }
  101. label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3);
  102. /* render datasets, start update interval */
  103. XHR.poll(3, '<%=build_url("admin/status/realtime/load_status")%>', null,
  104. function(x, data)
  105. {
  106. var data_max = 0;
  107. var data_scale = 0;
  108. var data_01_avg = 0;
  109. var data_05_avg = 0;
  110. var data_15_avg = 0;
  111. var data_01_peak = 0;
  112. var data_05_peak = 0;
  113. var data_15_peak = 0;
  114. for (var i = data_stamp ? 0 : 1; i < data.length; i++)
  115. {
  116. /* skip overlapping entries */
  117. if (data[i][TIME] <= data_stamp)
  118. continue;
  119. data_01.push(data[i][L01]);
  120. data_05.push(data[i][L05]);
  121. data_15.push(data[i][L15]);
  122. }
  123. /* cut off outdated entries */
  124. data_01 = data_01.slice(data_01.length - data_wanted, data_01.length);
  125. data_05 = data_05.slice(data_05.length - data_wanted, data_05.length);
  126. data_15 = data_15.slice(data_15.length - data_wanted, data_15.length);
  127. /* find peak */
  128. for (var i = 0; i < data_01.length; i++)
  129. {
  130. data_max = Math.max(data_max, data_01[i]);
  131. data_max = Math.max(data_max, data_05[i]);
  132. data_max = Math.max(data_max, data_15[i]);
  133. data_01_peak = Math.max(data_01_peak, data_01[i]);
  134. data_05_peak = Math.max(data_05_peak, data_05[i]);
  135. data_15_peak = Math.max(data_15_peak, data_15[i]);
  136. if (i > 0)
  137. {
  138. data_01_avg = (data_01_avg + data_01[i]) / 2;
  139. data_05_avg = (data_05_avg + data_05[i]) / 2;
  140. data_15_avg = (data_15_avg + data_15[i]) / 2;
  141. }
  142. else
  143. {
  144. data_01_avg = data_01[i];
  145. data_05_avg = data_05[i];
  146. data_15_avg = data_15[i];
  147. }
  148. }
  149. /* remember current timestamp, calculate horizontal scale */
  150. data_stamp = data[data.length-1][TIME];
  151. data_scale = height / (data_max * 1.1);
  152. /* plot data */
  153. var pt_01 = '0,' + height;
  154. var pt_05 = '0,' + height;
  155. var pt_15 = '0,' + height;
  156. var y_01 = 0;
  157. var y_05 = 0;
  158. var y_15 = 0;
  159. for (var i = 0; i < data_01.length; i++)
  160. {
  161. var x = i * step;
  162. y_01 = height - Math.floor(data_01[i] * data_scale);
  163. y_05 = height - Math.floor(data_05[i] * data_scale);
  164. y_15 = height - Math.floor(data_15[i] * data_scale);
  165. pt_01 += ' ' + x + ',' + y_01;
  166. pt_05 += ' ' + x + ',' + y_05;
  167. pt_15 += ' ' + x + ',' + y_15;
  168. }
  169. pt_01 += ' ' + width + ',' + y_01 + ' ' + width + ',' + height;
  170. pt_05 += ' ' + width + ',' + y_05 + ' ' + width + ',' + height;
  171. pt_15 += ' ' + width + ',' + y_15 + ' ' + width + ',' + height;
  172. line_01.setAttribute('points', pt_01);
  173. line_05.setAttribute('points', pt_05);
  174. line_15.setAttribute('points', pt_15);
  175. label_25.firstChild.data = (1.1 * 0.25 * data_max / 100).toFixed(2);
  176. label_50.firstChild.data = (1.1 * 0.50 * data_max / 100).toFixed(2);
  177. label_75.firstChild.data = (1.1 * 0.75 * data_max / 100).toFixed(2);
  178. label_01_cur.innerHTML = (data_01[data_01.length-1] / 100).toFixed(2);
  179. label_05_cur.innerHTML = (data_05[data_05.length-1] / 100).toFixed(2);
  180. label_15_cur.innerHTML = (data_15[data_15.length-1] / 100).toFixed(2);
  181. label_01_avg.innerHTML = (data_01_avg / 100).toFixed(2);
  182. label_05_avg.innerHTML = (data_05_avg / 100).toFixed(2);
  183. label_15_avg.innerHTML = (data_15_avg / 100).toFixed(2);
  184. label_01_peak.innerHTML = (data_01_peak / 100).toFixed(2);
  185. label_05_peak.innerHTML = (data_05_peak / 100).toFixed(2);
  186. label_15_peak.innerHTML = (data_15_peak / 100).toFixed(2);
  187. }
  188. );
  189. }
  190. }, 1000
  191. );
  192. //]]></script>
  193. <h2 name="content"><%:Realtime Load%></h2>
  194. <embed id="bwsvg" style="width:100%; height:300px; border:1px solid #000000; background-color:#FFFFFF" src="<%=resource%>/load.svg" />
  195. <div style="text-align:right"><small id="scale">-</small></div>
  196. <br />
  197. <table style="width:100%; table-layout:fixed" cellspacing="5">
  198. <tr>
  199. <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid #ff0000; white-space:nowrap"><%:1 Minute Load:%></strong></td>
  200. <td id="lb_load01_cur">0</td>
  201. <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td>
  202. <td id="lb_load01_avg">0</td>
  203. <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td>
  204. <td id="lb_load01_peak">0</td>
  205. </tr>
  206. <tr>
  207. <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid #ff6600; white-space:nowrap"><%:5 Minute Load:%></strong></td>
  208. <td id="lb_load05_cur">0</td>
  209. <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td>
  210. <td id="lb_load05_avg">0</td>
  211. <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td>
  212. <td id="lb_load05_peak">0</td>
  213. </tr>
  214. <tr>
  215. <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid #ffaa00; white-space:nowrap"><%:15 Minute Load:%></strong></td>
  216. <td id="lb_load15_cur">0</td>
  217. <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td>
  218. <td id="lb_load15_avg">0</td>
  219. <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td>
  220. <td id="lb_load15_peak">0</td>
  221. </tr>
  222. </table>
  223. <%+footer%>