index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. <el-table
  67. v-loading="keyListLoad"
  68. :data="keyList"
  69. row-key="id"
  70. >
  71. <el-table-column prop="keyTemplate" label="Key 模板" width="200" />
  72. <el-table-column prop="keyType" label="Key 类型" width="100" />
  73. <el-table-column prop="valueType" label="Value 类型" />
  74. <el-table-column prop="timeoutType" label="超时时间" width="200">
  75. <template slot-scope="scope">
  76. <dict-tag :type="DICT_TYPE.INFRA_REDIS_TIMEOUT_TYPE" :value="scope.row.timeoutType" />
  77. <span v-if="scope.row.timeout > 0">({{ scope.row.timeout / 1000 }} 秒)</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="memo" label="备注" />
  81. </el-table>
  82. </div>
  83. </template>
  84. <script>
  85. import { getCache, getKeyList } from "@/api/infra/redis";
  86. import echarts from "echarts";
  87. export default {
  88. name: "Server",
  89. data() {
  90. return {
  91. // 统计命令信息
  92. commandstats: null,
  93. // 使用内存
  94. usedmemory: null,
  95. // cache 信息
  96. cache: [],
  97. // key 列表
  98. keyListLoad: true,
  99. keyList: [],
  100. };
  101. },
  102. created() {
  103. this.getList();
  104. this.openLoading();
  105. },
  106. methods: {
  107. /** 查缓存询信息 */
  108. getList() {
  109. // 查询 Redis 监控信息
  110. getCache().then((response) => {
  111. this.cache = response.data;
  112. this.$modal.closeLoading();
  113. this.commandstats = echarts.init(this.$refs.commandstats, "macarons");
  114. const commandStats = [];
  115. response.data.commandStats.forEach(row => {
  116. commandStats.push({
  117. name: row.command,
  118. value: row.calls
  119. });
  120. })
  121. this.commandstats.setOption({
  122. tooltip: {
  123. trigger: "item",
  124. formatter: "{a} <br/>{b} : {c} ({d}%)",
  125. },
  126. series: [
  127. {
  128. name: "命令",
  129. type: "pie",
  130. roseType: "radius",
  131. radius: [15, 95],
  132. center: ["50%", "38%"],
  133. data: commandStats,
  134. animationEasing: "cubicInOut",
  135. animationDuration: 1000,
  136. },
  137. ],
  138. });
  139. this.usedmemory = echarts.init(this.$refs.usedmemory, "macarons");
  140. this.usedmemory.setOption({
  141. tooltip: {
  142. formatter: "{b} <br/>{a} : " + this.cache.info.used_memory_human,
  143. },
  144. series: [
  145. {
  146. name: "峰值",
  147. type: "gauge",
  148. min: 0,
  149. max: 1000,
  150. detail: {
  151. formatter: this.cache.info.used_memory_human,
  152. },
  153. data: [
  154. {
  155. value: parseFloat(this.cache.info.used_memory_human),
  156. name: "内存消耗",
  157. },
  158. ],
  159. },
  160. ],
  161. });
  162. });
  163. // 查询 Redis Key 列表
  164. getKeyList().then(response => {
  165. this.keyList = response.data;
  166. this.keyListLoad = false;
  167. });
  168. },
  169. // 打开加载层
  170. openLoading() {
  171. this.$modal.loading("正在加载缓存监控数据,请稍后!");
  172. },
  173. },
  174. };
  175. </script>