index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. @row-click="openCacheInfo"
  71. >
  72. <el-table-column prop="keyTemplate" label="Key 模板" width="200" />
  73. <el-table-column prop="keyType" label="Key 类型" width="100" />
  74. <el-table-column prop="valueType" label="Value 类型" />
  75. <el-table-column prop="timeoutType" label="超时时间" width="200">
  76. <template slot-scope="scope">
  77. <dict-tag
  78. :type="DICT_TYPE.INFRA_REDIS_TIMEOUT_TYPE"
  79. :value="scope.row.timeoutType"
  80. />
  81. <span v-if="scope.row.timeout > 0"
  82. >({{ scope.row.timeout / 1000 }} 秒)</span
  83. >
  84. </template>
  85. </el-table-column>
  86. <el-table-column prop="memo" label="备注" />
  87. </el-table>
  88. <!-- 缓存模块信息框 -->
  89. <el-dialog
  90. :title="keyTemplate + '模块'"
  91. :visible.sync="open"
  92. width="60vw"
  93. append-to-body
  94. >
  95. <el-row :gutter="10">
  96. <el-col :span="10" class="card-box">
  97. <el-card style="height: 70vh">
  98. <div slot="header">
  99. <span>键名列表</span>
  100. <el-button
  101. style="float: right; padding: 3px 0"
  102. type="text"
  103. icon="el-icon-refresh-right"
  104. @click="refreshCacheKeys"
  105. ></el-button>
  106. </div>
  107. <el-table
  108. :data="cachekeys"
  109. style="width: 100%"
  110. @row-click="handleCacheValue"
  111. >
  112. <el-table-column
  113. label="序号"
  114. width="60"
  115. type="index"
  116. ></el-table-column>
  117. <el-table-column
  118. label="缓存键名"
  119. align="center"
  120. :show-overflow-tooltip="true"
  121. :formatter="keyFormatter"
  122. >
  123. </el-table-column>
  124. <el-table-column
  125. label="操作"
  126. width="60"
  127. align="center"
  128. class-name="small-padding fixed-width"
  129. >
  130. <template slot-scope="scope">
  131. <el-button
  132. size="mini"
  133. type="text"
  134. icon="el-icon-delete"
  135. @click="handleClearCacheKey(scope.row)"
  136. ></el-button>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. </el-card>
  141. </el-col>
  142. <el-col :span="14">
  143. <el-card :bordered="false" style="height: 70vh">
  144. <div slot="header">
  145. <span>缓存内容</span>
  146. <!-- <el-button
  147. style="float: right; padding: 3px 0"
  148. type="text"
  149. icon="el-icon-refresh-right"
  150. @click="handleClearCacheAll()"
  151. >清理全部</el-button>
  152. -->
  153. </div>
  154. <el-form :model="cacheForm">
  155. <el-row :gutter="32">
  156. <el-col :offset="1" :span="22">
  157. <el-form-item label="缓存名称:" prop="keyTemplate">
  158. <el-input v-model="cacheForm.keyTemplate" :readOnly="true" />
  159. </el-form-item>
  160. </el-col>
  161. <el-col :offset="1" :span="22">
  162. <el-form-item label="缓存键名:" prop="key">
  163. <el-input v-model="cacheForm.key" :readOnly="true" />
  164. </el-form-item>
  165. </el-col>
  166. <el-col :offset="1" :span="22">
  167. <el-form-item label="缓存内容:" prop="value">
  168. <el-input
  169. v-model="cacheForm.value"
  170. type="textarea"
  171. :rows="12"
  172. :readOnly="true"
  173. />
  174. </el-form-item>
  175. </el-col>
  176. </el-row>
  177. </el-form>
  178. </el-card>
  179. </el-col>
  180. </el-row>
  181. </el-dialog>
  182. </div>
  183. </template>
  184. <script>
  185. import { getCache, getKeyList, getKeyDefineKeys, getKeyValue, clearCacheKey } from "@/api/infra/redis";
  186. import echarts from "echarts";
  187. export default {
  188. name: "Server",
  189. data () {
  190. return {
  191. // 统计命令信息
  192. commandstats: null,
  193. // 使用内存
  194. usedmemory: null,
  195. // cache 信息
  196. cache: [],
  197. // key 列表
  198. keyListLoad: true,
  199. keyList: [],
  200. // 模块弹出框
  201. open: false,
  202. keyTemplate: "",
  203. cachekeys: [],
  204. cacheForm: {}
  205. };
  206. },
  207. created () {
  208. this.getList();
  209. this.openLoading();
  210. },
  211. methods: {
  212. /** 查缓存询信息 */
  213. getList () {
  214. // 查询 Redis 监控信息
  215. getCache().then((response) => {
  216. this.cache = response.data;
  217. this.$modal.closeLoading();
  218. this.commandstats = echarts.init(this.$refs.commandstats, "macarons");
  219. const commandStats = [];
  220. response.data.commandStats.forEach(row => {
  221. commandStats.push({
  222. name: row.command,
  223. value: row.calls
  224. });
  225. })
  226. this.commandstats.setOption({
  227. tooltip: {
  228. trigger: "item",
  229. formatter: "{a} <br/>{b} : {c} ({d}%)",
  230. },
  231. series: [
  232. {
  233. name: "命令",
  234. type: "pie",
  235. roseType: "radius",
  236. radius: [15, 95],
  237. center: ["50%", "38%"],
  238. data: commandStats,
  239. animationEasing: "cubicInOut",
  240. animationDuration: 1000,
  241. },
  242. ],
  243. });
  244. this.usedmemory = echarts.init(this.$refs.usedmemory, "macarons");
  245. this.usedmemory.setOption({
  246. tooltip: {
  247. formatter: "{b} <br/>{a} : " + this.cache.info.used_memory_human,
  248. },
  249. series: [
  250. {
  251. name: "峰值",
  252. type: "gauge",
  253. min: 0,
  254. max: 1000,
  255. detail: {
  256. formatter: this.cache.info.used_memory_human,
  257. },
  258. data: [
  259. {
  260. value: parseFloat(this.cache.info.used_memory_human),
  261. name: "内存消耗",
  262. },
  263. ],
  264. },
  265. ],
  266. });
  267. });
  268. // 查询 Redis Key 列表
  269. getKeyList().then(response => {
  270. this.keyList = response.data;
  271. this.keyListLoad = false;
  272. });
  273. },
  274. // 打开加载层
  275. openLoading () {
  276. this.$modal.loading("正在加载缓存监控数据,请稍后!");
  277. },
  278. // 打开缓存弹窗
  279. openCacheInfo (e) {
  280. this.open = true;
  281. let keyDefine = e.keyTemplate.substring(0, e.keyTemplate.length - 2);
  282. this.keyTemplate = keyDefine;
  283. // 加载键名列表
  284. this.handleCacheKeys(keyDefine);
  285. },
  286. /** 键名前缀去除 */
  287. keyFormatter (cacheKey) {
  288. return cacheKey.replace(this.keyTemplate, "");
  289. },
  290. // 获取键名列表
  291. handleCacheKeys (keyDefine){
  292. const cacheName = keyDefine !== undefined ? keyDefine : this.keyTemplate;
  293. getKeyDefineKeys(cacheName).then(response => {
  294. this.cachekeys = response.data
  295. this.cacheForm = {}
  296. })
  297. },
  298. // 获取缓存值
  299. handleCacheValue (e){
  300. getKeyValue(this.keyTemplate, e).then(response => {
  301. this.cacheForm = response.data
  302. })
  303. },
  304. // 刷新键名列表
  305. refreshCacheKeys(){
  306. this.$modal.msgSuccess("刷新键名列表成功");
  307. this.handleCacheKeys();
  308. },
  309. // 删除缓存
  310. handleClearCacheKey(key){
  311. clearCacheKey(key).then(response =>{
  312. this.$modal.msgSuccess("清理缓存键名[" + key + "]成功");
  313. this.handleCacheKeys();
  314. })
  315. },
  316. },
  317. };
  318. </script>