@@ -176,9 +188,9 @@ const CHART_KEY_NAME_MAPPING = {
// 仪表盘字段映射
const INSTRUMENT_BOARD_KEY_TO_NAME_MAPPING = {
- cpu: "CPU使用率",
- memory: "内存使用率",
- disk: "磁盘使用率"
+ cpu: 'CPU使用率',
+ memory: '内存使用率',
+ disk: '磁盘使用率'
}
// 仪表盘颜色范围
@@ -297,8 +309,8 @@ export default {
},
/**修改服务器信息*/
updateServerInfo() {
- updateServerInfo(this.currentServer.id, this.currentServer).then(results => {
- this.msgSuccess(results.msg || '修改服务器信息成功!')
+ updateServerInfo(this.currentServer.id, this.currentServer).then(() => {
+ this.msgSuccess('修改服务器信息成功!')
}).catch(error => {
this.$message.error(error.msg || '提交修改服务器信息出错!')
})
@@ -306,27 +318,7 @@ export default {
/** 获取服务器最新监控信息 */
getServerLatestLogInfo(serverId) {
getServerLatestLog(serverId).then(results => {
- // this.instrumentBoardData = results.data
- this.instrumentBoardData = {
- cpu: {
- total: 2,
- used: '', // cpu核心 可不传,如指cpu当前主频,该值可以传
- rate: 12,
- unit: '核心' // 默认单位 核心
- },
- memory: {
- total: 1024,
- used: 512,
- rate: 70,
- unit: 'MB' // 默认单位 MB
- },
- disk: {
- total: 50,
- used: 30,
- rate: 90,
- unit: 'GB' // 默认单位 GB
- }
- }
+ this.instrumentBoardData = results.data
}).catch(error => {
this.msgError(error.msg || '获取服务器最新监控信息错误!')
})
@@ -334,11 +326,7 @@ export default {
/** 获取监控日志信息 */
getCurrentServerMonitorLogs() {
getMonitorLogs(this.currentServer.id, { as: { 'create_datetime__range': this.timeRange } }).then(results => {
- // this.lineChartData = results.data
- this.lineChartData = {
- cpu: [0.5, 0.43, 0.56, 0.89, 0.5, 0.43, 0.56, 0.89, 0.5, 0.43, 0.56, 0.89, 0.5, 0.43, 0.56, 0.89],
- memory: [0.6, 0.43, 0.56, 0.56, 0.89, 0.5, 0.43, 0.43, 0.56, 0.56, 0.5, 0.43, 0.56, 0.89, 0.5]
- }
+ this.lineChartData = results.data
}).catch(error => {
this.msgError(error.msg || '获取监控日志信息出错误!')
})
@@ -356,9 +344,9 @@ export default {
/** 获取监控配置信息 */
getMonitorStatusSettingsInfo() {
getMonitorStatusInfo().then(results => {
- let { enabled, interval, save_days } = results
+ let { enabled, interval, save_days } = results.data
this.isOpeningMonitor = enabled
- this.monitorLogSavingDays = parseInt(save_days || 30)
+ this.monitorLogSavingDays = parseInt(save_days)
this.formatInterval(parseInt(interval))
}).catch(error => {
this.msgError(error.msg || '获取服务器监控配置信息出错误!')
@@ -366,8 +354,8 @@ export default {
},
/** 更新监控配置信息 */
updateMonitorStatusSettingsInfo() {
- updateMonitorStatusInfo(this.monitorStatusInfo).then(result => {
- this.msgSuccess(result.msg || '更新配置成功!')
+ updateMonitorStatusInfo(this.monitorStatusInfo).then(() => {
+ this.msgSuccess('更新配置成功!')
}).catch((error) => {
this.msgError(error.msg || '更新服务器监控配置信息出错误!')
})
From ff5706af5301a5900d5d4030135a0fc279b8a0f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com>
Date: Sat, 24 Apr 2021 12:47:28 +0800
Subject: [PATCH 17/21] =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD(=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E7=9B=91=E6=8E=A7API):=20=E6=9C=8D=E5=8A=A1=E7=9B=91?=
=?UTF-8?q?=E6=8E=A7API?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dvadmin-backend/apps/vadmin/monitor/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dvadmin-backend/apps/vadmin/monitor/views.py b/dvadmin-backend/apps/vadmin/monitor/views.py
index 67e2861..417ffc4 100644
--- a/dvadmin-backend/apps/vadmin/monitor/views.py
+++ b/dvadmin-backend/apps/vadmin/monitor/views.py
@@ -81,7 +81,7 @@ class MonitorModelViewSet(CustomModelViewSet):
"cpu": {
"total": int(data.get('cpu_num'), 0),
"used": "", # cpu核心 可不传,如指cpu当前主频,该值可以传
- "rate": float(data.get('cpu_sys', 0)),
+ "rate": float(data.get('cpu_sys', 0)) / 100,
"unit": "核心", # 默认单位 核心
},
"memory": {
From 51581abe1319681220a1172298bd85968e325ce4 Mon Sep 17 00:00:00 2001
From: xt12321 <1499410095@qq.com>
Date: Sat, 24 Apr 2021 15:40:33 +0800
Subject: [PATCH 18/21] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=98=E5=8C=96(inst?=
=?UTF-8?q?rumentBoard):=20=E6=94=AF=E6=8C=81=E5=A4=9A=E6=9D=A1=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E9=80=89=E6=8B=A9=E6=98=BE=E7=A4=BA=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../server/components/InstrumentBoard.vue | 139 +++++++++++++-----
.../src/views/vadmin/monitor/server/index.vue | 38 +----
2 files changed, 109 insertions(+), 68 deletions(-)
diff --git a/dvadmin-ui/src/views/vadmin/monitor/server/components/InstrumentBoard.vue b/dvadmin-ui/src/views/vadmin/monitor/server/components/InstrumentBoard.vue
index 5bbe83e..9b8d182 100644
--- a/dvadmin-ui/src/views/vadmin/monitor/server/components/InstrumentBoard.vue
+++ b/dvadmin-ui/src/views/vadmin/monitor/server/components/InstrumentBoard.vue
@@ -1,10 +1,29 @@
-
- {{ topTitleKeyToNameMapping[topTitle.text] || topTitle.text }}
+
+
+
+
+
+
+
+ {{ topTitle }}
+
+
-
{{ subTitleContent }}
+
{{ subTitle.content }}
+
@@ -14,58 +33,88 @@ import VueTypes from 'vue-types'
const echarts = require('echarts/lib/echarts')
require('echarts/lib/chart/gauge')
+// 仪表盘颜色范围
+const NORMAL_COLOR = {
+ color: '#28BCFE',
+ itemColor: ['#25bfff', '#5284de', '#2a95f9']
+}
+const WARNING_COLOR = {
+ color: '#e6a23c',
+ itemColor: ['#e6a23c', '#cc8b1d', '#ffaf18']
+}
+const DANGER_COLOR = {
+ color: '#F56C6C',
+ itemColor: ['#fd666d', '#cf1717', '#b31212']
+}
+
export default {
name: 'InstrumentBoard',
props: {
- // 组件唯一id
- ringGraphId: VueTypes.string.isRequired,
+ // 组件key
+ ringGraphKey: VueTypes.string.isRequired,
// 上标题
- topTitle: VueTypes.shape({
- show: VueTypes.bool,
- text: VueTypes.string
- }).def({
- show: false
- }),
+ showTopTitle: VueTypes.bool.def(false),
// 下标题
- subTitle: VueTypes.shape({
- show: VueTypes.bool,
- total: VueTypes.any,
- used: VueTypes.any,
- unit: VueTypes.string
- }).def({
- show: false
- }),
- // 使用率-数值
- usingRate: VueTypes.number.isRequired,
- // 使用率样式配置
- usingRateStyle: VueTypes.object.def({
- color: '#28BCFE',
- fontSize: 18,
- itemColor: ['#25BFFF', '#5284DE', '#2A95F9']
- }),
+ showSubTitle: VueTypes.bool.def(false),
+ // top title 配置映射
topTitleKeyToNameMapping: VueTypes.object.def({
cpu: 'CPU使用率',
- memory: '内存使用率',
- disk: '磁盘使用率'
- })
+ memory: '内存使用率'
+ }),
+ instrumentBoardData: VueTypes.any.isRequired
},
data() {
- return {}
+ return {
+ // 当前显示的数据
+ currentInstrumentBoardData: {}
+ }
},
computed: {
- subTitleContent() {
- let used = this.subTitle.used ? this.subTitle.used + '/' : ''
- let total = this.subTitle.total ? this.subTitle.total : ''
- let unit = this.subTitle.unit ? ` (${this.subTitle.unit})` : ''
- return `${used}${total}${unit} `
+ // 仪表盘是否存在多个数据
+ haveMultipleData() {
+ return this.instrumentBoardData instanceof Array && this.instrumentBoardData.length > 0
+ },
+ // 使用率
+ ringRate() {
+ let ringRate = this.currentInstrumentBoardData.rate
+ return ringRate < 1 ? ringRate * 100 : ringRate
+ },
+ // 仪表盘id
+ ringGraphId() {
+ return `${this.ringGraphKey}UsingRate`
+ },
+ // 上方标题
+ topTitle() {
+ return this.currentInstrumentBoardData['dir_name'] || this.topTitleKeyToNameMapping[this.ringGraphKey] || this.ringGraphKey
+ },
+ // 下方标题
+ subTitle() {
+ let used = this.currentInstrumentBoardData['used'] ? this.currentInstrumentBoardData['used'] + '/' : ''
+ let total = this.currentInstrumentBoardData['total'] ? this.currentInstrumentBoardData['total'] : ''
+ let unit = this.currentInstrumentBoardData['unit'] ? ` (${this.currentInstrumentBoardData['unit']})` : ''
+ let content = `${used}${total}${unit} `
+ let title = (this.currentInstrumentBoardData['used'] ? '已用/' : '') + '总量(单位)'
+ return { content, title }
+ },
+ // 使用率样式配置
+ usingRateStyle() {
+ return {
+ fontSize: 18,
+ ...this.getCircleColor(this.ringRate)
+ }
}
},
mounted() {
+ if (this.haveMultipleData) {
+ this.currentInstrumentBoardData = this.instrumentBoardData[0]
+ } else {
+ this.currentInstrumentBoardData = this.instrumentBoardData
+ }
this.drawBar()
},
methods: {
drawBar() {
- let currentRate = [this.usingRate]
+ let currentRate = [this.ringRate]
// 基于dom,初始化echarts实例
let RingGraph = echarts.init(document.getElementById(this.ringGraphId))
@@ -128,8 +177,24 @@ export default {
}
// 绘制图表
RingGraph.setOption(option)
+ },
+ // 仪表盘样式-颜色
+ getCircleColor(usingRate) {
+ if (usingRate < 60) {
+ return NORMAL_COLOR
+ } else if (usingRate > 60 && usingRate < 80) {
+ return WARNING_COLOR
+ } else if (usingRate > 80) {
+ return DANGER_COLOR
+ }
+ return NORMAL_COLOR
+ },
+ chooseDisplayInstrumentBoardData(index) {
+ this.currentInstrumentBoardData = this.instrumentBoardData[index]
+ this.drawBar()
}
}
+
}
diff --git a/dvadmin-ui/src/views/vadmin/monitor/server/index.vue b/dvadmin-ui/src/views/vadmin/monitor/server/index.vue
index b20b946..35ecb3d 100755
--- a/dvadmin-ui/src/views/vadmin/monitor/server/index.vue
+++ b/dvadmin-ui/src/views/vadmin/monitor/server/index.vue
@@ -59,6 +59,7 @@
@@ -190,21 +191,6 @@ const CHART_KEY_NAME_MAPPING = {
const INSTRUMENT_BOARD_KEY_TO_NAME_MAPPING = {
cpu: 'CPU使用率',
memory: '内存使用率',
- disk: '磁盘使用率'
-}
-
-// 仪表盘颜色范围
-const NORMAL_COLOR = {
- color: '#28BCFE',
- itemColor: ['#25bfff', '#5284de', '#2a95f9']
-}
-const WARNING_COLOR = {
- color: '#e6a23c',
- itemColor: ['#e6a23c', '#cc8b1d', '#ffaf18']
-}
-const DANGER_COLOR = {
- color: '#F56C6C',
- itemColor: ['#fd666d', '#cf1717', '#b31212']
}
// 服务器信息可修改字段
@@ -401,16 +387,6 @@ export default {
}
}
},
- // 仪表盘样式-颜色
- getCircleColor(usingRate) {
- if (usingRate < 60) {
- return NORMAL_COLOR
- } else if (usingRate > 60 && usingRate < 80) {
- return WARNING_COLOR
- } else if (usingRate > 80) {
- return DANGER_COLOR
- }
- }
}
}
From 88fa332916456636413c0815e375ca9c06c793a6 Mon Sep 17 00:00:00 2001
From: xt12321 <1499410095@qq.com>
Date: Sat, 24 Apr 2021 15:44:55 +0800
Subject: [PATCH 19/21] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=98=E5=8C=96(?=
=?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=9B=91=E6=8E=A7):=20=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E5=99=A8=E4=BF=A1=E6=81=AF=E5=8F=98=E6=9B=B4=E6=8F=90=E4=BA=A4?=
=?UTF-8?q?=E5=90=8E=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=9C=8D=E5=8A=A1=E5=99=A8?=
=?UTF-8?q?=E5=88=97=E8=A1=A8=E4=BF=A1=E6=81=AF=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dvadmin-ui/src/views/vadmin/monitor/server/index.vue | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/dvadmin-ui/src/views/vadmin/monitor/server/index.vue b/dvadmin-ui/src/views/vadmin/monitor/server/index.vue
index 35ecb3d..dd6c472 100755
--- a/dvadmin-ui/src/views/vadmin/monitor/server/index.vue
+++ b/dvadmin-ui/src/views/vadmin/monitor/server/index.vue
@@ -66,7 +66,7 @@