index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="app-container">
  3. <doc-alert title="Redis 缓存" url="https://doc.iocoder.cn/redis-cache/" />
  4. <doc-alert title="本地缓存" url="https://doc.iocoder.cn/local-cache/" />
  5. <el-row>
  6. <el-col :span="24" class="card-box">
  7. <el-card>
  8. <div slot="header"><span>基本信息</span></div>
  9. <div class="el-table el-table--enable-row-hover el-table--medium">
  10. <table cellspacing="0" style="width: 100%">
  11. <tbody>
  12. <tr>
  13. <td><div class="cell">Redis版本</div></td>
  14. <td><div class="cell" v-if="cache.info">{{ cache.info.redis_version }}</div></td>
  15. <td><div class="cell">运行模式</div></td>
  16. <td><div class="cell" v-if="cache.info">{{ cache.info.redis_mode === "standalone" ? "单机" : "集群" }}</div></td>
  17. <td><div class="cell">端口</div></td>
  18. <td><div class="cell" v-if="cache.info">{{ cache.info.tcp_port }}</div></td>
  19. <td><div class="cell">客户端数</div></td>
  20. <td><div class="cell" v-if="cache.info">{{ cache.info.connected_clients }}</div></td>
  21. </tr>
  22. <tr>
  23. <td><div class="cell">运行时间(天)</div></td>
  24. <td><div class="cell" v-if="cache.info">{{ cache.info.uptime_in_days }}</div></td>
  25. <td><div class="cell">使用内存</div></td>
  26. <td><div class="cell" v-if="cache.info">{{ cache.info.used_memory_human }}</div></td>
  27. <td><div class="cell">使用CPU</div></td>
  28. <td><div class="cell" v-if="cache.info">{{ parseFloat(cache.info.used_cpu_user_children).toFixed(2) }}</div></td>
  29. <td><div class="cell">内存配置</div></td>
  30. <td><div class="cell" v-if="cache.info">{{ cache.info.maxmemory_human }}</div></td>
  31. </tr>
  32. <tr>
  33. <td><div class="cell">AOF是否开启</div></td>
  34. <td><div class="cell" v-if="cache.info">{{ cache.info.aof_enabled === "0" ? "否" : "是" }}</div></td>
  35. <td><div class="cell">RDB是否成功</div></td>
  36. <td><div class="cell" v-if="cache.info">{{ cache.info.rdb_last_bgsave_status }}</div></td>
  37. <td><div class="cell">Key数量</div></td>
  38. <td><div class="cell" v-if="cache.dbSize">{{ cache.dbSize }} </div></td>
  39. <td><div class="cell">网络入口/出口</div></td>
  40. <td><div class="cell" v-if="cache.info">{{ cache.info.instantaneous_input_kbps }}kps/{{cache.info.instantaneous_output_kbps}}kps</div></td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. </el-card>
  46. </el-col>
  47. <el-col :span="12" class="card-box">
  48. <el-card>
  49. <div slot="header"><span>命令统计</span></div>
  50. <div class="el-table el-table--enable-row-hover el-table--medium">
  51. <div ref="commandstats" style="height: 420px" />
  52. </div>
  53. </el-card>
  54. </el-col>
  55. <el-col :span="12" class="card-box">
  56. <el-card>
  57. <div slot="header">
  58. <span>内存信息</span>
  59. </div>
  60. <div class="el-table el-table--enable-row-hover el-table--medium">
  61. <div ref="usedmemory" style="height: 420px" />
  62. </div>
  63. </el-card>
  64. </el-col>
  65. </el-row>
  66. </div>
  67. </template>
  68. <script>
  69. import { getCache } from "@/api/infra/redis";
  70. import * as echarts from 'echarts'
  71. require('echarts/theme/macarons') // echarts theme
  72. export default {
  73. name: "Server",
  74. data () {
  75. return {
  76. // 统计命令信息
  77. commandstats: null,
  78. // 使用内存
  79. usedmemory: null,
  80. // cache 信息
  81. cache: []
  82. };
  83. },
  84. created () {
  85. this.getList();
  86. this.openLoading();
  87. },
  88. methods: {
  89. /** 查缓存询信息 */
  90. getList () {
  91. // 查询 Redis 监控信息
  92. getCache().then((response) => {
  93. this.cache = response.data;
  94. this.$modal.closeLoading();
  95. this.commandstats = echarts.init(this.$refs.commandstats, "macarons");
  96. const commandStats = [];
  97. response.data.commandStats.forEach(row => {
  98. commandStats.push({
  99. name: row.command,
  100. value: row.calls
  101. });
  102. })
  103. this.commandstats.setOption({
  104. tooltip: {
  105. trigger: "item",
  106. formatter: "{a} <br/>{b} : {c} ({d}%)",
  107. },
  108. series: [
  109. {
  110. name: "命令",
  111. type: "pie",
  112. roseType: "radius",
  113. radius: [15, 95],
  114. center: ["50%", "38%"],
  115. data: commandStats,
  116. animationEasing: "cubicInOut",
  117. animationDuration: 1000,
  118. },
  119. ],
  120. });
  121. this.usedmemory = echarts.init(this.$refs.usedmemory, "macarons");
  122. this.usedmemory.setOption({
  123. tooltip: {
  124. formatter: "{b} <br/>{a} : " + this.cache.info.used_memory_human,
  125. },
  126. series: [
  127. {
  128. name: "峰值",
  129. type: "gauge",
  130. min: 0,
  131. max: 1000,
  132. detail: {
  133. formatter: this.cache.info.used_memory_human,
  134. },
  135. data: [
  136. {
  137. value: parseFloat(this.cache.info.used_memory_human),
  138. name: "内存消耗",
  139. },
  140. ],
  141. },
  142. ],
  143. });
  144. });
  145. },
  146. // 打开加载层
  147. openLoading () {
  148. this.$modal.loading("正在加载缓存监控数据,请稍后!");
  149. }
  150. },
  151. };
  152. </script>