我们使用OpenWRT时发现很多第三方固件都带有CPU使用率,而我们编译官方OpenWRT时就没有这些,只有一些负载信息。研究了下,现在官方OpenWRT是采用js来渲染页面,直接在html页面中修改不可行。要修改的话需要授予前端 RPC 权限,后端实现获取 CPU 使用率的逻辑并向 RPC 返回。修改起来代码较多,好在ImmortalWrt开源仓库提供了修改的版本,我们只需覆盖官方OpenWRT三个文件即可实现OpenWRT主页显示CPU使用率。

这三个文件是:
immortalwrt/feeds/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js
immortalwrt/feeds/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json
只要拷贝这三个文件并覆盖官方OpenWRT同位置文件,编译出来即可带有CPU使用率。需要带有温度信息、Cpu信息、等还需编译 immortalwrt/package/emortal/autocore 这个应用,只要把这个文件夹放到官方OpenWRT的 openwrt/package/ 里面,make menuconfig 时选上该autocore应用。
全命令操作就是:
git clone https://github.com/immortalwrt/immortalwrt cd immortalwrt ./scripts/feeds update -a && ./scripts/feeds install -a cd mkdir openwrt/package/immortal cp -arf immortalwrt/package/emortal/autocore/ openwrt/package/immortal/ # 使得luci界面显示频率及cpu使用率 cd cp -f immortalwrt/feeds/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci openwrt/feeds/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci cp -f immortalwrt/feeds/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js openwrt/feeds/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js cp -f immortalwrt/feeds/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json openwrt/feeds/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json
已经安装的Openwrt路由器可以WinSCP对下面路径的文件进行替换。
/usr/share/rpcd/ucode/luci
/usr/share/rpcd/acl.d/luci-mod-status.json
替换完成后需要重启路由器,或者命令重启
/etc/init.d/rpcd restart /etc/init.d/uhttpd restart
另外,我们使用Esxi 或其他虚拟平台时,Openwrt型号会显示 Vmware Inc. 等相关字样,我们想要个性化型号,X86 Openwrt源码中可以进行这样处理:
# 请将CUSTOM PRODUCT 改为自己想要的型号 sed -i -E 's|echo\s+"?\$vendor\s+\$product"?\s*>.*|echo "CUSTOM PRODUCT" > /tmp/sysinfo/model|' openwrt/target/linux/x86/base-files/lib/preinit/01_sysinfo
也就是替换自动获取型号的代码 echo "$vendor $product" > /tmp/sysinfo/model ,改为自定义型号。
已经安装的Openwrt,X86可以到 /lib/preinit/01_sysinfo 里进行修改,非X86设备是由 /lib/preinit/02_sysinfo 获取的型号。
技术不断升级,请注意文章时效性。
本站文章,欢迎转发。转载请注明出处:https://www.bandwh.com/net/2423.html

评论列表(2条)
作者大大,貌似现在失效了,无法显示CPU使用率了直接显示?号。
太感谢你了,难怪为什么官方openwrt系统界面概况没有cpu温度信息和使用率。