redis.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="perf-redis">
  3. <p class="title">Redis</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>{{ used_memory | unit_size }}</p>
  14. </li>
  15. </ul>
  16. </div>
  17. </el-col>
  18. <el-col :span="8">
  19. <div class="block">
  20. <div class="icon _network">
  21. <icon-svg name="perf-network"></icon-svg>
  22. </div>
  23. <ul class="b scroller1">
  24. <li>
  25. <p>输入</p>
  26. <p>{{ total_net_input_bytes | unit_size }}</p>
  27. </li>
  28. <li>
  29. <p>输出</p>
  30. <p>{{ total_net_output_bytes | unit_size }}</p>
  31. </li>
  32. </ul>
  33. </div>
  34. </el-col>
  35. <el-col :span="8">
  36. <div class="block">
  37. <div class="icon _db">
  38. <icon-svg name="perf-db"></icon-svg>
  39. </div>
  40. <ul class="b scroller1">
  41. <li v-for="(item, index) in dbList" :key="index">
  42. <p>{{ item.label }}</p>
  43. <p>{{ item.value }} key</p>
  44. </li>
  45. </ul>
  46. </div>
  47. </el-col>
  48. </el-row>
  49. <vue-echarts ref="chart" :options="chartOptions" autoresize></vue-echarts>
  50. </div>
  51. </template>
  52. <script>
  53. import echarts from "echarts";
  54. import Common from "./common";
  55. export default {
  56. mixins: [Common],
  57. data() {
  58. return {
  59. dbList: [],
  60. chartOptions: {},
  61. total_net_input_bytes: 0,
  62. total_net_output_bytes: 0,
  63. used_memory: 0
  64. };
  65. },
  66. methods: {
  67. refresh({ data, time }) {
  68. const item = data[data.length - 1];
  69. const { Keyspace, Stats, Memory } = item.redis;
  70. let list = [];
  71. for (let i in Keyspace) {
  72. list.push({
  73. label: i,
  74. value: Keyspace[i].split(",")[0].split("=")[1]
  75. });
  76. }
  77. this.total_net_input_bytes = Stats.total_net_input_bytes;
  78. this.total_net_output_bytes = Stats.total_net_output_bytes;
  79. this.used_memory = Memory.used_memory;
  80. this.chartOptions = this.onChart(
  81. time,
  82. data.map((e) => e.redis.Stats.instantaneous_ops_per_sec),
  83. {
  84. color: "204, 32, 20",
  85. smooth: false
  86. }
  87. );
  88. this.dbList = list;
  89. },
  90. onChart(x, y) {
  91. return {
  92. tooltip: {
  93. trigger: "axis",
  94. axisPointer: {
  95. lineStyle: {
  96. color: "#F56C6C"
  97. }
  98. },
  99. backgroundColor: "rgb(255,255,255)",
  100. padding: [5, 10],
  101. textStyle: {
  102. color: "#F56C6C"
  103. },
  104. extraCssText: "box-shadow: 0 0 5px rgba(0, 0, 0, 0.3)",
  105. formatter: (arr) => {
  106. return `${arr[0].data} / S(每秒操作数)`;
  107. }
  108. },
  109. grid: {
  110. left: "10px",
  111. right: "10px",
  112. bottom: "10px",
  113. top: "30px"
  114. },
  115. xAxis: {
  116. type: "category",
  117. show: false,
  118. boundaryGap: false,
  119. splitLine: {
  120. interval: "auto",
  121. lineStyle: {
  122. color: ["#D4DFF5"]
  123. }
  124. },
  125. axisTick: {
  126. show: false
  127. },
  128. axisLine: {
  129. show: false,
  130. lineStyle: {
  131. color: "#609ee9"
  132. }
  133. },
  134. axisLabel: {
  135. margin: 10,
  136. textStyle: {
  137. fontSize: 12
  138. }
  139. },
  140. data: x
  141. },
  142. yAxis: {
  143. type: "value",
  144. show: false,
  145. splitLine: {
  146. show: true,
  147. lineStyle: {
  148. color: ["#D4DFF5"]
  149. }
  150. },
  151. axisTick: {
  152. show: false
  153. },
  154. axisLine: {
  155. show: true,
  156. lineStyle: {
  157. color: ["#609ee9"]
  158. }
  159. },
  160. axisLabel: {
  161. margin: 10,
  162. textStyle: {
  163. fontSize: 12
  164. }
  165. }
  166. },
  167. series: [
  168. {
  169. type: "line",
  170. smooth: true,
  171. showSymbol: false,
  172. symbol: "circle",
  173. symbolSize: 6,
  174. data: y,
  175. markPoint: {
  176. symbolSize: 30,
  177. data: [
  178. { type: "max", name: "最大值" },
  179. { type: "min", name: "最小值" }
  180. ]
  181. },
  182. areaStyle: {
  183. normal: {
  184. color: new echarts.graphic.LinearGradient(
  185. 0,
  186. 0,
  187. 0,
  188. 1,
  189. [
  190. {
  191. offset: 0,
  192. color: "rgba(245, 108, 108, 0.5)"
  193. },
  194. {
  195. offset: 1,
  196. color: "rgba(245, 108, 108, 0.1)"
  197. }
  198. ],
  199. false
  200. )
  201. }
  202. },
  203. itemStyle: {
  204. normal: {
  205. color: "#F56C6C"
  206. }
  207. },
  208. lineStyle: {
  209. normal: {
  210. width: 1
  211. }
  212. }
  213. }
  214. ]
  215. };
  216. }
  217. }
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. .perf-redis {
  222. background-color: #fff;
  223. .title {
  224. font-size: 16px;
  225. padding: 15px;
  226. border-bottom: 1px solid #f7f7f7;
  227. }
  228. .block {
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. height: 160px;
  233. font-size: 13px;
  234. margin: 0 10px;
  235. .icon {
  236. height: 60px;
  237. width: 60px;
  238. margin-bottom: 10px;
  239. border: 1px dashed #eee;
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. border-radius: 3px;
  244. margin-top: 25px;
  245. .icon-svg {
  246. font-size: 40px;
  247. }
  248. &._disk {
  249. color: #67c23a;
  250. }
  251. &._network {
  252. color: #409eff;
  253. }
  254. &._db {
  255. color: #e6a23c;
  256. }
  257. }
  258. .a {
  259. font-size: 13px;
  260. }
  261. .b {
  262. display: flex;
  263. text-align: center;
  264. width: 100%;
  265. overflow: auto hidden;
  266. li {
  267. list-style: none;
  268. flex: 1;
  269. margin: 0 8px;
  270. &:first-child {
  271. margin-left: 0;
  272. }
  273. &:last-child {
  274. margin-right: 0;
  275. }
  276. p {
  277. &:first-child {
  278. margin-bottom: 5px;
  279. font-size: 12px;
  280. color: #999;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. .echarts {
  287. height: 150px;
  288. width: 100%;
  289. margin-top: 10px;
  290. }
  291. }
  292. </style>