show.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <script src="jq/jquery-3.5.1.min.js"></script>
  8. <script src="code/highcharts.js"></script>
  9. <script src="code/modules/exporting.js"></script>
  10. <script src="code/plugins/highcharts-zh_CN.js"></script>
  11. <style>
  12. #content div {
  13. float: left;
  14. }
  15. </style>
  16. <script>
  17. var apiUrl = "http://iaun.cn:18088/api"
  18. var id = ""
  19. var cpuLast = 0, memLast = 0;
  20. window.onload = function () {
  21. var search = window.location.search.substr(1).split("&")
  22. for (var i = 0, j = search.length; i < j; i++) {
  23. var temp = search[i].split('=');
  24. if (temp.length === 2 && temp[0] === "id") {
  25. id = temp[1];
  26. }
  27. }
  28. getData();
  29. loopGetData(5000, id);
  30. }
  31. function getData() {
  32. $.ajax({
  33. type: 'GET',
  34. url: apiUrl + '/cpu/get' + `?id=${id}&time=${cpuLast}&limit=50`,
  35. success: function (data) {
  36. cpuLast = (data.last !== 0) ? data.last : cpuLast;
  37. for (var i = 0, j = data["data"].length; i < j; i++) {
  38. var d = data["data"][i];
  39. var x = d["time"] * 1000, y = d["percent"];
  40. cpuChart.series[0].addPoint([x, y], true, true, true);
  41. }
  42. }
  43. });
  44. $.ajax({
  45. type: 'GET',
  46. url: apiUrl + '/memory/get' + `?id=${id}&time=${memLast}&limit=50`,
  47. success: function (data) {
  48. console.log(data);
  49. memLast = (data.last !== 0) ? data.last : memLast;
  50. for (var i = 0, j = data["data"].length; i < j; i++) {
  51. var d = data["data"][i];
  52. var x = d["time"] * 1000, y = d["used_percent"];
  53. memChart.series[0].addPoint([x, y], true, true, true);
  54. }
  55. }
  56. });
  57. }
  58. function loopGetData(time, id) {
  59. setInterval(function () {
  60. getData();
  61. }, time);
  62. }
  63. </script>
  64. </head>
  65. <body>
  66. <div id="content">
  67. <div id="container" style="width: 400px; height:200px;"></div>
  68. <div id="container_mem" style="width: 400px; height:200px;"></div>
  69. <!--<div style="width: 400px; height:200px;background: gray;"></div>
  70. <div style="width: 400px; height:200px;background: gray;"></div>
  71. <div style="width: 400px; height:200px;background: gray;"></div>
  72. <div style="width: 400px; height:200px;background: gray;"></div>
  73. <div style="width: 400px; height:200px;background: gray;"></div>-->
  74. </div>
  75. <script>
  76. function getConfig(name, count) {
  77. return {
  78. chart: {
  79. // type: 'spline',
  80. marginRight: 10
  81. },
  82. exporting: {
  83. buttons: {
  84. contextButton: {
  85. menuItems: null,
  86. onclick: function () {
  87. this.fullscreen.toggle();
  88. }
  89. }
  90. }
  91. },
  92. title: {
  93. text: name
  94. },
  95. xAxis: {
  96. type: 'datetime',
  97. tickPixelInterval: 150
  98. },
  99. credits: {
  100. enabled: false
  101. },
  102. yAxis: {
  103. title: {
  104. text: null
  105. }
  106. },
  107. tooltip: {
  108. formatter: function () {
  109. return '<b>' + this.series.name + '</b><br/>' +
  110. Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
  111. Highcharts.numberFormat(this.y, 2);
  112. }
  113. },
  114. legend: {
  115. enabled: false
  116. },
  117. plotOptions: {
  118. series: {
  119. marker: {
  120. enabled: false
  121. }
  122. }
  123. },
  124. series: [{
  125. name: name,
  126. data: (function () {
  127. var data = [], i;
  128. for (i = count * -1; i <= 0; i += 1) {
  129. data.push({
  130. x: null,
  131. y: null
  132. });
  133. }
  134. return data;
  135. }())
  136. }]
  137. };
  138. }
  139. /* events
  140. load: function () {
  141. var series = this.series[0];
  142. setInterval(function () {
  143. time += 1000;
  144. var x = new Date(time).getTime(), // 当前时间
  145. y = Math.random() * 100; // 随机值
  146. series.addPoint([x, y], true, true, true);
  147. }, 800);
  148. }
  149. */
  150. Highcharts.setOptions({
  151. global: {
  152. useUTC: false
  153. }
  154. });
  155. function activeLastPointToolip(chart) {
  156. var points = chart.series[0].points;
  157. chart.tooltip.refresh(points[points.length - 1]);
  158. }
  159. var time = (new Date()).getTime();
  160. var cpuChart = Highcharts.chart('container', getConfig('CPU', 20));
  161. var memChart = Highcharts.chart('container_mem', getConfig('Memory', 20));
  162. </script>
  163. </body>
  164. </html>