generated from P3TERX/Actions-OpenWrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
luci-status-patch.patch
224 lines (215 loc) · 7.08 KB
/
luci-status-patch.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
diff -ur feeds/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci luci-index-patch/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci
--- feeds/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci 2024-05-06 14:00:12.988595207 +0000
+++ luci-index-patch/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci 2024-05-06 14:00:22.460851679 +0000
@@ -581,7 +581,111 @@
return { result: ports };
}
- }
+ },
+
+ getCPUUsage: {
+ call: function() {
+ const fd = popen('top -n1 | grep -E -i cpu -m1 | grep -oE \'[0-9.%]+ \'| sed -n \'4p\' | sed \'s/%//\'');
+ if (fd) {
+ let cpuusage = fd.read('all');
+ if (cpuusage === ''){
+ cpuusage = '??';
+ }else{
+ cpuusage = 100 - cpuusage;
+ }
+ fd.close();
+
+ return { cpuusage: cpuusage + '%' };
+ } else {
+ return { cpuusage: 'error' };
+ }
+ }
+ },
+
+ getTempInfo: {
+ call: function() {
+ //return {tempinfo: '20℃'};
+
+ let fd = popen('command -v sensors >/dev/null && sensors 2>/dev/null | grep -i -A10 \'^coretemp\' | grep -i -m1 \'^package\' | grep -oE \'[+-][0-9]+\' | head -n 1 ');
+
+ if (fd){
+ let tempinfo = fd.read('all');
+ if (tempinfo !== ''){
+ tempinfo = tempinfo + '℃'
+ };
+ fd.close();
+ return { tempinfo: tempinfo };
+
+ } else {
+ return { tempinfo: 'error' };
+ }
+
+ }
+ },
+
+ getFanSpeed: {
+ call: function() {
+ //return { fanspeed: '1686' };
+
+ let fd = popen('command -v sensors >/dev/null && sensors 2>/dev/null | grep -ioE \':[[:space:]]+[1-9][0-9]* RPM \' | grep -Eo \'[0-9]+\' | awk \'{printf $0 ","}\' | sed -E \'s|,$||\' ');
+
+ if (fd){
+ let fanspeed = fd.read('all');
+ fd.close();
+ return { fanspeed: fanspeed };
+
+ } else {
+ return { fanspeed: 'error' };
+ }
+
+ }
+ },
+
+ getCpuFreq: {
+ call: function() {
+ let fd = popen('cat /proc/cpuinfo | grep -i mhz | grep -Eo \'[0-9.]+\' | awk -F . \'{printf("%.1f ",$1/1000)}\'');
+ if (fd){
+ let cpufreq = fd.read('all');
+ if (cpufreq === '') {
+ fd.close();
+
+ fd = popen('cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq | awk -F . \'{printf("%.1f ",$1/1000000)}\'');
+ cpufreq = fd.read('all');
+ fd.close();
+ } else {
+ fd.close();
+ }
+
+ return { cpufreq: cpufreq };
+ } else {
+ return { cpufreq: 'error' };
+ }
+
+ }
+ },
+
+ getOnlineUsers: {
+ call: function() {
+ // let fd = popen('cat /proc/net/arp | grep 0x2 | wc -l');
+ // let fd = popen('cat /proc/net/arp | grep 0x2 | grep -F $(ubus call network.interface.lan status | grep \'"device"\' | sed -E \'s/.+"([^"]+).+/\1/\') | wc -l');
+ let fd = popen('cat /proc/net/arp | grep 0x2 | grep -F $(uci get network.lan.device) | wc -l');
+ if (fd){
+ let onlineusers = fd.read('all');
+ fd.close();
+
+ return { onlineusers: onlineusers };
+ } else {
+
+ return { onlineusers: 'error' };
+ }
+ }
+ },
+
+ getCPUBench: {
+ call: function() {
+ return { cpubench: readfile('/etc/.coremarkscore') || '' };
+ }
+ },
};
return { luci: methods };
diff -ur feeds/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js luci-index-patch/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js
--- feeds/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js 2024-05-06 14:00:12.992595314 +0000
+++ luci-index-patch/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js 2024-05-06 14:00:22.456851568 +0000
@@ -18,6 +18,36 @@
method: 'info'
});
+var callCPUUsage = rpc.declare({
+ object: 'luci',
+ method: 'getCPUUsage'
+});
+
+var callTempInfo = rpc.declare({
+ object: 'luci',
+ method: 'getTempInfo'
+});
+
+var callFanSpeed = rpc.declare({
+ object: 'luci',
+ method: 'getFanSpeed'
+});
+
+var callCpuFreq = rpc.declare({
+ object: 'luci',
+ method: 'getCpuFreq'
+});
+
+var callOnlineUsers = rpc.declare({
+ object: 'luci',
+ method: 'getOnlineUsers'
+});
+
+var callCPUBench = rpc.declare({
+ object: 'luci',
+ method: 'getCPUBench'
+});
+
return baseclass.extend({
title: _('System'),
@@ -25,14 +55,26 @@
return Promise.all([
L.resolveDefault(callSystemBoard(), {}),
L.resolveDefault(callSystemInfo(), {}),
- L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' })
+ L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' }),
+ L.resolveDefault(callCPUUsage(), {}),
+ L.resolveDefault(callTempInfo(), {}),
+ L.resolveDefault(callCpuFreq(), {}),
+ L.resolveDefault(callOnlineUsers(), {}),
+ L.resolveDefault(callCPUBench(), {}),
+ L.resolveDefault(callFanSpeed(), {}),
]);
},
render: function(data) {
var boardinfo = data[0],
systeminfo = data[1],
- luciversion = data[2];
+ luciversion = data[2],
+ cpuusage = data[3],
+ tempinfo = data[4],
+ cpufreq = data[5],
+ onlineusers = data[6],
+ cpubench = data[7],
+ fanspeed = data[8];
luciversion = luciversion.branch + ' ' + luciversion.revision;
@@ -53,18 +95,23 @@
var fields = [
_('Hostname'), boardinfo.hostname,
- _('Model'), boardinfo.model,
+ _('Model'), boardinfo.model + cpubench.cpubench,
_('Architecture'), boardinfo.system,
_('Target Platform'), (L.isObject(boardinfo.release) ? boardinfo.release.target : ''),
_('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,
+ _('Uptime'), (systeminfo.uptime ? '%t'.format(systeminfo.uptime) : null) + ' | 在线设备: ' + onlineusers.onlineusers,
_('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
+ ) : null,
+ _('CPU'), cpuusage.cpuusage +
+ ( ! /^$|^error$/i.test(tempinfo.tempinfo) ? ( ' | 温度: ' + tempinfo.tempinfo ) : '' ) +
+ ( ! /^$|^error$/i.test(fanspeed.fanspeed) ? ( ' | 风扇: ' + fanspeed.fanspeed ) : '' ) +
+ ' | 频率: ' + cpufreq.cpufreq,
+
];
var table = E('table', { 'class': 'table' });
diff -ur feeds/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json luci-index-patch/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json
--- feeds/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json 2024-05-06 14:00:12.996595422 +0000
+++ luci-index-patch/luci/modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json 2024-05-06 14:00:22.452851462 +0000
@@ -3,7 +3,7 @@
"description": "Grant access to realtime statistics",
"read": {
"ubus": {
- "luci": [ "getConntrackList", "getRealtimeStats" ],
+ "luci": [ "getConntrackList", "getRealtimeStats" , "getCPUUsage", "getTempInfo", "getFanSpeed", "getCpuFreq", "getOnlineUsers", "getCPUBench" ],
"network.rrdns": [ "lookup" ]
}
}