simulate.html.template 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <link rel="stylesheet" href="css/bootstrap.min.css" media="screen">
  5. <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
  6. <style type="text/css">
  7. body '{' font: 20px sans-serif; '}'
  8. .axis path,
  9. .axis line '{' fill: none; stroke: #000; shape-rendering: crispEdges; '}'
  10. .axis text '{' font-family: sans-serif; font-size: 20px; '}'
  11. .line '{' fill: none; stroke: steelblue; stroke-width: 3px; '}'
  12. .legend '{'
  13. padding: 5px;
  14. font: 18px sans-serif;
  15. background: yellow;
  16. box-shadow: 2px 2px 1px #888;
  17. '}'
  18. .title '{' font: 24px sans-serif; '}'
  19. .divborder '{'
  20. border-width: 1px;
  21. border-style: solid;
  22. border-color: black;
  23. margin-top:10px
  24. '}'
  25. </style>
  26. <script src="js/thirdparty/d3.v3.js"></script>
  27. <script src="js/thirdparty/jquery.js"></script>
  28. <script src="js/thirdparty/bootstrap.min.js"></script>
  29. </head>
  30. <body>
  31. <div class="row">
  32. <div class="span10 offset2"><br>
  33. <input type="button" style="float: right;" value="Stop"
  34. onClick="stop()" />
  35. </div>
  36. </div>
  37. <div class="row">
  38. <div class="divborder span8" style="margin-left:50px" id="area1"></div>
  39. <div class="divborder span8" style="margin-left:50px" id="area2"></div>
  40. </div>
  41. <div class="row">
  42. <div class="divborder span8" style="margin-left:50px" id="area3"></div>
  43. <div class="divborder span8" style="margin-left:50px" id="area4"></div>
  44. </div>
  45. <div class="row">
  46. <div class="divborder span8" style="margin-left:50px" id="area5"></div>
  47. <div class="divborder span8" style="margin-left:50px" id="area6"></div>
  48. </div>
  49. <div class="row">
  50. <div class="divborder span8" style="margin-left:50px" id="area7"></div>
  51. <div class="divborder span8" style="margin-left:50px" id="area8"></div>
  52. </div><br/><br/>
  53. <script>
  54. var basetime = 0;
  55. var running = 1;
  56. var data = [];
  57. var width, height;
  58. var legends = [];
  59. var titles = [];
  60. var yLabels = [];
  61. var isAreas = [];
  62. var svgs = [];
  63. var xs = [];
  64. var ys = [];
  65. var xAxiss = [];
  66. var yAxiss = [];
  67. var lineAreas = [];
  68. var stacks = [];
  69. // legends
  70. legends[0] = [''running.applications'', ''running.containers''];
  71. legends[1] = [''jvm.free.memory'', ''jvm.max.memory'', ''jvm.total.memory''];
  72. legends[2] = [''cluster.allocated.memory'', ''cluster.available.memory''];
  73. legends[3] = [''cluster.allocated.vcores'', ''cluster.available.vcores''];
  74. legends[4] = [];
  75. legends[5] = [];
  76. {0}
  77. legends[6] = [''scheduler.allocate.timecost'',
  78. ''scheduler.handle-NODE_ADDED.timecost'',
  79. ''scheduler.handle-NODE_REMOVED.timecost'',
  80. ''scheduler.handle-NODE_UPDATE.timecost'',
  81. ''scheduler.handle-APP_ADDED.timecost'',
  82. ''scheduler.handle-APP_REMOVED.timecost'',
  83. ''scheduler.handle-CONTAINER_EXPIRED.timecost'',
  84. ''scheduler.commit.success.timecost'',
  85. ''scheduler.commit.failure.timecost''];
  86. legends[7] = [''scheduler.commit.success.throughput'',
  87. ''scheduler.commit.failure.throughput''];
  88. // title
  89. titles[0] = ''Cluster running applications & containers'';
  90. titles[1] = ''JVM memory'';
  91. titles[2] = ''Cluster allocated & available memory'';
  92. titles[3] = ''Cluster allocated & available vcores'';
  93. titles[4] = ''Queue allocated memory'';
  94. titles[5] = ''Queue allocated vcores'';
  95. titles[6] = ''Scheduler allocate & handle & commit operation timecost'';
  96. titles[7] = ''Scheduler commit success/failure operation throughput'';
  97. // ylabels
  98. yLabels[0] = ''Number'';
  99. yLabels[1] = ''Memory (GB)'';
  100. yLabels[2] = ''Memory (GB)'';
  101. yLabels[3] = ''Number'';
  102. yLabels[4] = ''Memory (GB)'';
  103. yLabels[5] = ''Number'';
  104. yLabels[6] = ''Timecost (ms)'';
  105. yLabels[7] = ''Number'';
  106. // is area?
  107. isAreas = [0, 0, 0, 0, 1, 1, 0, 0];
  108. // draw all charts
  109. for (var i = 0; i < 8; i ++) '{'
  110. drawEachChart(i);
  111. '}'
  112. // draw each chart
  113. function drawEachChart(index) '{'
  114. var margin = '{'top: 50, right: 250, bottom: 50, left: 70'}';
  115. width = 750 - margin.left - margin.right;
  116. height = 420 - margin.top - margin.bottom;
  117. xs[index] = d3.scale.linear().range([0, width]);
  118. ys[index] = d3.scale.linear().range([height, 0]);
  119. xAxiss[index] = d3.svg.axis().scale(xs[index]).orient(''bottom'');
  120. yAxiss[index] = d3.svg.axis().scale(ys[index]).orient(''left'');
  121. if (isAreas[index] == 1)'{'
  122. lineAreas[index] = d3.svg.area()
  123. .x(function(d) '{' return xs[index](d.time); '}')
  124. .y0(function(d) '{' return ys[index](d.y0); '}')
  125. .y1(function(d) '{' return ys[index](d.y0 + d.y); '}');
  126. stacks[index] = d3.layout.stack()
  127. .values(function(d) '{' return d.values; '}');
  128. '}' else '{'
  129. lineAreas[index] = d3.svg.line()
  130. .interpolate(''basis'')
  131. .x(function(d) '{' return xs[index](d.time); '}')
  132. .y(function(d) '{' return ys[index](d.value); '}');
  133. '}'
  134. svgs[index] = d3.select(''#area'' + (index + 1)).append(''svg'')
  135. .attr(''width'', width + margin.left + margin.right)
  136. .attr(''height'', height + margin.top + margin.bottom)
  137. .append(''g'')
  138. .attr(''transform'', ''translate('' + margin.left + '','' + margin.top + '')'');
  139. // x, y and title
  140. svgs[index].append(''text'')
  141. .attr(''transform'', ''translate('' + (width / 2) + '' ,'' +
  142. (height + margin.bottom - 10 ) + '')'')
  143. .style(''text-anchor'', ''middle'')
  144. .text(''Time ({1})'');
  145. svgs[index].append(''text'')
  146. .attr(''transform'', ''rotate(-90)'')
  147. .attr(''y'', 0 - margin.left)
  148. .attr(''x'',0 - (height / 2))
  149. .attr(''dy'', ''1em'')
  150. .style(''text-anchor'', ''middle'')
  151. .text(yLabels[index]);
  152. svgs[index].append(''text'')
  153. .attr(''x'', (width / 2))
  154. .attr(''y'', 10 - (margin.top / 2))
  155. .attr(''text-anchor'', ''middle'')
  156. .text(titles[index]);
  157. '}'
  158. // request data
  159. function requestData() '{'
  160. $.ajax('{'url: ''simulateMetrics'',
  161. success: function(point) '{'
  162. // update data
  163. if (basetime == 0) basetime = point.time;
  164. point.time = (point.time - basetime) / {2};
  165. data.push(point);
  166. // clear old
  167. for (var i = 0; i < 8; i ++) '{'
  168. svgs[i].selectAll(''g.tick'').remove();
  169. svgs[i].selectAll(''g'').remove();
  170. var color = d3.scale.category10();
  171. color.domain(d3.keys(data[0]).filter(function(key) '{'
  172. return $.inArray(key, legends[i]) !== -1;
  173. '}'));
  174. var values;
  175. if (isAreas[i] == 1) '{'
  176. values = stacks[i](color.domain().map(function(name) '{'
  177. return '{'
  178. name: name,
  179. values: data.map(function(d) '{'
  180. return '{'time: d.time, y: d[name]'}';
  181. '}')
  182. '}'
  183. '}'));
  184. xs[i].domain(d3.extent(data, function(d) '{' return d.time;'}'));
  185. ys[i].domain([
  186. d3.min(values, function(c) '{' return 0; '}'),
  187. d3.max(values, function(c) '{' return 1.1 * d3.max(c.values,
  188. function(v) '{' return v.y + v.y0; '}'); '}')
  189. ]);
  190. '}' else '{'
  191. values = color.domain().map(function(name) '{'
  192. return '{'
  193. name: name,
  194. values: data.map(function(d) '{'
  195. return '{'time: d.time, value: d[name]'}';
  196. '}')
  197. '}'
  198. '}');
  199. xs[i].domain(d3.extent(data, function(d) '{' return d.time;'}'));
  200. ys[i].domain([
  201. d3.min(values, function(c) '{' return 0; '}'),
  202. d3.max(values, function(c) '{' return 1.1 * d3.max(c.values,
  203. function(v) '{' return v.value; '}'); '}')
  204. ]);
  205. '}'
  206. svgs[i].append(''g'').attr(''class'', ''x axis'')
  207. .attr(''transform'', ''translate(0,'' + height + '')'').call(xAxiss[i]);
  208. svgs[i].append(''g'').attr(''class'', ''y axis'').call(yAxiss[i]);
  209. var value = svgs[i].selectAll(''.path'')
  210. .data(values).enter().append(''g'').attr(''class'', ''line'');
  211. if(isAreas[i] == 1) '{'
  212. value.append(''path'').attr(''class'', ''area'')
  213. .attr(''d'', function(d) '{'return lineAreas[i](d.values); '}')
  214. .style(''fill'', function(d) '{'return color(d.name); '}');
  215. '}' else '{'
  216. value.append(''path'').attr(''class'', ''line'')
  217. .attr(''d'', function(d) '{'return lineAreas[i](d.values); '}')
  218. .style(''stroke'', function(d) '{'return color(d.name); '}');
  219. '}'
  220. // legend
  221. var legend = svgs[i].append(''g'')
  222. .attr(''class'', ''legend'')
  223. .attr(''x'', width + 5)
  224. .attr(''y'', 25)
  225. .attr(''height'', 120)
  226. .attr(''width'', 140);
  227. legend.selectAll(''g'').data(legends[i])
  228. .enter()
  229. .append(''g'')
  230. .each(function(d, i) '{'
  231. var g = d3.select(this);
  232. g.append(''rect'')
  233. .attr(''x'', width + 5)
  234. .attr(''y'', i*20)
  235. .attr(''width'', 10)
  236. .attr(''height'', 10)
  237. .style(''fill'', color(d));
  238. g.append(''text'')
  239. .attr(''x'', width + 25)
  240. .attr(''y'', i * 20 + 8)
  241. .attr(''height'',30)
  242. .attr(''width'',250)
  243. .style(''fill'', color(d))
  244. .text(d);
  245. '}');
  246. '}'
  247. if(running == 1)
  248. setTimeout(requestData, {3});
  249. '}',
  250. cache: false
  251. '}');
  252. '}'
  253. // stop
  254. function stop() '{'
  255. running = 0;
  256. '}'
  257. requestData();
  258. </script>
  259. </body>
  260. </html>