index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <script lang="ts" setup>
  2. import { onBeforeMount, ref } from 'vue'
  3. import * as RedisApi from '@/api/infra/redis'
  4. import DictTag from '@/components/DictTag/src/DictTag.vue'
  5. import { DICT_TYPE } from '@/utils/dict'
  6. import * as echarts from 'echarts'
  7. import { RedisKeyInfo, RedisMonitorInfoVO } from '@/api/infra/redis/types'
  8. import {
  9. ElRow,
  10. ElCard,
  11. ElCol,
  12. ElTable,
  13. ElTableColumn,
  14. ElScrollbar,
  15. ElDescriptions,
  16. ElDescriptionsItem
  17. } from 'element-plus'
  18. const cache = ref<RedisMonitorInfoVO>()
  19. const keyListLoad = ref(true)
  20. const keyList = ref<RedisKeyInfo[]>([])
  21. // 基本信息
  22. const readRedisInfo = async () => {
  23. const data = await RedisApi.getCacheApi()
  24. cache.value = data
  25. loadEchartOptions(data.commandStats)
  26. const redisKeysInfo = await RedisApi.getKeyDefineListApi()
  27. keyList.value = redisKeysInfo
  28. keyListLoad.value = false //加载完成
  29. }
  30. // 图表
  31. const commandStatsRef = ref<HTMLElement>()
  32. const usedmemory = ref<HTMLDivElement>()
  33. const loadEchartOptions = (stats) => {
  34. const commandStats = [] as any[]
  35. const nameList = [] as string[]
  36. stats.forEach((row) => {
  37. commandStats.push({
  38. name: row.command,
  39. value: row.calls
  40. })
  41. nameList.push(row.command)
  42. })
  43. const commandStatsInstance = echarts.init(commandStatsRef.value!, 'macarons')
  44. commandStatsInstance.setOption({
  45. title: {
  46. text: '命令统计',
  47. left: 'center'
  48. },
  49. tooltip: {
  50. trigger: 'item',
  51. formatter: '{a} <br/>{b} : {c} ({d}%)'
  52. },
  53. legend: {
  54. type: 'scroll',
  55. orient: 'vertical',
  56. right: 30,
  57. top: 10,
  58. bottom: 20,
  59. data: nameList,
  60. textStyle: {
  61. color: '#a1a1a1'
  62. }
  63. },
  64. series: [
  65. {
  66. name: '命令',
  67. type: 'pie',
  68. radius: [20, 120],
  69. center: ['40%', '60%'],
  70. data: commandStats,
  71. roseType: 'radius',
  72. label: {
  73. show: true
  74. },
  75. emphasis: {
  76. label: {
  77. show: true
  78. },
  79. itemStyle: {
  80. shadowBlur: 10,
  81. shadowOffsetX: 0,
  82. shadowColor: 'rgba(0, 0, 0, 0.5)'
  83. }
  84. }
  85. }
  86. ]
  87. })
  88. const usedMemoryInstance = echarts.init(usedmemory.value!, 'macarons')
  89. usedMemoryInstance.setOption({
  90. title: {
  91. text: '内存使用情况',
  92. left: 'center'
  93. },
  94. tooltip: {
  95. formatter: '{b} <br/>{a} : ' + cache.value!.info.used_memory_human
  96. },
  97. series: [
  98. {
  99. name: '峰值',
  100. type: 'gauge',
  101. min: 0,
  102. max: 100,
  103. progress: {
  104. show: true
  105. },
  106. detail: {
  107. formatter: cache.value!.info.used_memory_human
  108. },
  109. data: [
  110. {
  111. value: parseFloat(cache.value!.info.used_memory_human),
  112. name: '内存消耗'
  113. }
  114. ]
  115. }
  116. ]
  117. })
  118. }
  119. onBeforeMount(() => {
  120. readRedisInfo()
  121. })
  122. </script>
  123. <template>
  124. <el-scrollbar height="calc(100vh - 88px - 40px - 50px)">
  125. <el-row>
  126. <el-col :span="24" class="card-box" shadow="hover">
  127. <el-card>
  128. <el-descriptions title="基本信息" :column="6" border>
  129. <el-descriptions-item label="Redis版本 :">
  130. {{ cache?.info?.redis_version }}
  131. </el-descriptions-item>
  132. <el-descriptions-item label="运行模式 :">
  133. {{ cache?.info?.redis_mode == 'standalone' ? '单机' : '集群' }}
  134. </el-descriptions-item>
  135. <el-descriptions-item label="端口 :">
  136. {{ cache?.info?.tcp_port }}
  137. </el-descriptions-item>
  138. <el-descriptions-item label="客户端数 :">
  139. {{ cache?.info?.connected_clients }}
  140. </el-descriptions-item>
  141. <el-descriptions-item label="运行时间(天) :">
  142. {{ cache?.info?.uptime_in_days }}
  143. </el-descriptions-item>
  144. <el-descriptions-item label="使用内存 :">
  145. {{ cache?.info?.used_memory_human }}
  146. </el-descriptions-item>
  147. <el-descriptions-item label="使用CPU :">
  148. {{ cache?.info ? parseFloat(cache?.info?.used_cpu_user_children).toFixed(2) : '' }}
  149. </el-descriptions-item>
  150. <el-descriptions-item label="内存配置 :">
  151. {{ cache?.info?.maxmemory_human }}
  152. </el-descriptions-item>
  153. <el-descriptions-item label="AOF是否开启 :">
  154. {{ cache?.info?.aof_enabled == '0' ? '否' : '是' }}
  155. </el-descriptions-item>
  156. <el-descriptions-item label="RDB是否成功 :">
  157. {{ cache?.info?.rdb_last_bgsave_status }}
  158. </el-descriptions-item>
  159. <el-descriptions-item label="Key数量 :">
  160. {{ cache?.dbSize }}
  161. </el-descriptions-item>
  162. <el-descriptions-item label="网络入口/出口 :">
  163. {{ cache?.info?.instantaneous_input_kbps }}kps/
  164. {{ cache?.info?.instantaneous_output_kbps }}kps
  165. </el-descriptions-item>
  166. </el-descriptions>
  167. </el-card>
  168. </el-col>
  169. <el-col :span="12" style="margin-top: 10px">
  170. <el-card :gutter="12" shadow="hover">
  171. <div ref="commandStatsRef" style="height: 350px"></div>
  172. </el-card>
  173. </el-col>
  174. <el-col :span="12" style="margin-top: 10px">
  175. <el-card style="margin-left: 10px" :gutter="12" shadow="hover">
  176. <div ref="usedmemory" style="height: 350px"></div>
  177. </el-card>
  178. </el-col>
  179. </el-row>
  180. <el-row style="margin-top: 10px">
  181. <el-col :span="24" class="card-box" shadow="hover">
  182. <el-card>
  183. <el-table v-loading="keyListLoad" :data="keyList" row-key="id">
  184. <el-table-column prop="keyTemplate" label="Key 模板" width="200" />
  185. <el-table-column prop="keyType" label="Key 类型" width="100" />
  186. <el-table-column prop="valueType" label="Value 类型" />
  187. <el-table-column prop="timeoutType" label="超时时间" width="200">
  188. <template #default="{ row }">
  189. <DictTag :type="DICT_TYPE.INFRA_REDIS_TIMEOUT_TYPE" :value="row?.timeoutType" />
  190. <span v-if="row?.timeout > 0">({{ row?.timeout / 1000 }} 秒)</span>
  191. </template>
  192. </el-table-column>
  193. <el-table-column prop="memo" label="备注" />
  194. </el-table>
  195. </el-card>
  196. </el-col>
  197. </el-row>
  198. </el-scrollbar>
  199. </template>