index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <doc-alert title="Redis 缓存" url="https://doc.iocoder.cn/redis-cache/" />
  3. <doc-alert title="本地缓存" url="https://doc.iocoder.cn/local-cache/" />
  4. <el-scrollbar height="calc(100vh - 88px - 40px - 50px)">
  5. <el-row>
  6. <!-- 基本信息 -->
  7. <el-col :span="24" class="card-box" shadow="hover">
  8. <el-card>
  9. <el-descriptions title="基本信息" :column="6" border>
  10. <el-descriptions-item label="Redis版本 :">
  11. {{ cache?.info?.redis_version }}
  12. </el-descriptions-item>
  13. <el-descriptions-item label="运行模式 :">
  14. {{ cache?.info?.redis_mode == 'standalone' ? '单机' : '集群' }}
  15. </el-descriptions-item>
  16. <el-descriptions-item label="端口 :">
  17. {{ cache?.info?.tcp_port }}
  18. </el-descriptions-item>
  19. <el-descriptions-item label="客户端数 :">
  20. {{ cache?.info?.connected_clients }}
  21. </el-descriptions-item>
  22. <el-descriptions-item label="运行时间(天) :">
  23. {{ cache?.info?.uptime_in_days }}
  24. </el-descriptions-item>
  25. <el-descriptions-item label="使用内存 :">
  26. {{ cache?.info?.used_memory_human }}
  27. </el-descriptions-item>
  28. <el-descriptions-item label="使用CPU :">
  29. {{ cache?.info ? parseFloat(cache?.info?.used_cpu_user_children).toFixed(2) : '' }}
  30. </el-descriptions-item>
  31. <el-descriptions-item label="内存配置 :">
  32. {{ cache?.info?.maxmemory_human }}
  33. </el-descriptions-item>
  34. <el-descriptions-item label="AOF是否开启 :">
  35. {{ cache?.info?.aof_enabled == '0' ? '否' : '是' }}
  36. </el-descriptions-item>
  37. <el-descriptions-item label="RDB是否成功 :">
  38. {{ cache?.info?.rdb_last_bgsave_status }}
  39. </el-descriptions-item>
  40. <el-descriptions-item label="Key数量 :">
  41. {{ cache?.dbSize }}
  42. </el-descriptions-item>
  43. <el-descriptions-item label="网络入口/出口 :">
  44. {{ cache?.info?.instantaneous_input_kbps }}kps/
  45. {{ cache?.info?.instantaneous_output_kbps }}kps
  46. </el-descriptions-item>
  47. </el-descriptions>
  48. </el-card>
  49. </el-col>
  50. <!-- 命令统计 -->
  51. <el-col :span="12" class="mt-3">
  52. <el-card :gutter="12" shadow="hover">
  53. <div ref="commandStatsRef" class="h-88"></div>
  54. </el-card>
  55. </el-col>
  56. <!-- 内存使用量统计 -->
  57. <el-col :span="12" class="mt-3">
  58. <el-card class="ml-3" :gutter="12" shadow="hover">
  59. <div ref="usedmemory" class="h-88"></div>
  60. </el-card>
  61. </el-col>
  62. </el-row>
  63. </el-scrollbar>
  64. </template>
  65. <script setup lang="ts" name="Redis">
  66. import * as echarts from 'echarts'
  67. import * as RedisApi from '@/api/infra/redis'
  68. import { RedisMonitorInfoVO } from '@/api/infra/redis/types'
  69. const cache = ref<RedisMonitorInfoVO>()
  70. // 基本信息
  71. const readRedisInfo = async () => {
  72. const data = await RedisApi.getCache()
  73. cache.value = data
  74. loadEchartOptions(data.commandStats)
  75. }
  76. // 图表
  77. const commandStatsRef = ref<HTMLElement>()
  78. const usedmemory = ref<HTMLDivElement>()
  79. const loadEchartOptions = (stats) => {
  80. const commandStats = [] as any[]
  81. const nameList = [] as string[]
  82. stats.forEach((row) => {
  83. commandStats.push({
  84. name: row.command,
  85. value: row.calls
  86. })
  87. nameList.push(row.command)
  88. })
  89. const commandStatsInstance = echarts.init(commandStatsRef.value!, 'macarons')
  90. commandStatsInstance.setOption({
  91. title: {
  92. text: '命令统计',
  93. left: 'center'
  94. },
  95. tooltip: {
  96. trigger: 'item',
  97. formatter: '{a} <br/>{b} : {c} ({d}%)'
  98. },
  99. legend: {
  100. type: 'scroll',
  101. orient: 'vertical',
  102. right: 30,
  103. top: 10,
  104. bottom: 20,
  105. data: nameList,
  106. textStyle: {
  107. color: '#a1a1a1'
  108. }
  109. },
  110. series: [
  111. {
  112. name: '命令',
  113. type: 'pie',
  114. radius: [20, 120],
  115. center: ['40%', '60%'],
  116. data: commandStats,
  117. roseType: 'radius',
  118. label: {
  119. show: true
  120. },
  121. emphasis: {
  122. label: {
  123. show: true
  124. },
  125. itemStyle: {
  126. shadowBlur: 10,
  127. shadowOffsetX: 0,
  128. shadowColor: 'rgba(0, 0, 0, 0.5)'
  129. }
  130. }
  131. }
  132. ]
  133. })
  134. const usedMemoryInstance = echarts.init(usedmemory.value!, 'macarons')
  135. usedMemoryInstance.setOption({
  136. title: {
  137. text: '内存使用情况',
  138. left: 'center'
  139. },
  140. tooltip: {
  141. formatter: '{b} <br/>{a} : ' + cache.value!.info.used_memory_human
  142. },
  143. series: [
  144. {
  145. name: '峰值',
  146. type: 'gauge',
  147. min: 0,
  148. max: 100,
  149. progress: {
  150. show: true
  151. },
  152. detail: {
  153. formatter: cache.value!.info.used_memory_human
  154. },
  155. data: [
  156. {
  157. value: parseFloat(cache.value!.info.used_memory_human),
  158. name: '内存消耗'
  159. }
  160. ]
  161. }
  162. ]
  163. })
  164. }
  165. onBeforeMount(() => {
  166. readRedisInfo()
  167. })
  168. </script>