From b5d28b4ef2a8a2fc96abb0d1529b0561e517ed9c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 19 Dec 2023 23:31:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E6=98=BE=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/system_api.py | 4 +-- route/static/app/index.js | 72 ++++++++++++++++++++++++-------------- route/static/app/public.js | 2 +- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/class/core/system_api.py b/class/core/system_api.py index f6a395a13..60a0e2aa7 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -558,9 +558,9 @@ class system_api: networkInfo['upTotal'] = networkIo[0] networkInfo['downTotal'] = networkIo[1] networkInfo['up'] = round(float( - networkIo[0] - session['up']) / 1024 / (ntime - session['otime']), 2) + networkIo[0] - session['up']) / (ntime - session['otime']), 2) networkInfo['down'] = round( - float(networkIo[1] - session['down']) / 1024 / (ntime - session['otime']), 2) + float(networkIo[1] - session['down']) / (ntime - session['otime']), 2) networkInfo['downPackets'] = networkIo[3] networkInfo['upPackets'] = networkIo[2] diff --git a/route/static/app/index.js b/route/static/app/index.js index 81c06fdf2..9538dffea 100755 --- a/route/static/app/index.js +++ b/route/static/app/index.js @@ -29,6 +29,7 @@ $(function() { } }); }); + //获取负载 function getLoad(data) { $("#LoadList .mask").html("获取中.."); @@ -83,19 +84,18 @@ function showCpuTips(rdata){ $('#cpuChart .mask').unbind(); $('#cpuChart .mask').hover(function() { var cpuText = ''; - if (rdata.cpu[2].length == 1){ var cpuUse = parseFloat(rdata.cpu[2][0] == 0 ? 0 : rdata.cpu[2][0]).toFixed(1); - cpuText += 'CPU-1:' + cpuUse + '%' - } else{ + cpuText += 'CPU-1:' + cpuUse + '%'; + } else { for (var i = 1; i < rdata.cpu[2].length + 1; i++) { - var cpuUse = parseFloat(rdata.cpu[2][i - 1] == 0 ? 0 : rdata.cpu[2][i - 1]).toFixed(1); - if (i % 2 != 0) { - cpuText += 'CPU-' + i + ':' + cpuUse + '% | ' - } else { - cpuText += 'CPU-' + i + ':' + cpuUse + '%' - cpuText += '\n' - } + var cpuUse = parseFloat(rdata.cpu[2][i - 1] == 0 ? 0 : rdata.cpu[2][i - 1]).toFixed(1); + if (i % 2 != 0) { + cpuText += 'CPU-' + i + ':' + cpuUse + '% | '; + } else { + cpuText += 'CPU-' + i + ':' + cpuUse + '%'; + cpuText += '\n'; + } } } layer.tips(rdata.cpu[3] + "
" + rdata.cpu[5] + "个物理CPU," + (rdata.cpu[4]) + "个物理核心," + rdata.cpu[1] + "个逻辑核心
" + cpuText, this, { time: 0, tips: [1, '#999'] }); @@ -109,6 +109,7 @@ function rocket(sum, m) { var n = sum - m; $(".mem-release").find(".mask span").text(n); } + //释放内存 function reMemory() { setTimeout(function() { @@ -281,8 +282,8 @@ function getNet() { var up, down; $.get("/system/network", function(net) { $("#InterfaceSpeed").html(lan.index.interfacespeed + ": 1.0Gbps"); - $("#upSpeed").html(net.up + ' KB'); - $("#downSpeed").html(net.down + ' KB'); + $("#upSpeed").html(toSize(net.up)); + $("#downSpeed").html(toSize(net.down)); $("#downAll").html(toSize(net.downTotal)); $("#downAll").attr('title', lan.index.package + ':' + net.downPackets) $("#upAll").html(toSize(net.upTotal)); @@ -303,7 +304,7 @@ function getNet() { //网络Io function netImg() { - var myChartNetwork = echarts.init(document.getElementById('netImg')); + var echartsNetImg = echarts.init(document.getElementById('netImg')); var xData = []; var yData = []; var zData = []; @@ -333,10 +334,27 @@ function netImg() { return ts(h) + ':' + ts(mm) + ':' + ts(s); } + var default_unit = 'KB/s'; function addData(shift) { xData.push(getTime()); - yData.push(getCookie("upNet")); - zData.push(getCookie("downNet")); + + if (getCookie("upNet") > getCookie("downNet") ){ + tmp = getCookie("upNet"); + } else { + tmp = getCookie("downNet"); + } + var tmpSize = toSize(tmp); + default_unit = tmpSize.split(' ')[1]; + + + var upNetTmp = toSize(getCookie("upNet")); + var downNetTmp = toSize(getCookie("downNet")); + + var upNetTmpSize = upNetTmp.split(' ')[0]; + var downNetTmp = downNetTmp.split(' ')[0] + + yData.push(upNetTmpSize); + zData.push(downNetTmp); if (shift) { xData.shift(); yData.shift(); @@ -379,7 +397,7 @@ function netImg() { } }, yAxis: { - name: lan.index.unit + 'KB/s', + name: '单位 '+ default_unit, splitLine: { lineStyle: { color: "#eee" @@ -392,7 +410,7 @@ function netImg() { } }, series: [{ - name: lan.index.net_up, + name: '上行', type: 'line', data: yData, smooth: true, @@ -420,8 +438,9 @@ function netImg() { width: 1 } } - }, { - name: lan.index.net_down, + }, + { + name: '下行', type: 'line', data: zData, smooth: true, @@ -432,21 +451,21 @@ function netImg() { normal: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, - color: 'rgba(30, 144, 255,0.5)' + color: 'rgba(30, 144, 255,0.5)', }, { offset: 1, - color: 'rgba(30, 144, 255,0.8)' + color: 'rgba(30, 144, 255,0.8)', }], false) } }, itemStyle: { normal: { - color: '#52a9ff' + color: '#52a9ff', } }, lineStyle: { normal: { - width: 1 + width: 1, } } }] @@ -454,7 +473,7 @@ function netImg() { setInterval(function() { getNet(); addData(true); - myChartNetwork.setOption({ + echartsNetImg.setOption({ xAxis: { data: xData }, @@ -467,10 +486,11 @@ function netImg() { }] }); }, 3000); + // 使用刚指定的配置项和数据显示图表。 - myChartNetwork.setOption(option); + echartsNetImg.setOption(option); window.addEventListener("resize", function() { - myChartNetwork.resize(); + echartsNetImg.resize(); }); } diff --git a/route/static/app/public.js b/route/static/app/public.js index 909c02d35..75bb3f489 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -12,7 +12,7 @@ function toSize(a) { if(a < e) { return(b == 0 ? a : a.toFixed(2)) + d[b] } - a /= e + a /= e; } }