index.vue 6.4 KB

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