counter.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. function showSpeed() {
  2. var myChart = echarts.init(document.getElementById("container"));
  3. myChart.setOption({
  4. series: [{
  5. type: 'gauge',
  6. anchor: {
  7. show: true,
  8. showAbove: true,
  9. size: 18,
  10. itemStyle: {
  11. color: '#FAC858'
  12. }
  13. },
  14. pointer: {
  15. icon: 'path://M2.9,0.7L2.9,0.7c1.4,0,2.6,1.2,2.6,2.6v115c0,1.4-1.2,2.6-2.6,2.6l0,0c-1.4,0-2.6-1.2-2.6-2.6V3.3C0.3,1.9,1.4,0.7,2.9,0.7z',
  16. width: 8,
  17. length: '80%',
  18. offsetCenter: [0, '8%']
  19. },
  20. progress: {
  21. show: true,
  22. overlap: true,
  23. roundCap: true
  24. },
  25. axisLine: {
  26. roundCap: true
  27. },
  28. data: [{
  29. value: 0,
  30. name: 'CPU',
  31. title: {
  32. offsetCenter: ['-20%', '80%']
  33. },
  34. detail: {
  35. offsetCenter: ['-20%', '95%']
  36. }
  37. },
  38. {
  39. value: 0,
  40. name: '内存',
  41. title: {
  42. offsetCenter: ['20%', '80%']
  43. },
  44. detail: {
  45. offsetCenter: ['20%', '95%']
  46. }
  47. }
  48. ],
  49. title: {
  50. fontSize: 14
  51. },
  52. detail: {
  53. width: 40,
  54. height: 14,
  55. fontSize: 14,
  56. color: '#fff',
  57. backgroundColor: 'auto',
  58. borderRadius: 3,
  59. formatter: '{value}%'
  60. }
  61. }]
  62. });
  63. return myChart;
  64. }
  65. function showIO(data) {
  66. var myChart = echarts.init(document.getElementById("container-io"));
  67. myChart.setOption({
  68. tooltip: {
  69. trigger: 'axis',
  70. axisPointer: {
  71. animation: false
  72. }
  73. },
  74. dataZoom: [{
  75. type: 'inside',
  76. start: 90,
  77. end: 100,
  78. minValueSpan: 50
  79. }, {
  80. start: 90,
  81. end: 100,
  82. minValueSpan: 50
  83. }],
  84. xAxis: {
  85. type: 'time',
  86. splitLine: {
  87. show: false
  88. }
  89. }, yAxis: [
  90. {
  91. name: '磁盘',
  92. type: 'value'
  93. },
  94. {
  95. name: '网络',
  96. type: 'value'
  97. }
  98. ],
  99. legend: {
  100. data: ['磁盘读(KBps)', '磁盘写(KBps)', "网络上行(KBps)", "网络下行(KBps)"]
  101. },
  102. series: [{
  103. name: '磁盘读(KBps)',
  104. type: 'line',
  105. showSymbol: false,
  106. hoverAnimation: false,
  107. data: data.read,
  108. markLine: {
  109. data: [
  110. { type: 'average', name: '磁盘读平均值' }
  111. ]
  112. }
  113. }, {
  114. name: '磁盘写(KBps)',
  115. type: 'line',
  116. showSymbol: false,
  117. hoverAnimation: false,
  118. data: data.write,
  119. markLine: {
  120. data: [
  121. { type: 'average', name: '磁盘写平均值' }
  122. ]
  123. }
  124. }, {
  125. name: '网络上行(KBps)',
  126. yAxisIndex: 1,
  127. type: 'line',
  128. showSymbol: false,
  129. hoverAnimation: false,
  130. data: data.up,
  131. markLine: {
  132. data: [
  133. { type: 'average', name: '上行平均值' }
  134. ]
  135. }
  136. }, {
  137. name: '网络下行(KBps)',
  138. yAxisIndex: 1,
  139. type: 'line',
  140. showSymbol: false,
  141. hoverAnimation: false,
  142. data: data.down,
  143. markLine: {
  144. data: [
  145. { type: 'average', name: '下行平均值' }
  146. ]
  147. }
  148. }]
  149. });
  150. return myChart;
  151. }
  152. function showLine() {
  153. DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'GetHistoryList').then(data => {
  154. var myChart = echarts.init(document.getElementById("container-cpu"));
  155. myChart.setOption({
  156. visualMap: [{
  157. show: false,
  158. type: 'continuous',
  159. seriesIndex: 0
  160. }],
  161. tooltip: {
  162. trigger: 'axis',
  163. axisPointer: {
  164. animation: false
  165. }
  166. },
  167. dataZoom: [{
  168. type: 'inside',
  169. start: 90,
  170. end: 100,
  171. minValueSpan: 50
  172. }, {
  173. start: 90,
  174. end: 100,
  175. minValueSpan: 50
  176. }],
  177. xAxis: {
  178. type: 'time',
  179. splitLine: {
  180. show: false
  181. }
  182. },
  183. yAxis: {
  184. type: 'value',
  185. boundaryGap: [0, '100%'],
  186. splitLine: {
  187. show: false
  188. },
  189. max:100
  190. },
  191. legend: {
  192. data: ['CPU使用率', '内存使用率']
  193. },
  194. series: [{
  195. name: 'CPU使用率',
  196. type: 'line',
  197. showSymbol: false,
  198. hoverAnimation: false,
  199. data: data.cpu,
  200. markPoint: {
  201. data: [
  202. { type: 'max', name: '最大值' },
  203. { type: 'min', name: '最小值' }
  204. ]
  205. },
  206. markLine: {
  207. data: [
  208. { type: 'average', name: '平均值' }
  209. ]
  210. }
  211. }, {
  212. name: '内存使用率',
  213. type: 'line',
  214. showSymbol: false,
  215. hoverAnimation: false,
  216. data: data.mem,
  217. markPoint: {
  218. data: [
  219. { type: 'max', name: '最大值' },
  220. { type: 'min', name: '最小值' }
  221. ]
  222. },
  223. markLine: {
  224. data: [
  225. { type: 'average', name: '平均值' }
  226. ]
  227. }
  228. }]
  229. });
  230. var rateChart = showSpeed();
  231. var ioChart = showIO(data);
  232. setInterval(function () {
  233. DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'GetCurrentPerformanceCounter').then(item => {
  234. data.cpu.push([item.time, item.cpuLoad.toFixed(2)]);
  235. data.mem.push([item.time, item.memoryUsage.toFixed(2)]);
  236. data.read.push([item.time, item.diskRead.toFixed(2)]);
  237. data.write.push([item.time, item.diskWrite.toFixed(2)]);
  238. data.up.push([item.time, item.upload.toFixed(2)]);
  239. data.down.push([item.time, item.download.toFixed(2)]);
  240. myChart.setOption({
  241. series: [{
  242. data: data.cpu
  243. }, {
  244. data: data.mem
  245. }]
  246. });
  247. ioChart.setOption({
  248. series: [{
  249. data: data.read
  250. }, {
  251. data: data.write
  252. }, {
  253. data: data.up
  254. }, {
  255. data: data.down
  256. }]
  257. });
  258. let option = rateChart.getOption();
  259. option.series[0].data[0].value = item.cpuLoad.toFixed(2);
  260. option.series[0].data[1].value = item.memoryUsage.toFixed(2);
  261. rateChart.setOption(option, true);
  262. });
  263. }, 5000);
  264. });
  265. }