From 5d3c797e5a5add21f750950e784f082b4d6cacf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E5=90=AF=E9=BE=99?= Date: Wed, 24 Jul 2024 18:05:24 +0800 Subject: [PATCH] fix: modify --- src/views/screen/RealTimeUsed.vue | 18 ++++++++++-------- src/views/screen/UsedTrend.vue | 2 +- src/views/screen/api.js | 14 +++++++++++--- src/views/screen/index.vue | 5 ++--- vue.config.js | 19 ------------------- 5 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/views/screen/RealTimeUsed.vue b/src/views/screen/RealTimeUsed.vue index 6384e50..cdcb3b6 100644 --- a/src/views/screen/RealTimeUsed.vue +++ b/src/views/screen/RealTimeUsed.vue @@ -18,6 +18,7 @@ export default { const chartDom = document.getElementById('RealTimeUsed') this.myChart = echarts.init(chartDom) this.getRealTimeUesdView() + this.getRealTimeData() this.timer = setInterval(() => { this.getRealTimeData() }, 10000) @@ -29,8 +30,9 @@ export default { // 平台实用利用率 async getRealTimeData() { const res = await getRealTimeUtilization() - if (res.status !== 'success') return - this.used = (res.data?.result?.[0]?.value[1] || 25.7).toFixed(2) + if (res?.status !== 'success') return + const value = res.data?.result?.[0]?.value[1] * 100 || 0 + this.used = value.toFixed(2) }, getRealTimeUesdView() { let angle = 0 @@ -59,7 +61,7 @@ export default { name: 'ring5', type: 'custom', coordinateSystem: 'none', - renderItem: function(params, api) { + renderItem: function (params, api) { return { type: 'arc', shape: { @@ -83,7 +85,7 @@ export default { name: 'ring5', type: 'custom', coordinateSystem: 'none', - renderItem: function(params, api) { + renderItem: function (params, api) { return { type: 'arc', shape: { @@ -107,7 +109,7 @@ export default { name: 'ring5', type: 'custom', coordinateSystem: 'none', - renderItem: function(params, api) { + renderItem: function (params, api) { return { type: 'arc', shape: { @@ -131,7 +133,7 @@ export default { name: 'ring5', type: 'custom', coordinateSystem: 'none', - renderItem: function(params, api) { + renderItem: function (params, api) { return { type: 'arc', shape: { @@ -155,7 +157,7 @@ export default { name: 'ring5', type: 'custom', coordinateSystem: 'none', - renderItem: function(params, api) { + renderItem: function (params, api) { const x0 = api.getWidth() / 2 const y0 = api.getHeight() / 2 const r = (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65 @@ -180,7 +182,7 @@ export default { name: 'ring5', // 绿点 type: 'custom', coordinateSystem: 'none', - renderItem: function(params, api) { + renderItem: function (params, api) { const x0 = api.getWidth() / 2 const y0 = api.getHeight() / 2 const r = (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65 diff --git a/src/views/screen/UsedTrend.vue b/src/views/screen/UsedTrend.vue index 545ebee..9ed8210 100644 --- a/src/views/screen/UsedTrend.vue +++ b/src/views/screen/UsedTrend.vue @@ -76,7 +76,7 @@ export default { // 平台实用利用率 async getQueryRangeData() { const res = await getAverageUtilizationTrend() - if (res.status !== 'success') return + if (res?.status !== 'success') return this.tableData7 = res.data?.result?.[0]?.values?.map((v) => { return { name: v[0], diff --git a/src/views/screen/api.js b/src/views/screen/api.js index fabafe5..e0bb956 100644 --- a/src/views/screen/api.js +++ b/src/views/screen/api.js @@ -89,20 +89,28 @@ export const getHelp = () => console.log(error) }) // 实时利用率 +const query = 'avg(1 - avg(rate(node_cpu_seconds_total{mode="idle"}[2m])) by (instance)) * 100' export const getRealTimeUtilization = () => axios - .get('/prometheus/api/v1/query?query=avg(1 - avg(rate(node_cpu_seconds_total{mode="idle"}[2m])) by (instance)) * 100') + .get(`/prometheus/api/v1/query?query=${encodeURIComponent(query)}`) .then(function (response) { return response.data }) .catch(function (error) { console.log(error) }) - +const query2 = 'avg(1 - avg(rate(node_cpu_seconds_total{mode="idle"}[2m]))) * 100' +const todayTimestamp = new Date().getTime() +const oneYearAgo = new Date() +oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1) +const oneYearAgoTimestamp = oneYearAgo.getTime() +const start = Math.floor(oneYearAgoTimestamp / 1000) +const end = Math.floor(todayTimestamp / 1000) +const step = '1036800' // 平均利用率趋势 export const getAverageUtilizationTrend = () => axios - .get('/prometheus/api/v1/query_range') + .get(`/prometheus/api/v1/query_range?query=${encodeURIComponent(query2)}&start=${start}&end=${end}&step=${step}`) .then(function (response) { return response.data }) diff --git a/src/views/screen/index.vue b/src/views/screen/index.vue index 0cde270..3486ea7 100644 --- a/src/views/screen/index.vue +++ b/src/views/screen/index.vue @@ -229,13 +229,12 @@ export default { if (item.keyName === 'userNum') { state.introItems[0].value = item.numValue } - if (item.keyName === 'softNum') { + if (item.keyName === 'orgNum') { state.introItems[1].value = item.numValue } - if (item.keyName === 'orgNum') { + if (item.keyName === 'softNum') { state.introItems[2].value = item.numValue } - if (item.keyName === 'timeSum') { state.introItems[3].value = item.numValue } diff --git a/vue.config.js b/vue.config.js index 8c2f3b0..da7a55c 100644 --- a/vue.config.js +++ b/vue.config.js @@ -27,25 +27,6 @@ module.exports = { errors: true }, proxy: { - '/api/sms/messageService': { - target: 'ws://' + proxyUrl, - changeOrigin: true, - ws: false - }, - '/api': { - target: httpType + proxyUrl, - changeOrigin: true, - ws: false - }, - '/config-files': { - target: httpType + proxyUrl - }, - '/scr-web/static/img': { - target: 'http://localhost:8083', - pathRewrite: { - '^/scr-web/static/img': '/static/img' // rewrite path - } - }, '/screen_server': { target: 'http://gn.api.aipow.cn:8080', changeOrigin: true,