index.vue 8.0 KB

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