Skip to content

Commit 750149d

Browse files
committed
feat:add redis monitor
1 parent e412e5b commit 750149d

File tree

1 file changed

+208
-8
lines changed

1 file changed

+208
-8
lines changed

web/src/views/MonitorView.vue

Lines changed: 208 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,29 @@
4444
</el-row>
4545
</el-header>
4646
<el-main>
47-
<div v-show="!showswitch">chart</div>
47+
<div v-show="!showswitch">
48+
<el-row>
49+
<el-col :span="8" style="height:350px;">
50+
<div style="width:100%;height:100%" id="chart1"></div>
51+
</el-col>
52+
<el-col :span="8" style="height:350px;">
53+
<div style="width:100%;height:100%" id="chart2"></div>
54+
</el-col>
55+
<el-col :span="8" style="height:350px;">
56+
<div style="width:100%;height:100%" id="chart3"></div>
57+
</el-col>
58+
<el-col :span="8" style="height:350px;">
59+
<div style="width:100%;height:100%" id="chart4"></div>
60+
</el-col>
61+
<el-col :span="8" style="height:350px;">
62+
<div style="width:100%;height:100%" id="chart5"></div>
63+
</el-col>
64+
<el-col :span="8" style="height:350px;">
65+
<div style="width:100%;height:100%" id="chart6"></div>
66+
</el-col>
67+
</el-row>
68+
69+
</div>
4870
<div v-show="showswitch">data list</div>
4971
</el-main>
5072
</el-container>
@@ -55,27 +77,107 @@
5577
import { onMounted, ref } from '@vue/runtime-core'
5678
import { useRoute } from 'vue-router'
5779
import { serInfo } from "@/api/index.js"
80+
import * as echarts from "echarts";
5881
export default {
5982
name:"MonitorView",
6083
setup() {
6184
const route = new useRoute()
6285
let timer = null
86+
let xtime = []
87+
//内存
88+
let memuse = []
89+
let memChart = null
90+
let memChartOption = []
91+
const memChartChange = (used_memory)=>{
92+
if(memuse.length < 100){
93+
memuse.push(used_memory)
94+
}else{
95+
memuse.shift()
96+
memuse.push(used_memory)
97+
}
98+
memChartOption.xAxis.data = xtime
99+
memChartOption.series[0].data = memuse
100+
memChart.setOption(memChartOption)
101+
}
102+
103+
104+
//进口流量
105+
let input_kbps = []
106+
let inputChart = null
107+
let inputChartOption = []
108+
const inputChartChange = (input_kbps_val)=>{
109+
if(input_kbps.length < 100){
110+
input_kbps.push(input_kbps_val)
111+
}else{
112+
input_kbps.shift()
113+
input_kbps.push(input_kbps_val)
114+
}
115+
inputChartOption.xAxis.data = xtime
116+
inputChartOption.series[0].data = input_kbps
117+
inputChart.setOption(inputChartOption)
118+
}
119+
120+
//出口流量
121+
let output_kbps = []
122+
let outputChart = null
123+
let outputChartOption = []
124+
const outputChartChange = (output_kbps_val)=>{
125+
if(output_kbps.length < 100){
126+
output_kbps.push(output_kbps_val)
127+
}else{
128+
output_kbps.shift()
129+
output_kbps.push(output_kbps_val)
130+
}
131+
outputChartOption.xAxis.data = xtime
132+
outputChartOption.series[0].data = output_kbps
133+
outputChart.setOption(outputChartOption)
134+
}
135+
136+
const trans = (size) => {
137+
let kb = 1024
138+
let unit = ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
139+
let i = Math.floor(Math.log(size) / Math.log(kb))
140+
if(size > 0){
141+
return (size / Math.pow(kb, i)).toPrecision(3) + ' ' + unit[i];
142+
}else{
143+
return '0B'
144+
}
145+
}
146+
147+
148+
149+
const getInfo = ()=>{
150+
serInfo({key:"8e7eca1f7079c6a7861b3dcaa2dc8c05"}).then((res)=>{
151+
if(xtime.length < 100){
152+
xtime.push(res.data.time)
153+
}else{
154+
xtime.shift()
155+
xtime.push(res.data.time)
156+
}
157+
158+
//更新内存
159+
memChartChange(res.data.info.Memory.used_memory)
160+
//更新进口流量
161+
inputChartChange(res.data.info.Stats.instantaneous_input_kbps)
162+
//更新出口流量
163+
outputChartChange(res.data.info.Stats.instantaneous_output_kbps)
164+
})
165+
}
63166
64167
const intervalChange = (val)=>{
65168
clearTimeout(timer)
66169
timer = setInterval(()=>{
67-
console.log(new Date().getMinutes(),new Date().getSeconds())
170+
getInfo()
68171
},val * 1000)
69172
}
70173
71174
const autoChange = (val) => {
72-
console.log(val)
73175
if(val == false){
74176
clearTimeout(timer)
75177
timer = null
76178
}else{
77179
timer = setInterval(()=>{
78-
console.log(new Date().getMinutes(),new Date().getSeconds())
180+
getInfo()
79181
},interval.value * 1000)
80182
}
81183
}
@@ -87,16 +189,114 @@ export default {
87189
88190
if(autoupdate.value){
89191
timer = setInterval(()=>{
90-
console.log(new Date().getMinutes(),new Date().getSeconds())
192+
getInfo()
91193
},interval.value * 1000)
92194
}
93195
94196
onMounted(() => {
95197
// 打印
96198
console.log(route.params.sk)
97-
serInfo({key:"8e7eca1f7079c6a7861b3dcaa2dc8c05"}).then((res)=>{
98-
console.log(res)
99-
})
199+
xtime = []
200+
201+
memChart = echarts.init(document.getElementById('chart1'));
202+
memChartOption = {
203+
title: {
204+
text: 'Redis内存使用'
205+
},
206+
tooltip: {
207+
trigger: 'axis',
208+
formatter:(params)=>{
209+
return params[0].axisValueLabel+":"+ trans(params[0].data);
210+
},
211+
},
212+
xAxis: {
213+
type: 'category',
214+
data: []
215+
},
216+
yAxis: {
217+
type: 'value',
218+
axisLabel:{
219+
formatter:(value) => {
220+
return trans(value)
221+
}
222+
}
223+
},
224+
series: [
225+
{
226+
data: [],
227+
type: 'line',
228+
smooth: true
229+
}
230+
]
231+
};
232+
memChart.setOption(memChartOption);
233+
234+
235+
inputChart = echarts.init(document.getElementById('chart2'));
236+
inputChartOption = {
237+
title: {
238+
text: 'Redis进口流量'
239+
},
240+
tooltip: {
241+
trigger: 'axis',
242+
formatter:(params)=>{
243+
return params[0].axisValueLabel+":"+ params[0].data + "kbps";
244+
},
245+
},
246+
xAxis: {
247+
type: 'category',
248+
data: []
249+
},
250+
yAxis: {
251+
type: 'value',
252+
axisLabel:{
253+
formatter:(value) => {
254+
return value + "kbps"
255+
}
256+
}
257+
},
258+
series: [
259+
{
260+
data: [],
261+
type: 'line',
262+
smooth: true
263+
}
264+
]
265+
};
266+
inputChart.setOption(inputChartOption);
267+
268+
outputChart = echarts.init(document.getElementById('chart3'));
269+
outputChartOption = {
270+
title: {
271+
text: 'Redis出口流量'
272+
},
273+
tooltip: {
274+
trigger: 'axis',
275+
formatter:(params)=>{
276+
return params[0].axisValueLabel+":"+ params[0].data + "kbps";
277+
},
278+
},
279+
xAxis: {
280+
type: 'category',
281+
data: []
282+
},
283+
yAxis: {
284+
type: 'value',
285+
axisLabel:{
286+
formatter:(value) => {
287+
return value + "kbps"
288+
}
289+
}
290+
},
291+
series: [
292+
{
293+
data: [],
294+
type: 'line',
295+
smooth: true
296+
}
297+
]
298+
};
299+
outputChart.setOption(outputChartOption);
100300
})
101301
102302
return {

0 commit comments

Comments
 (0)