cpu
This commit is contained in:
parent
0cd13113b4
commit
13e0935ce0
1
Makefile
1
Makefile
@ -51,6 +51,7 @@ define Package/autocore/install/Default
|
||||
$(CP) ./files/generic/luci-mod-status-autocore.json $(1)/usr/share/rpcd/acl.d/
|
||||
|
||||
$(INSTALL_DIR) $(1)/www/luci-static/resources/view/status/include
|
||||
$(INSTALL_DATA) ./files/generic/19_cpu.js $(1)/www/luci-static/resources/view/status/include/
|
||||
$(INSTALL_DATA) ./files/generic/29_ethinfo.js $(1)/www/luci-static/resources/view/status/include/
|
||||
endef
|
||||
|
||||
|
45
files/generic/19_cpu.js
Normal file
45
files/generic/19_cpu.js
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
'require rpc';
|
||||
|
||||
var callCPUFreeInfo = rpc.declare({
|
||||
object: 'luci',
|
||||
method: 'getCPUUsage'
|
||||
});
|
||||
|
||||
function progressbar(value, max) {
|
||||
var vn = parseInt(value) || 0,
|
||||
mn = parseInt(max) || 100,
|
||||
pc = Math.floor((100 / mn) * vn);
|
||||
|
||||
return E('div', {
|
||||
'class': 'cbi-progressbar',
|
||||
'title': '%s%% / %s%%'.format(vn, mn, pc)
|
||||
}, E('div', { 'style': 'width:%.2f%%'.format(pc) }));
|
||||
}
|
||||
|
||||
return L.Class.extend({
|
||||
title: _('CPU'),
|
||||
|
||||
load: function() {
|
||||
return L.resolveDefault(callCPUFreeInfo(), {});
|
||||
},
|
||||
|
||||
render: function(info) {
|
||||
var fields = [
|
||||
_('Used'), (info.cpuusage) ? info.cpuusage : 0, 100
|
||||
];
|
||||
|
||||
var table = E('div', { 'class': 'table cpu' });
|
||||
|
||||
for (var i = 0; i < fields.length; i += 3) {
|
||||
table.appendChild(E('div', { 'class': 'tr' }, [
|
||||
E('div', { 'class': 'td left', 'width': '33%' }, [ fields[i] ]),
|
||||
E('div', { 'class': 'td left' }, [
|
||||
(fields[i + 1] != null) ? progressbar(fields[i + 1], fields[i + 2], true) : '?'
|
||||
])
|
||||
]));
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
});
|
@ -650,7 +650,7 @@ local methods = {
|
||||
local sys = require "luci.sys"
|
||||
local cpuusage = {}
|
||||
|
||||
cpuusage.cpuusage = sys.exec("busybox top -n1 | awk '/^CPU/ {printf(\"%d%%\", 100 - $8)}'") or "6%"
|
||||
cpuusage.cpuusage = sys.exec("busybox top -n1 | awk '/^CPU/ {printf(\"%d%\", 100 - $8)}'") or "6%"
|
||||
return cpuusage
|
||||
end
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user