恩山无线论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 16004|回复: 110

OpenWRT 19.06.7 最新官方固件添加CPU频率,温度,接口速率,磁盘使用信息

  [复制链接]
发表于 2021-1-24 21:45 | 显示全部楼层 |阅读模式
本帖最后由 a798047000 于 2021-2-1 13:10 编辑

修改 /usr/libexec/rpcd/luci 添加如下代码
  1. getCoreInfo = {
  2.         call = function()
  3.             local sys = require "luci.sys"
  4.             local rv = {}

  5.             local freqs = string.split(string.trim(sys.exec("cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq")),"\n")
  6.             local temps = string.split(string.trim(sys.exec("sensors | grep 'Core' | cut -c10-24")),"\n")

  7.             local i
  8.             for i = 1, #freqs do
  9.                 local freq = string.trim(freqs[i])
  10.                 local temp = string.trim(temps[i])
  11.                 rv[#rv + 1] = {
  12.                     core = "Core " .. i,
  13.                     freq = string.format("%.2f", freq / 1000) .. " MHz",
  14.                     temp = temp
  15.                 }
  16.             end

  17.             return {coreinfo = rv}
  18.         end
  19.     },

  20.     getDiskInfo = {
  21.         call = function()
  22.             local sys = require "luci.sys"
  23.             local rv = {}

  24.             local lines = string.split(string.trim(sys.exec("/bin/df -h | sed 's/\\s\\+/ /g' | uniq")),"\n")

  25.             local i
  26.             for i = 2, #lines do
  27.                 local tokens = string.split(lines[i], " ")
  28.                 local block = string.trim(tokens[1])
  29.                 -- ignore block not start with /
  30.                 if (string.sub(block, 1, 1) == "/") then
  31.                     rv[#rv + 1] = {
  32.                         block = block,
  33.                         size = string.trim(tokens[2]),
  34.                         used = string.trim(tokens[3]),
  35.                         available = string.trim(tokens[4]),
  36.                         used_percent = string.trim(tokens[5]),
  37.                         mounte_point = string.trim(tokens[6])
  38.                     }
  39.                 end
  40.             end

  41.             return {diskinfo = rv}
  42.         end
  43.     },

  44.     getETHInfo = {
  45.         call = function()
  46.             local sys = require "luci.sys"
  47.             local rv = {}
  48.             local ethinfo = sys.exec("/usr/bin/ethinfo")
  49.             local lines = string.split(string.trim(ethinfo), "\n")
  50.             local i
  51.             for i = 1, #lines do
  52.                 local line = string.trim(lines[i])
  53.                 if line == "" then
  54.                 else
  55.                     local tokens
  56.                     tokens = string.split(line, " ")
  57.                     rv[#rv + 1] = {
  58.                         name = tokens[1],
  59.                         status = tokens[2],
  60.                         speed = tokens[3],
  61.                         duplex = tokens[4]
  62.                     }
  63.                 end
  64.             end
  65.             return {ethinfo = rv}
  66.         end
  67.     }
复制代码



安装 lm-sensors 执行命令
  1. opkg update
  2. opkg install lm-sensors
复制代码

添加文件 /usr/bin/ethinfo 写入

  1. #!/bin/sh
  2. a=$(ip address | grep ^[0-9] | awk -F: '{print $2}' | sed "s/ //g" | grep '^[e]' | grep -v "@" | grep -v "\.")
  3. b=$(echo "$a" | wc -l)

  4. for i in $(seq 1 $b)
  5. do
  6.         c=$(echo "$a" | sed -n ${i}p)
  7.         d=$(ethtool $c)
  8.         e=$(echo "$d" | grep "Link detected" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
  9.         f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!")
  10.         [ -z "$f" ] && f="-"
  11.         g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
  12.         [ "$g" != "Full" -a "$g" != "Half" ] && g="-"
  13.         echo "$c $e $f $g"
  14. done
复制代码

并给执行权限,执行

  1. chmod 755 /usr/bin/ethinfo
复制代码

修改 /usr/share/rpcd/acl.d/luci-base.json 找到

  1. "luci": [ "getConntrackList", "getInitList", "getLocaltime", "getProcessList", "getRealtimeStats", "getTimezones", "getLEDs", "getUSBDevices", "getSwconfigFeatures", "getSwconfigPortState", "getBlockDevices", "getMountPoints" ],
复制代码

添加 "getCoreInfo", "getETHInfo", "getDiskInfo" 改完后是这样的

  1. "luci": [ "getConntrackList", "getInitList", "getLocaltime", "getProcessList", "getRealtimeStats", "getTimezones", "getLEDs", "getUSBDevices", "getSwconfigFeatures", "getSwconfigPortState", "getBlockDevices", "getMountPoints", "getCoreInfo", "getETHInfo", "getDiskInfo" ],
复制代码

然后将压缩包内的3个文件放入 /www/luci-static/resources/view/status/include/

include.zip (1.88 KB, 下载次数: 238)

最后别忘了重启 rpcd 和 uhttpd (或nginx,如果你用nginx替代了uhttpd的话) 服务

  1. service rpcd restart
  2. service uhttpd restart
复制代码


最终效果如图

QQ20210124-214454@2x.png


以上方案是直接修改系统文件实现的,没有改源码重新编译,如果想要在源码内修改,可以找到源码下相应的路径和文件,修改即可

由于我这里是直接修改系统文件的,因此没有国际化(翻译),中文文本是直接以unicode编码写到js文件里的

如果需要加入源码编译,建议将对应文本改为英文,然后在po文件内添加相应的翻译文本即可

此帖部分代码来自于 https://www.right.com.cn/forum/thread-1358471-1-1.html  感谢!

多说一句,如果更新了luci-base包,可能会导致修改失效,这主要是因为更新的包覆盖了修改后的文件,这时一般只需要重新在rpc中添加lua方法,然后再json中注册,重启rpcd,就能重新work。如果不行,那就对照教程完整的再来一次吧。

为了帮助有同样需求的小伙伴,版主帮忙推荐高亮一下,谢谢~~
















评分

参与人数 6恩山币 +9 收起 理由
wxt7327 + 1 补充,记的要安装ethtool,否则不会显示网.
1538304461 + 1 一看就是觉得高端、大气、上档次!
99010 + 3 风清云淡、飘逸悠然……极爽!
hong0980 + 2 图片选的好,高手少不了!
18907514643 + 1 恩山全体路由党向你学习!
67942 + 1 不要怂、就是干!

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-2-19 13:53 | 显示全部楼层
a798047000 发表于 2021-2-19 11:01
你加我qq吧,我帮你看看,798047000

谢谢,是我大意了,复制下面代码时,最后一行没有“,” 加上“,”就正常了   getETHInfo = {
        call = function()
            local sys = require "luci.sys"
            local rv = {}
            local ethinfo = sys.exec("/usr/bin/ethinfo")
            local lines = string.split(string.trim(ethinfo), "\n")
            local i
            for i = 1, #lines do
                local line = string.trim(lines)
                if line == "" then
                else
                    local tokens
                    tokens = string.split(line, " ")
                    rv[#rv + 1] = {
                        name = tokens[1],
                        status = tokens[2],
                        speed = tokens[3],
                        duplex = tokens[4]
                    }
                end
            end
            return {ethinfo = rv}
        end
    }
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-2-1 15:49 | 显示全部楼层
BootROM - 1.73
Booting from NAND flash

General initialization - Version: 1.0.0
AVS selection from EFUSE disabled (Skip reading EFUSE values)
mvSysEnvIsFlavourReduced: TWSI Read of 'flavor' failed
Detected Device ID 6820
High speed PHY - Version: 2.0

Init RD NAS topology Serdes Lane 3 is USB3
Serdes Lane 4 is SGMII
board SerDes lanes topology details:
| Lane # | Speed|    Type     |
------------------------------|
|   0    |  6   |  SATA0      |
|   1    |  5   |  PCIe0      |
|   2    |  6   |  SATA1      |
|   3    |  5   |  USB3 HOST1 |
|   4    |  5   |  PCIe1      |
|   5    |  0   |  SGMII2     |
-------------------------------
:** Link is Gen1, check the EP capability
PCIe, Idx 0: Link upgraded to Gen2 based on client cpabilities
:** Link is Gen1, check the EP capability
PCIe, Idx 1: remains Gen1
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver TIP-1.46.0
mvSysEnvGetTopologyUpdateInfo: TWSI Read failed
DDR3 Training Sequence - Switching XBAR Window to FastPath Window
DDR3 Training Sequence - Ended Successfully
Not detected suspend to RAM indication
BootROM: Image checksum verification PASSED


U-Boot 2013.01 (May 18 2017 - 16:37:44) Marvell version: 2015_T1.QA.0p16

Boot version : v2.0.9

Board: RD-NAS-88F6820-DDR3
SoC:   MV88F6820 Rev A0
       running 2 CPUs
CPU:   ARM Cortex A9 MPCore (Rev 1) LE
       CPU 0
       CPU    @ 1866 [MHz]
       L2     @ 933 [MHz]
       TClock @ 200 [MHz]
       DDR3    @ 933 [MHz]
       DDR3 32 Bit Width,FastPath Memory Access, DLB Enabled, ECC Disabled
DRAM:  512 MiB
NAND:  256 MiB
MMC:   mv_sdh: 0
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2021-2-1 13:11 | 显示全部楼层
aximpda 发表于 2021-1-29 19:35
我已经改了一下再用的机器。很不完美,主要是Linksys 的机器问题
cat /proc/cpuinfo 和sensors只能得到这 ...

我找了个安卓手机试了下,arm设备上获取cpu当前频率的方法更新了,现在应该可以兼容你的设备了。至于温度的话,不太清楚了,手上没有其它arm设备可以测试

  1.         getCoreInfo = {
  2.         call = function()
  3.             local sys = require "luci.sys"
  4.             local rv = {}

  5.             local freqs = string.split(string.trim(sys.exec("cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq")),"\n")
  6.             local temps = string.split(string.trim(sys.exec("sensors | grep 'Core' | cut -c10-24")),"\n")

  7.             local i
  8.             for i = 1, #freqs do
  9.                 local freq = string.trim(freqs[i])
  10.                 local temp = string.trim(temps[i])
  11.                 rv[#rv + 1] = {
  12.                     core = "Core " .. i,
  13.                     freq = string.format("%.2f", freq / 1000) .. " MHz",
  14.                     temp = temp
  15.                 }
  16.             end

  17.             return {coreinfo = rv}
  18.         end
  19.     },
复制代码

我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2021-1-24 21:47 | 显示全部楼层
沙发自己坐吧
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-24 21:52 来自手机 | 显示全部楼层
谢谢了!!!
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-25 03:29 来自手机 | 显示全部楼层
支持一下。
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-25 07:18 | 显示全部楼层
帮顶一下
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-25 08:20 | 显示全部楼层
支持支持支持
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-25 09:06 | 显示全部楼层
我的是官方master的版本,本来也想改成你这种(还有像接口信息那种,把图标换成cpu的),但考虑到有4核4线程也有4核8线程的CPU就不准了,结果就成了这样,看看哪个好,多核心的就是显示栏太长会辣眼睛
11.png
333.png

点评

你这个也挺好的,很简洁!赞~  详情 回复 发表于 2021-1-25 09:31
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-25 09:21 | 显示全部楼层
支持一下。
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2021-1-25 09:31 | 显示全部楼层
401626436 发表于 2021-1-25 09:06
我的是官方master的版本,本来也想改成你这种(还有像接口信息那种,把图标换成cpu的),但考虑到有4核4线程 ...

你这个也挺好的,很简洁!赞~

点评

牛啊。 可以请教一下你这个图标是怎么做到的吗?  详情 回复 发表于 2021-1-28 21:18
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-26 21:24 | 显示全部楼层
谢谢了!!!
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-28 21:18 | 显示全部楼层
a798047000 发表于 2021-1-25 09:31
你这个也挺好的,很简洁!赞~

牛啊。
可以请教一下你这个图标是怎么做到的吗?
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-28 21:29 | 显示全部楼层
谢谢了!!!
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-28 22:35 | 显示全部楼层
非常感谢!@
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-29 06:57 | 显示全部楼层
谢谢了!!!
我的恩山、我的无线 The best wifi forum is right here.
发表于 2021-1-29 17:00 | 显示全部楼层
谢谢这个贴,学习中
我的恩山、我的无线 The best wifi forum is right here.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛上一条 /1 下一条

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )|网站地图

GMT+8, 2023-3-26 07:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377@jschina.com.cn 举报电话:025-88802724 | 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797
快速回复 返回顶部 返回列表