index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. <Echart :options="commandStatsRefChika" :height="420" />
  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. <Echart :options="usedmemoryEchartChika" :height="420" />
  60. </el-card>
  61. </el-col>
  62. </el-row>
  63. </el-scrollbar>
  64. </template>
  65. <script setup lang="ts">
  66. import * as RedisApi from '@/api/infra/redis'
  67. import { RedisMonitorInfoVO } from '@/api/infra/redis/types'
  68. const cache = ref<RedisMonitorInfoVO>()
  69. // 基本信息
  70. const readRedisInfo = async () => {
  71. const data = await RedisApi.getCache()
  72. cache.value = data
  73. }
  74. // 内存使用情况
  75. const usedmemoryEchartChika = reactive<any>({
  76. title: {
  77. // 仪表盘标题。
  78. text: '内存使用情况',
  79. left: 'center',
  80. show: true, // 是否显示标题,默认 true。
  81. offsetCenter: [0, '20%'], //相对于仪表盘中心的偏移位置,数组第一项是水平方向的偏移,第二项是垂直方向的偏移。可以是绝对的数值,也可以是相对于仪表盘半径的百分比。
  82. color: 'yellow', // 文字的颜色,默认 #333。
  83. fontSize: 20 // 文字的字体大小,默认 15。
  84. },
  85. toolbox: {
  86. show: false,
  87. feature: {
  88. restore: { show: true },
  89. saveAsImage: { show: true }
  90. }
  91. },
  92. series: [
  93. {
  94. name: '峰值',
  95. type: 'gauge',
  96. min: 0,
  97. max: 50,
  98. splitNumber: 10,
  99. //这是指针的颜色
  100. color: '#F5C74E',
  101. radius: '85%',
  102. center: ['50%', '50%'],
  103. startAngle: 225,
  104. endAngle: -45,
  105. axisLine: {
  106. // 坐标轴线
  107. lineStyle: {
  108. // 属性lineStyle控制线条样式
  109. color: [
  110. [0.2, '#7FFF00'],
  111. [0.8, '#00FFFF'],
  112. [1, '#FF0000']
  113. ],
  114. //width: 6 外框的大小(环的宽度)
  115. width: 10
  116. }
  117. },
  118. axisTick: {
  119. // 坐标轴小标记
  120. //里面的线长是5(短线)
  121. length: 5, // 属性length控制线长
  122. lineStyle: {
  123. // 属性lineStyle控制线条样式
  124. color: '#76D9D7'
  125. }
  126. },
  127. splitLine: {
  128. // 分隔线
  129. length: 20, // 属性length控制线长
  130. lineStyle: {
  131. // 属性lineStyle(详见lineStyle)控制线条样式
  132. color: '#76D9D7'
  133. }
  134. },
  135. axisLabel: {
  136. color: '#76D9D7',
  137. distance: 15,
  138. fontSize: 15
  139. },
  140. pointer: {
  141. // 指针的大小
  142. width: 7,
  143. show: true
  144. },
  145. detail: {
  146. textStyle: {
  147. fontWeight: 'normal',
  148. // 里面文字下的数值大小(50)
  149. fontSize: 15,
  150. color: '#FFFFFF'
  151. },
  152. valueAnimation: true
  153. },
  154. progress: {
  155. show: true
  156. }
  157. }
  158. ]
  159. })
  160. // 指令使用情况
  161. const commandStatsRefChika = reactive({
  162. title: {
  163. text: '命令统计',
  164. left: 'center'
  165. },
  166. tooltip: {
  167. trigger: 'item',
  168. formatter: '{a} <br/>{b} : {c} ({d}%)'
  169. },
  170. legend: {
  171. type: 'scroll',
  172. orient: 'vertical',
  173. right: 30,
  174. top: 10,
  175. bottom: 20,
  176. data: [] as any[],
  177. textStyle: {
  178. color: '#a1a1a1'
  179. }
  180. },
  181. series: [
  182. {
  183. name: '命令',
  184. type: 'pie',
  185. radius: [20, 120],
  186. center: ['40%', '60%'],
  187. data: [] as any[],
  188. roseType: 'radius',
  189. label: {
  190. show: true
  191. },
  192. emphasis: {
  193. label: {
  194. show: true
  195. },
  196. itemStyle: {
  197. shadowBlur: 10,
  198. shadowOffsetX: 0,
  199. shadowColor: 'rgba(0, 0, 0, 0.5)'
  200. }
  201. }
  202. }
  203. ]
  204. })
  205. /** 加载数据 */
  206. const getSummary = () => {
  207. // 初始化命令图表
  208. initCommandStatsChart()
  209. usedMemoryInstance()
  210. }
  211. /** 命令使用情况 */
  212. const initCommandStatsChart = async () => {
  213. usedmemoryEchartChika.series[0].data = []
  214. // 发起请求
  215. try {
  216. const data = await RedisApi.getCache()
  217. cache.value = data
  218. // 处理数据
  219. const commandStats = [] as any[]
  220. const nameList = [] as string[]
  221. data.commandStats.forEach((row) => {
  222. commandStats.push({
  223. name: row.command,
  224. value: row.calls
  225. })
  226. nameList.push(row.command)
  227. })
  228. commandStatsRefChika.legend.data = nameList
  229. commandStatsRefChika.series[0].data = commandStats
  230. } catch {}
  231. }
  232. const usedMemoryInstance = async () => {
  233. try {
  234. const data = await RedisApi.getCache()
  235. cache.value = data
  236. // 仪表盘详情,用于显示数据。
  237. usedmemoryEchartChika.series[0].detail = {
  238. show: true, // 是否显示详情,默认 true。
  239. offsetCenter: [0, '50%'], // 相对于仪表盘中心的偏移位置,数组第一项是水平方向的偏移,第二项是垂直方向的偏移。可以是绝对的数值,也可以是相对于仪表盘半径的百分比。
  240. color: 'auto', // 文字的颜色,默认 auto。
  241. fontSize: 30, // 文字的字体大小,默认 15。
  242. formatter: cache.value!.info.used_memory_human // 格式化函数或者字符串
  243. }
  244. usedmemoryEchartChika.series[0].data[0] = {
  245. value: cache.value!.info.used_memory_human,
  246. name: '内存消耗'
  247. }
  248. console.log(cache.value!.info)
  249. usedmemoryEchartChika.tooltip = {
  250. formatter: '{b} <br/>{a} : ' + cache.value!.info.used_memory_human
  251. }
  252. } catch {}
  253. }
  254. /** 初始化 **/
  255. onMounted(() => {
  256. // 读取 redis 信息
  257. readRedisInfo()
  258. // 加载数据
  259. getSummary()
  260. })
  261. </script>