diff --git a/class/core/mw.py b/class/core/mw.py index c4cb1d603..1711b0d22 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -714,13 +714,24 @@ def getStrBetween(startStr, endStr, srcStr): def getCpuType(): + cpuType = '' + if isAppleSystem(): + cmd = "system_profiler SPHardwareDataType | grep 'Processor Name' | awk -F ':' '{print $2}'" + cpuinfo = execShell(cmd) + return cpuinfo[0].strip() + # 取CPU类型 cpuinfo = open('/proc/cpuinfo', 'r').read() rep = "model\s+name\s+:\s+(.+)" - tmp = re.search(rep, cpuinfo) - cpuType = None + tmp = re.search(rep, cpuinfo, re.I) if tmp: cpuType = tmp.groups()[0] + else: + cpuinfo = execShell('LANG="en_US.UTF-8" && lscpu')[0] + rep = "Model\s+name:\s+(.+)" + tmp = re.search(rep, cpuinfo, re.I) + if tmp: + cpuType = tmp.groups()[0] return cpuType diff --git a/class/core/system_api.py b/class/core/system_api.py index f176642be..80c493048 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -162,7 +162,7 @@ class system_api: except: port = mw.readFile('data/port.pl') except: - port = '8888' + port = '7200' domain = '' if os.path.exists('data/domain.conf'): domain = mw.readFile('data/domain.conf') @@ -201,9 +201,9 @@ class system_api: def getLoadAverage(self): c = os.getloadavg() data = {} - data['one'] = float(c[0]) - data['five'] = float(c[1]) - data['fifteen'] = float(c[2]) + data['one'] = round(float(c[0]), 2) + data['five'] = round(float(c[1]), 2) + data['fifteen'] = round(float(c[2]), 2) data['max'] = psutil.cpu_count() * 2 data['limit'] = data['max'] data['safe'] = data['max'] * 0.75 @@ -276,8 +276,17 @@ class system_api: def getCpuInfo(self, interval=1): # 取CPU信息 cpuCount = psutil.cpu_count() + cpuLogicalNum = psutil.cpu_count(logical=False) used = psutil.cpu_percent(interval=interval) - return used, cpuCount + + if os.path.exists('/proc/cpuinfo'): + c_tmp = public.readFile('/proc/cpuinfo') + d_tmp = re.findall("physical id.+", c_tmp) + cpuLogicalNum = len(set(d_tmp)) + + used_all = psutil.cpu_percent(percpu=True) + cpu_name = mw.getCpuType() + " * {}".format(cpuLogicalNum) + return used, cpuCount, used_all, cpu_name, cpuCount, cpuLogicalNum def getMemInfo(self): # 取内存信息 diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index 898514477..e494d29e0 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -681,12 +681,7 @@ def getTotalStatistics(): data = {} if st.strip() == 'start': list_count = pQuery('select count(id) as num from repository') - - if list_count.find("error") > -1: - data['status'] = False - data['count'] = 0 - return mw.returnJson(False, 'fail', data) - + count = list_count[0]["num"] data['status'] = True data['count'] = count data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip() diff --git a/route/static/app/index.js b/route/static/app/index.js index 50140ad5f..d14e1cf90 100755 --- a/route/static/app/index.js +++ b/route/static/app/index.js @@ -65,6 +65,7 @@ function getLoad(data) { $('#LoadList .circle').click(function() { getNet(); }); + $('#LoadList .mask').hover(function() { var one, five, fifteen; var that = this; @@ -78,6 +79,25 @@ $('#LoadList .mask').hover(function() { }); +function showCpuTips(rdata){ + $('#cpuChart .mask').hover(function() { + var cpuText = ''; + 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' + } + } + layer.tips(rdata.cpu[3] + "
" + rdata.cpu[5] + "个物理CPU," + (rdata.cpu[4]) + "个物理核心," + rdata.cpu[1] + "个逻辑核心
" + cpuText, this, { time: 0, tips: [1, '#999'] }); + }, function() { + layer.closeAll('tips'); + }); +} + + function rocket(sum, m) { var n = sum - m; $(".mem-release").find(".mask span").text(n); @@ -249,9 +269,11 @@ function setcolor(pre, s, s1, s2, s3) { co.parent('.circle').css("background", LoadColor); } + + + function getNet() { - var up; - var down; + var up, down; $.get("/system/network", function(net) { $("#InterfaceSpeed").html(lan.index.interfacespeed + ": 1.0Gbps"); $("#upSpeed").html(net.up + ' KB'); @@ -269,6 +291,8 @@ function getNet() { // setMemImg(net.mem); setImg(); + + showCpuTips(net); },'json'); } @@ -478,16 +502,7 @@ setTimeout(function() { $('#toUpdate a').css("position","relative"); return; } - // $.get('/system?action=ReWeb', function() {}); - // layer.msg(rdata.msg, { icon: 1 }); - // setTimeout(function() { - // window.location.reload(); - // }, 3000); },'json').error(function() { - // $.get('/system?action=ReWeb', function() {}); - // setTimeout(function() { - // window.location.reload(); - // }, 3000); }); }, 3000); diff --git a/route/templates/default/index.html b/route/templates/default/index.html index 6b8b4b3bf..9146b09a7 100755 --- a/route/templates/default/index.html +++ b/route/templates/default/index.html @@ -38,7 +38,7 @@

获取中...

-
  • +
  • CPU使用率