cpu tips 优化

gogs 统计优化
pull/199/head
midoks 3 years ago
parent 38f8fe9a38
commit b314ebeed3
  1. 15
      class/core/mw.py
  2. 19
      class/core/system_api.py
  3. 7
      plugins/gogs/index.py
  4. 37
      route/static/app/index.js
  5. 2
      route/templates/default/index.html

@ -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

@ -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):
# 取内存信息

@ -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()

@ -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 + '%&nbsp;|&nbsp;'
} else {
cpuText += 'CPU-' + i + ':' + cpuUse + '%'
cpuText += '\n'
}
}
layer.tips(rdata.cpu[3] + "</br>" + rdata.cpu[5] + "个物理CPU," + (rdata.cpu[4]) + "个物理核心," + rdata.cpu[1] + "个逻辑核心</br>" + 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);

@ -38,7 +38,7 @@
</div>
<h4 id="LoadState" class="c5 f15">获取中...</h4>
</li>
<li class="col-xs-6 col-sm-3 col-md-3 col-lg-2 mtb20 circle-box text-center">
<li class="col-xs-6 col-sm-3 col-md-3 col-lg-2 mtb20 circle-box text-center" id="cpuChart">
<h3 class="c5 f15">CPU使用率</h3>
<div class="circle">
<div class="pie_left">

Loading…
Cancel
Save