admin-compact-performance-monitor.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <html>
  2. <head>
  3. <title>Performance Monitoring</title>
  4. <link type="text/css" rel="stylesheet" href="../css/basicadmin.css" />
  5. <link rel="shortcut icon" href="../images/monitor-graph.png" />
  6. <style>
  7. body, td {
  8. font-family: calibri, tahoma, verdana, arial, helvetica;
  9. font-size: 10px;
  10. margin: 0px 0px 0px 0px;
  11. }
  12. #countdown {
  13. position: fixed;
  14. right: 0px;
  15. height: 100%;
  16. width: 5px;
  17. background-color: rgb(100,100,110);
  18. background: -moz-linear-gradient(top, rgb(90,90,100), rgb(200,200,210));
  19. -moz-box-shadow: 0px 0px 10px rgba(100,100,110,0.75);
  20. }
  21. #countdown.error {
  22. background-color: rgb(190,10,10);
  23. background: -moz-linear-gradient(top, rgb(160,0,0), rgb(230,20,20));
  24. -moz-box-shadow: 0px 0px 10px rgba(190,10,10,0.75);
  25. }
  26. #lastupdate {
  27. margin: 4px 4px 4px 30px;
  28. }
  29. #health {
  30. height: 175px;
  31. margin: 4px 4px 4px 0px;
  32. }
  33. #datatable {
  34. margin: 4px 4px 4px 30px;
  35. }
  36. #uptime {
  37. padding: 4px 4px 4px 30px;
  38. }
  39. #controls {
  40. margin: 10px 4px 10px 30px;
  41. }
  42. #controls .enabled {
  43. border: 2px solid rgb(100,100,110);
  44. padding: 2px 4px 2px 4px;
  45. margin-right: 6px;
  46. -moz-box-shadow: 0px 0px 10px rgba(100,100,110,0.5);
  47. }
  48. #controls a {
  49. border: 1px solid rgb(180,180,240);
  50. padding: 3px 5px 3px 5px;
  51. -moz-box-shadow: 0px 0px 10px rgba(100,100,190,0.25);
  52. text-decoration: none;
  53. margin-right: 6px;
  54. color: rgb(40,40,130);
  55. }
  56. #controls a:hover {
  57. border: 2px solid rgb(180,240,180);
  58. padding: 2px 4px 2px 4px;
  59. -moz-box-shadow: 0px 0px 10px rgba(100,190,100,0.5);
  60. background-color: rgb(200,255,200);
  61. color: black;
  62. }
  63. </style>
  64. <script type="text/javascript" src="../js/basicadmin.js"></script>
  65. <script type="text/javascript" src="../js/jquery.js"></script>
  66. <script type="text/javascript" src="../js/jquery.flot.js"></script>
  67. </head>
  68. <body>
  69. <div id='countdown'>&nbsp;</div>
  70. <div id="uptime">[Uptime]</div>
  71. <div id="health">[Health]</div>
  72. <table id='datatable' border="0" cellpadding="0" cellspacing="0">
  73. <tbody id='header'>
  74. </tbody>
  75. <tbody id='cmds'>
  76. </tbody>
  77. </table>
  78. <div id="controls"></div>
  79. <div id="lastupdate">[Last update]</div>
  80. <div id="message"></div>
  81. </body>
  82. <script>
  83. var mode = 0,
  84. svUrl = '../',
  85. detail = '',
  86. exc = 5,
  87. commands,
  88. content = "",
  89. concurrencyHighlight = 10,
  90. titles = ["Performance Monitoring", "Error - Cannot fetch performance data"],
  91. refreshInterval = 5,
  92. nextRefresh = refreshInterval,
  93. seconds = nextRefresh,
  94. maximumRefresh = 60,
  95. lastUpdate = 0;
  96. if (!Date.now) {
  97. Date.now = function now() {
  98. return +new Date();
  99. };
  100. }
  101. function renderHeader() {
  102. var content = '';
  103. // Performance monitoring mode.
  104. if (mode == 0) {
  105. content =
  106. '<tr class="admheader">'
  107. + '<td rowspan="2" valign="bottom">Command</td>'
  108. + '<td rowspan="2" valign="bottom"><abbr title="Current load">CL</abbr></td>'
  109. + '<td rowspan="2" valign="bottom"><abbr title="Count since application start">Count</abbr></td>'
  110. + '<td rowspan="2" valign="bottom"><abbr title="Count in last hour">LH</abbr></td>'
  111. + '<td class="separator">&nbsp;</td>'
  112. + '<td colspan="6" align="center">Average in last hour</td>'
  113. + '<td class="separator">&nbsp;</td>'
  114. + '<td colspan="5" align="center">Worst in last hour</td>'
  115. + '</tr>'
  116. + '<tr class="admheader">'
  117. + '<td class="separator">&nbsp;</td>'
  118. + '<td align="right"><abbr title="Queries">Qs</abbr></td>'
  119. + '<td align="right"><abbr title="Query Time">QT</abbr></td>'
  120. + '<td align="right"><abbr title="Logic Time">LT</abbr></td>'
  121. + '<td align="right"><abbr title="Render Time">RT</abbr></td>'
  122. + '<td align="right"><abbr title="CPU Time">CT</abbr></td>'
  123. + '<td align="right">Total</td>'
  124. + '<td class="separator">&nbsp;</td>'
  125. + '<td align="right"><abbr title="Queries">Qs</abbr></td>'
  126. + '<td align="right"><abbr title="Query Time">QT</abbr></td>'
  127. + '<td align="right"><abbr title="Logic Time">LT</abbr></td>'
  128. + '<td align="right"><abbr title="Render Time">RT</abbr></td>'
  129. + '<td align="right"><abbr title="CPU Time">CT</abbr></td>'
  130. + '<td class="separator">&nbsp;</td>'
  131. + '</tr>';
  132. }
  133. // Current requests mode.
  134. else if (mode == 1) {
  135. content =
  136. '<tr class="admheader">'
  137. + '<td>Command</td>'
  138. + '<td><abbr title="Request Number">Req</abbr></td>'
  139. + '<td><abbr title="Thread ID">TID</abbr></td>'
  140. + '<td><abbr title="Request start time">Time</abbr></td>'
  141. + '<td class="separator">&nbsp;</td>'
  142. + '<td align="right"><abbr title="Dispatches">Ds</abbr></td>'
  143. + '<td align="right"><abbr title="Queries">Qs</abbr></td>'
  144. + '<td align="right"><abbr title="Query Exceptions">QEs</abbr></td>'
  145. + '<td align="right"><abbr title="Query Time">QT</abbr></td>'
  146. + '<td align="right"><abbr title="Logic Time">LT</abbr></td>'
  147. + '<td align="right"><abbr title="Render Time">RT</abbr></td>'
  148. + '<td align="right"><abbr title="CPU Time">CT</abbr></td>'
  149. + '<td align="right"><abbr title="Total time">Total</abbr></td>'
  150. + '</tr>';
  151. }
  152. $("tbody#header").html(content);
  153. }
  154. function render(commands, uptime) {
  155. if (mode == 0) {
  156. $("tbody#cmds").html(gba.renderPerformanceMonitorList(commands, detail, exc, 2, concurrencyHighlight));
  157. }
  158. else if (mode == 1) {
  159. $("tbody#cmds").html(gba.renderCurrentRequestList(commands, detail, 2));
  160. }
  161. lastUpdate = Date.now();
  162. if (uptime != null) {
  163. $("div#uptime").html("Application last reported " + uptime + ".");
  164. }
  165. };
  166. function refresh() {
  167. var urlSuffix = '?cmd=admin-monitor-list&mode=1'
  168. if (mode == 1) {
  169. urlSuffix = '?cmd=admin-monitor-current&mode=1';
  170. }
  171. $.ajax({
  172. url: svUrl + urlSuffix,
  173. dataType: 'json',
  174. type: 'get',
  175. data: {},
  176. timeout: 4000,
  177. success: function(data) {
  178. if (data != null) {
  179. document.title = titles[0];
  180. $("div#countdown").removeClass("error");
  181. nextRefresh = refreshInterval;
  182. if (seconds > nextRefresh)
  183. seconds = nextRefresh;
  184. if (mode == 0)
  185. render(data.commands, data.uptime);
  186. else
  187. render(data.requests, data.uptime);
  188. gba.renderHealthMonitorFlot(data.health, data.tzshift, data.interval, "div#health");
  189. }
  190. else {
  191. refreshError();
  192. }
  193. },
  194. error: refreshError
  195. });
  196. }
  197. function refreshError() {
  198. document.title = titles[1];
  199. $("div#countdown").addClass("error");
  200. // Back off a bit.
  201. var newRefresh = nextRefresh + refreshInterval;
  202. if (newRefresh > maximumRefresh)
  203. newRefresh = maximumRefresh;
  204. seconds += (newRefresh - nextRefresh);
  205. nextRefresh = newRefresh;
  206. }
  207. function countdown() {
  208. seconds--;
  209. if (seconds == 0) {
  210. refresh();
  211. seconds = nextRefresh;
  212. }
  213. if (seconds == nextRefresh) {
  214. $("div#countdown").height("100%");
  215. }
  216. else {
  217. $("div#countdown").height(seconds * (100 / nextRefresh) + "%");
  218. }
  219. refreshLastUpdate();
  220. }
  221. function refreshLastUpdate() {
  222. if (lastUpdate > 0) {
  223. var sec = Math.floor((Date.now() - lastUpdate) / 1000);
  224. var content = "Last update at " + new Date(lastUpdate) + " (" + sec + " second" + (sec == 1 ? "" : "s") + " ago).";
  225. $("div#lastupdate").html(content);
  226. }
  227. }
  228. function renderControls() {
  229. var content = '';
  230. function item(label, index) {
  231. if (mode != index)
  232. return ' <a href="javascript:switchMode(' + index + ');">' + label + '</a>';
  233. else
  234. return ' <span class="enabled">' + label + '</span>';
  235. }
  236. content += item("Overall Performance", 0);
  237. content += item("Current Requests", 1);
  238. $("div#controls").html(content);
  239. }
  240. function switchMode(newMode) {
  241. mode = newMode;
  242. renderControls();
  243. renderHeader();
  244. refresh();
  245. }
  246. renderControls();
  247. renderHeader();
  248. refresh();
  249. window.setInterval(countdown, 1000);
  250. </script>
  251. </html>