BUG(监控日志管理): 获取监控日志信息优化
parent
13902ef599
commit
467d5fc8a7
|
@ -48,19 +48,22 @@ class MonitorModelViewSet(CustomModelViewSet):
|
||||||
"""
|
"""
|
||||||
pk = kwargs.get("pk")
|
pk = kwargs.get("pk")
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
queryset = queryset.filter(server__id=pk).order_by("-create_datetime")
|
queryset = queryset.filter(server__id=pk).order_by("create_datetime")
|
||||||
# 间隔取值
|
# 间隔取值
|
||||||
queryset_count = queryset.count()
|
queryset_count = queryset.count()
|
||||||
Interval_num = 1 if queryset_count < 200 else int(queryset_count / 100)
|
Interval_num = 1 if queryset_count < 200 else int(queryset_count / 100)
|
||||||
queryset = queryset.values('cpu_sys', 'mem_num', 'mem_sys')[::Interval_num][:100]
|
queryset = queryset.values('cpu_sys', 'mem_num', 'mem_sys', 'create_datetime')[::Interval_num][:100]
|
||||||
data = {
|
data = {
|
||||||
"cpu": [],
|
"cpu": [],
|
||||||
"memory": [],
|
"memory": [],
|
||||||
|
"datetime": [],
|
||||||
}
|
}
|
||||||
for ele in queryset:
|
for ele in queryset:
|
||||||
data["cpu"].append(float(ele.get('cpu_sys', 0)) / 100)
|
data["cpu"].append(round(float(ele.get('cpu_sys', 0)), 2))
|
||||||
data["memory"].append(float(ele.get('mem_num', 0)) and round(float(ele.get('mem_sys', 0)) /
|
data["datetime"].append(ele.get('create_datetime').strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
float(ele.get('mem_num', 0)), 4))
|
data["memory"].append(round(float(ele.get('mem_num', 0)), 4) and round(float(ele.get('mem_sys', 0)) /
|
||||||
|
float(ele.get('mem_num', 0)) * 100,
|
||||||
|
2))
|
||||||
return SuccessResponse(data=data)
|
return SuccessResponse(data=data)
|
||||||
|
|
||||||
def get_monitor_info(self, request: Request, *args, **kwargs):
|
def get_monitor_info(self, request: Request, *args, **kwargs):
|
||||||
|
|
|
@ -74,14 +74,15 @@ export default {
|
||||||
serverInfo: VueTypes.object.isRequired,
|
serverInfo: VueTypes.object.isRequired,
|
||||||
lineChartKey: VueTypes.string.isRequired,
|
lineChartKey: VueTypes.string.isRequired,
|
||||||
chartTitle: VueTypes.string.isRequired,
|
chartTitle: VueTypes.string.isRequired,
|
||||||
chartData: VueTypes.array.isRequired
|
chartData: VueTypes.array.isRequired,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
TIME_LIMIT_SETTING,
|
TIME_LIMIT_SETTING,
|
||||||
timeLimit: DEFAULT_TIME,
|
timeLimit: DEFAULT_TIME,
|
||||||
lineChartId: this.lineChartKey + 'Chart',
|
lineChartId: this.lineChartKey + 'Chart',
|
||||||
lineChartData: this.chartData
|
lineChartData: this.chartData,
|
||||||
|
lineChartTime: this.chartData
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -107,9 +108,14 @@ export default {
|
||||||
let barGraph = echarts.init(document.getElementById(this.lineChartId))
|
let barGraph = echarts.init(document.getElementById(this.lineChartId))
|
||||||
// 绘制图表
|
// 绘制图表
|
||||||
barGraph.setOption({
|
barGraph.setOption({
|
||||||
tooltip: {
|
tooltip : {
|
||||||
trigger: 'item',
|
trigger: 'axis',
|
||||||
formatter: '{a} <br/>{b} : {c}'
|
axisPointer: {
|
||||||
|
type: 'cross',
|
||||||
|
label: {
|
||||||
|
backgroundColor: '#6a7985',
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
left: 'center',
|
left: 'center',
|
||||||
|
@ -120,7 +126,8 @@ export default {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
name: 'x',
|
name: 'x',
|
||||||
splitLine: { show: false },
|
splitLine: { show: false },
|
||||||
data: []
|
data:this.lineChartTime,
|
||||||
|
offset:20
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
left: '1%',
|
left: '1%',
|
||||||
|
@ -131,14 +138,19 @@ export default {
|
||||||
yAxis: {
|
yAxis: {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
name: '使用率',
|
name: '使用率',
|
||||||
|
axisLabel: {
|
||||||
|
show: true,
|
||||||
|
interval: 'auto',
|
||||||
|
formatter: '{value}%'
|
||||||
|
},
|
||||||
},
|
},
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
name: '使用率',
|
name: '使用率',
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: this.lineChartData
|
data: this.lineChartData,
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
changeTimeLimit(value) {
|
changeTimeLimit(value) {
|
||||||
|
@ -148,6 +160,7 @@ export default {
|
||||||
getCurrentServerMonitorLogs() {
|
getCurrentServerMonitorLogs() {
|
||||||
getMonitorLogs(this.serverInfo.id, {as: JSON.stringify({create_datetime__range: this.currentTimeLimitSetting.timeRange})}).then(results => {
|
getMonitorLogs(this.serverInfo.id, {as: JSON.stringify({create_datetime__range: this.currentTimeLimitSetting.timeRange})}).then(results => {
|
||||||
this.lineChartData = results.data[this.lineChartKey]
|
this.lineChartData = results.data[this.lineChartKey]
|
||||||
|
this.lineChartTime = results.data["datetime"]
|
||||||
this.drawBar()
|
this.drawBar()
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
this.$message.warning(error.msg || `获取${this.chartTitle}数据失败!`)
|
this.$message.warning(error.msg || `获取${this.chartTitle}数据失败!`)
|
||||||
|
|
Loading…
Reference in New Issue