autocore: add cpu usage for x86

This commit is contained in:
coolsnowwolf 2020-02-16 00:14:40 +08:00
parent 8419c9376d
commit e652b67597
3 changed files with 23 additions and 1 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=autocore
PKG_VERSION:=1
PKG_RELEASE:=26
PKG_RELEASE:=27
include $(INCLUDE_DIR)/package.mk

View File

@ -51,8 +51,19 @@
local eth_info = luci.sys.exec("ethinfo")
local user_info = tonumber(luci.sys.exec("cat /proc/net/arp | grep '0x2' | wc -l")) or 0
local cpu_usage
if fs.readfile("/tmp/cpuusage") then
cpu_usage = luci.sys.exec("cat /tmp/cpuusage")
else
cpu_usage = "6.6%"
end
luci.sys.exec("/sbin/getcpu &")
local rv = {
cpuusage = cpu_usage,
cpuinfo = cpu_info,
ethinfo = eth_info,
userinfo = user_info,
@ -660,6 +671,9 @@
if (e = document.getElementById('cpuinfo'))
e.innerHTML = info.cpuinfo;
if (e = document.getElementById('cpuusage'))
e.innerHTML = info.cpuusage;
if (e = document.getElementById('loadavg'))
e.innerHTML = String.format(
@ -717,6 +731,7 @@
<tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
<tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
<tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
<tr><td width="33%"><%:CPU Usage%></td><td id="cpuusage">-</td></tr>
</table>
</fieldset>

View File

@ -0,0 +1,7 @@
#!/bin/sh
AT=$(cat /proc/stat | grep "^cpu " | awk '{print $2+$3+$4+$5+$6+$7+$8 " " $2+$3+$4+$7+$8}')
sleep 3
BT=$(cat /proc/stat | grep "^cpu " | awk '{print $2+$3+$4+$5+$6+$7+$8 " " $2+$3+$4+$7+$8}')
printf "%.01f%%" $(echo $AT $BT | awk '{print (($4-$2)/($3-$1))*100}') >/tmp/cpuusage