index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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="150">
  73. <template slot-scope="scope">
  74. {{ getDictDataLabel(DICT_TYPE.INF_REDIS_TIMEOUT_TYPE, 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. loading: [],
  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.loading.close();
  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.loading = this.$loading({
  172. lock: true,
  173. text: "拼命读取中",
  174. spinner: "el-icon-loading",
  175. background: "rgba(0, 0, 0, 0.7)",
  176. });
  177. },
  178. },
  179. };
  180. </script>