From 75d8f786a6347babe05472b16f80d2d883a41294 Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Fri, 7 Aug 2020 13:23:45 +0800 Subject: [PATCH] add article: add cpu info to openwrt status page --- package.json | 2 +- .../Add-CPU-info-to-OpenWrt-status-page.md | 88 +++++++++++++++++++ themes/next/_config.yml | 4 +- 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 source/_posts/Add-CPU-info-to-OpenWrt-status-page.md diff --git a/package.json b/package.json index 2a6643f..18be5d9 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "hexo": { - "version": "3.8.0" + "version": "3.9.0" }, "dependencies": { "hexo": "^3.8.0", diff --git a/source/_posts/Add-CPU-info-to-OpenWrt-status-page.md b/source/_posts/Add-CPU-info-to-OpenWrt-status-page.md new file mode 100644 index 0000000..99a1270 --- /dev/null +++ b/source/_posts/Add-CPU-info-to-OpenWrt-status-page.md @@ -0,0 +1,88 @@ +--- +title: OpenWrt 19.07.2 状态页面增加 CPU 信息显示 +date: 2020-08-07 12:29:15 +tags: +--- +{% blockquote 引用文章 https://www.popyone.com/post/30.html OPENWRT_x86(19.07.3)界面添加cpu温度和使用率 %} +{% endblockquote %} +--- +安装软件包:`lm-sensors`、`lm-sensors-detect` + +修改 `/usr/libexec/rpcd/luci` 文件,添加一个 `ubus` 的 `method`: +
+            return { result = args.localtime }
+        end
+    },
+
+    getCPUInfo = {
+        call = function()
+            local sys = require "luci.sys"
+            local rv = {}
+            rv.cpufreq = sys.exec("grep 'MHz' /proc/cpuinfo | cut -c11- | sed -n '1p' | tr -d '\n'")
+            rv.cputemp = sys.exec("sensors | grep Core | awk '{print $1,$2,$3}' | tr '\n' ' '")
+            return rv
+        end
+    },
+
+    getTimezones = {
+
+ + + +修改 `/usr/share/rpcd/acl.d/luci-base.json` ,给刚刚添加的 `getCPUInfo` 添加权限: + +
+    "ubus": {
+        "file": [ "list", "read", "stat" ],
+        "iwinfo": [ "assoclist", "freqlist", "txpowerlist", "countrylist" ],
+        "luci": [ "getConntrackList", "getInitList", "getLocaltime", "getProcessList", "getRealtimeStats", "getTimezones", "getLEDs", "getUSBDevices", "getSwconfigFeatures", "getSwconfigPortState", "getBlockDevices", "getMountPoints", "getCPUInfo" ],
+        "luci-rpc": [ "getBoardJSON", "getDHCPLeases", "getDSLStatus", "getDUIDHints", "getHostHints",  "getNetworkDevices", "getWirelessDevices" ],
+
+ +修改 `/www/luci-static/resources/view/status/include/10_system.js` + +
+    var callSystemInfo = rpc.declare({
+        object: 'system',
+        method: 'info'
+    });
+    var callCPUInfo = rpc.declare({
+        object: 'luci',
+        method: 'getCPUInfo'
+    });
+    return baseclass.extend({
+        title: _('System'),
+        load: function() {
+            return Promise.all([
+                L.resolveDefault(callSystemBoard(), {}),
+                L.resolveDefault(callSystemInfo(), {}),
+                L.resolveDefault(callCPUInfo(), {}),
+                fs.lines('/usr/lib/lua/luci/version.lua')
+            ]);
+        },
+        render: function(data) {
+            var boardinfo   = data[0],
+                systeminfo  = data[1],
+                cpuinfo     = data[2],
+                luciversion = data[3];
+...
+            var fields = [
+                _('Hostname'),         boardinfo.hostname,
+                _('Model'),            boardinfo.model,
+                _('Architecture'),     boardinfo.system,
+                _('Firmware Version'), (L.isObject(boardinfo.release) ? boardinfo.release.description + ' / ' : '') + (luciversion || ''),
+                _('Kernel Version'),   boardinfo.kernel,
+                _('Local Time'),       datestr,
+                _('Uptime'),           systeminfo.uptime ? '%t'.format(systeminfo.uptime) : null,
+                _('CPU Info'),         cpuinfo.cpufreq + ' MHz / ' + cpuinfo.cputemp,
+                _('Load Average'),     Array.isArray(systeminfo.load) ? '%.2f, %.2f, %.2f'.format(
+                    systeminfo.load[0] / 65535.0,
+                    systeminfo.load[1] / 65535.0,
+                    systeminfo.load[2] / 65535.0
+                ) : null
+            ];
+
+ +使用命令 `/etc/init.d/rpcd restart` 重启 `rpcd` 服务,最后清除浏览器页面缓存。 + +PS:可使用 `ubus call luci getCPUInfo` 检查执行是否有异常。 \ No newline at end of file diff --git a/themes/next/_config.yml b/themes/next/_config.yml index f07f8e9..a3ca480 100644 --- a/themes/next/_config.yml +++ b/themes/next/_config.yml @@ -480,8 +480,8 @@ font: # Font settings for and code blocks. codes: external: true - family: - size: + family: 'SF Mono' + size: 13 # ---------------------------------------------------------------