index.vue 7.9 KB

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