guest_detail.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {% extends "layout.html" %}
  2. {% block title %} Guest {% endblock %}
  3. {% block head %}
  4. {{ super() }}
  5. <style type="text/css">
  6. @media (min-width: 768px) {
  7. .form-horizontal .control-label {
  8. text-align: left;
  9. }
  10. }
  11. label>span {
  12. color: deepskyblue;
  13. }
  14. .btn,
  15. .form-group>div>div,
  16. .form-control {
  17. border-radius: 0;
  18. }
  19. .btn-ability {
  20. margin-right: 16px;
  21. height: 50px;
  22. padding: 8px 50px;
  23. margin-bottom: 30px;
  24. }
  25. .btn-ability-line {
  26. }
  27. </style>
  28. {% endblock head %}
  29. {% block body %}
  30. <script>
  31. var resource_path = window.location.pathname;
  32. var resource_path_array = resource_path.split('/');
  33. var uuid = resource_path_array[resource_path_array.length - 1];
  34. var cpu_chart = null;
  35. var datetime_format_type = 'time';
  36. function format_time(timestamp, i) {
  37. if (datetime_format_type === 'time') {
  38. return new Date(timestamp).format('HH:MM');
  39. } else {
  40. return new Date(timestamp).format('mm-dd');
  41. }
  42. }
  43. function render_cpu_memory_chart(uuid) {
  44. $.ajax({
  45. url : '/api/performance/cpu_memory/last_hour/' + uuid,
  46. type : 'GET',
  47. contentType: "application/json; charset=utf-8",
  48. dataType: 'json',
  49. error : function() {
  50. alter_danger('获取图表数据失败失败!');
  51. },
  52. success : function(data, textStatus, xhr) {
  53. if (data.data.length > 1) {
  54. if ((data.data[data.data.length - 1]['timestamp'] - data.data[0]['timestamp']) >= 86400) {
  55. datetime_format_type = 'date';
  56. }
  57. }
  58. var option = {
  59. color: ['#3BC0FF'],
  60. title: {
  61. text: 'CPU'
  62. },
  63. legend: {
  64. data:['CPU使用率(%)'],
  65. bottom: 5
  66. },
  67. toolbox: {
  68. feature: {
  69. dataZoom: {
  70. yAxisIndex: 'none'
  71. },
  72. magicType: {type: ['line', 'bar']},
  73. saveAsImage: {show: true}
  74. }
  75. },
  76. tooltip: {
  77. show: true,
  78. trigger: 'axis',
  79. formatter: (function (params, ticket, callback) {
  80. var cpu_load = params[0].data[1];
  81. var seriesName = params[0].seriesName;
  82. var marker = params[0].marker;
  83. var datetime = new Date(params[0].data[0]).format('yyyy-mm-dd HH:MM:ss');
  84. if (cpu_load === null) {
  85. cpu_load = '无数据';
  86. }
  87. return datetime + '<br />' + [marker, seriesName, cpu_load].join(' ')
  88. })
  89. },
  90. xAxis: {
  91. type: 'time',
  92. axisTick: {
  93. show: false
  94. },
  95. axisLine: {
  96. lineStyle: {
  97. opacity: 0.1,
  98. color: '#3d4245'
  99. }
  100. },
  101. splitLine: {
  102. show: false
  103. },
  104. axisLabel: {
  105. formatter: format_time
  106. }
  107. },
  108. yAxis: {
  109. min: 0,
  110. max: 'dataMax',
  111. minInterval: 2,
  112. axisTick: {
  113. show: false
  114. },
  115. axisLine: {
  116. lineStyle: {
  117. opacity: 0,
  118. color: '#8c8f91'
  119. }
  120. },
  121. splitLine: {
  122. show: true,
  123. lineStyle: {
  124. width: 1,
  125. opacity: 0.5
  126. }
  127. }
  128. },
  129. series: [{
  130. name: 'CPU使用率(%)',
  131. type: 'line',
  132. showSymbol: false,
  133. smooth: true,
  134. lineStyle: {
  135. normal: {
  136. width: 1
  137. }
  138. },
  139. data: (function () {
  140. var d = [];
  141. $.each(data.data, function(i, ele) {
  142. d.push([
  143. ele['timestamp'] * 1000,
  144. ele['cpu_load']
  145. ])
  146. });
  147. return d;
  148. })()
  149. }]
  150. };
  151. cpu_chart.setOption(option);
  152. }
  153. });
  154. }
  155. $(document).ready(function() {
  156. $('body').addClass('add-transition');
  157. $('.add-page-transition').on('click', function(){
  158. var transAttr = $(this).attr('data-transition');
  159. $('.add-transition').attr('class', 'add-transition');
  160. $('.add-transition').addClass(transAttr);
  161. });
  162. cpu_chart = echarts.init(document.getElementById('cpu_chart'));
  163. render_cpu_memory_chart(uuid);
  164. });
  165. </script>
  166. <div class="container" style="padding-top: 100px; width: 90%; max-width: 100%;">
  167. <div class="panel">
  168. <div class="panel-body">
  169. <h3 class="title-hero" style="display: inline;">
  170. 虚拟机实例详情
  171. </h3>
  172. <a href="/guests" class="btn btn-xs btn-default add-page-transition" data-transition="pt-page-moveFromLeft-init" style="margin-bottom: 4px; margin-left: 10px;">
  173. <span class="glyph-icon icon-separator" style="transform: rotateY(-180deg);">
  174. <i class="glyph-icon icon-level-up"></i>
  175. </span>
  176. <span class="button-content">
  177. 返回虚拟机列表
  178. </span>
  179. </a>
  180. <div class="row">
  181. <div class="col-xs-4">
  182. <h1>H1llo</h1>
  183. </div>
  184. <div class="col-xs-8">
  185. <div id="cpu_chart" style="width: 800px;height:280px;"></div>
  186. <div id="traffic_chart" style="width: 600px;height:300px;"></div>
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. {% endblock body %}