mysql.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class="perf-mysql">
  3. <p class="title">Mysql</p>
  4. <el-row class="fn">
  5. <el-col :span="8">
  6. <div class="block">
  7. <div class="icon _disk">
  8. <icon-svg name="perf-disk"></icon-svg>
  9. </div>
  10. <ul class="b">
  11. <li>
  12. <p>已使用</p>
  13. <p>{{ data_size }}</p>
  14. </li>
  15. </ul>
  16. </div>
  17. </el-col>
  18. <el-col :span="8">
  19. <div class="block">
  20. <div class="icon _cache">
  21. <icon-svg name="perf-cache"></icon-svg>
  22. </div>
  23. <ul class="b">
  24. <li>
  25. <p>缓存数</p>
  26. <p>{{ Threads_cached }}</p>
  27. </li>
  28. </ul>
  29. </div>
  30. </el-col>
  31. <el-col :span="8">
  32. <div class="block">
  33. <div class="icon _connect">
  34. <icon-svg name="perf-connect"></icon-svg>
  35. </div>
  36. <ul class="b">
  37. <li>
  38. <p>连接数</p>
  39. <p>{{ Threads_connected }}</p>
  40. </li>
  41. </ul>
  42. </div>
  43. </el-col>
  44. </el-row>
  45. <vue-echarts ref="chart" :options="chartOptions" autoresize></vue-echarts>
  46. </div>
  47. </template>
  48. <script>
  49. import echarts from "echarts";
  50. import Common from "./common";
  51. export default {
  52. mixins: [Common],
  53. data() {
  54. return {
  55. chartOptions: {},
  56. Threads_connected: 0,
  57. Threads_cached: 0,
  58. data_size: 0
  59. };
  60. },
  61. methods: {
  62. refresh({ data, time }) {
  63. const item = data[data.length - 1];
  64. const { mysqlConn, mysqlSize } = item.mysql;
  65. this.Threads_cached = mysqlConn[0].Threads_cached;
  66. this.Threads_connected = mysqlConn[1].Threads_connected;
  67. this.data_size = mysqlSize.reduce((a, b) => a + parseFloat(b.data_size), 0) + "mb";
  68. this.chartOptions = this.onChart(
  69. time,
  70. data.map((e) => e.mysql.mysqlConn[3].Threads_running)
  71. );
  72. },
  73. onChart(x, y) {
  74. return {
  75. tooltip: {
  76. trigger: "axis",
  77. axisPointer: {
  78. lineStyle: {
  79. color: "rgb(15, 75, 111)"
  80. }
  81. },
  82. backgroundColor: "rgb(255,255,255)",
  83. padding: [5, 10],
  84. textStyle: {
  85. color: "rgb(15, 75, 111)"
  86. },
  87. extraCssText: "box-shadow: 0 0 5px rgba(0, 0, 0, 0.3)",
  88. formatter: (arr) => {
  89. return `线程数:${arr[0].data}`;
  90. }
  91. },
  92. grid: {
  93. left: "10px",
  94. right: "10px",
  95. bottom: "10px",
  96. top: "30px"
  97. },
  98. xAxis: {
  99. type: "category",
  100. show: false,
  101. boundaryGap: false,
  102. splitLine: {
  103. interval: "auto"
  104. },
  105. axisTick: {
  106. show: false
  107. },
  108. axisLine: {
  109. show: false
  110. },
  111. axisLabel: {
  112. margin: 10,
  113. textStyle: {
  114. fontSize: 12
  115. }
  116. },
  117. data: x
  118. },
  119. yAxis: {
  120. type: "value",
  121. show: false,
  122. splitLine: {
  123. show: true
  124. },
  125. axisTick: {
  126. show: false
  127. },
  128. axisLine: {
  129. show: true
  130. }
  131. },
  132. series: [
  133. {
  134. type: "line",
  135. smooth: true,
  136. showSymbol: false,
  137. symbol: "circle",
  138. symbolSize: 6,
  139. data: y,
  140. markPoint: {
  141. symbolSize: 30,
  142. data: [
  143. { type: "max", name: "最大值" },
  144. { type: "min", name: "最小值" }
  145. ]
  146. },
  147. areaStyle: {
  148. normal: {
  149. color: new echarts.graphic.LinearGradient(
  150. 0,
  151. 0,
  152. 0,
  153. 1,
  154. [
  155. {
  156. offset: 0,
  157. color: "rgba(15, 75, 111, 0.5)"
  158. },
  159. {
  160. offset: 1,
  161. color: "rgba(15, 75, 111, 0.1)"
  162. }
  163. ],
  164. false
  165. )
  166. }
  167. },
  168. itemStyle: {
  169. normal: {
  170. color: "rgb(15, 75, 111)"
  171. }
  172. },
  173. lineStyle: {
  174. normal: {
  175. width: 1
  176. }
  177. }
  178. }
  179. ]
  180. };
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .perf-mysql {
  187. background-color: #fff;
  188. .title {
  189. font-size: 16px;
  190. padding: 15px;
  191. border-bottom: 1px solid #f7f7f7;
  192. }
  193. .block {
  194. display: flex;
  195. flex-direction: column;
  196. align-items: center;
  197. height: 160px;
  198. font-size: 13px;
  199. .icon {
  200. height: 60px;
  201. width: 60px;
  202. margin-bottom: 10px;
  203. border: 1px dashed #eee;
  204. display: flex;
  205. justify-content: center;
  206. align-items: center;
  207. border-radius: 3px;
  208. margin-top: 25px;
  209. .icon-svg {
  210. font-size: 40px;
  211. }
  212. &._disk {
  213. color: #67c23a;
  214. }
  215. &._cache {
  216. color: #409eff;
  217. }
  218. &._connect {
  219. color: #e6a23c;
  220. }
  221. }
  222. .a {
  223. font-size: 13px;
  224. }
  225. .b {
  226. display: flex;
  227. text-align: center;
  228. width: 150px;
  229. li {
  230. list-style: none;
  231. flex: 1;
  232. p {
  233. &:first-child {
  234. margin-bottom: 5px;
  235. font-size: 12px;
  236. color: #999;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. .echarts {
  243. height: 150px;
  244. width: 100%;
  245. margin-top: 10px;
  246. }
  247. }
  248. </style>