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