Skip to content

Commit 8bf05f2

Browse files
committed
show cpu usage
1 parent 192c9a2 commit 8bf05f2

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

addon_files/redmatic/www/js/script.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ $(document).ready(() => {
3131

3232
const $status = $('#node-red-status');
3333
const $memory = $('#node-red-memory');
34+
const $cpu = $('#node-red-cpu');
3435

3536
$alertSaved.hide();
3637
$alertError.hide();
@@ -56,10 +57,16 @@ $(document).ready(() => {
5657
let psTimeout;
5758
let psInterval = 5000;
5859

60+
function cpu() {
61+
$.get(`service.cgi?sid=${sid}&cmd=cpu`, (data, success) => {
62+
$cpu.html(data ? 'cpu ' + data : '');
63+
});
64+
}
65+
5966
function ps() {
6067
clearTimeout(psTimeout);
6168
$.get(`service.cgi?sid=${sid}&cmd=ps`, (data, success) => {
62-
console.log(data);
69+
cpu();
6370
const lines = data.split('\n');
6471
let found = false;
6572
lines.forEach(line => {
@@ -83,7 +90,7 @@ $(document).ready(() => {
8390
$linkRed.removeClass('disabled');
8491
$linkUi.removeClass('disabled');
8592
$start.addClass('disabled');
86-
psInterval = 10000;
93+
psInterval = 5000;
8794
return;
8895
}
8996
match = line.match(/([0-9]+[a-z]?)\s+([0-9]+[a-z]?)\s+.*red.js/);
@@ -117,7 +124,7 @@ $(document).ready(() => {
117124
$start.removeClass('disabled');
118125
$linkRed.addClass('disabled');
119126
$linkUi.addClass('disabled');
120-
psInterval = 10000;
127+
psInterval = 5000;
121128
}
122129
psTimeout = setTimeout(ps, psInterval);
123130
});
@@ -348,7 +355,7 @@ $(document).ready(() => {
348355
psInterval = 2000;
349356
setTimeout(() => {
350357
ps();
351-
}, 3000);
358+
}, 4000);
352359
alert($alertExec);
353360
} else {
354361
alert($alertError);

addon_files/redmatic/www/service.cgi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if {[info exists cmd]} {
2828
puts [exec ps -o vsz,rss,comm,args | grep node]
2929
exit 0
3030
}
31+
if {$cmd == "cpu"} {
32+
puts [exec top -b -n 1 | grep "% node-red$" | tr -s " " | cut -d " " -f7]
33+
exit 0
34+
}
3135
}
3236

3337
puts {error: invalid command}

addon_files/redmatic/www/settings.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<div style="vertical-align: middle; display: inline-block; width: 148px; font-size: 11px; color: grey;" class="">
5959
<div>Node-RED: <span id="node-red-status" style="font-weight: bold;"></span></div>
6060
<div><span id="node-red-memory" style="font-weight: bold;"></span>&nbsp;</div>
61+
<div><span id="node-red-cpu" style="font-weight: bold;"></span>&nbsp;</div>
6162
</div>
6263
</div>
6364
</div>

0 commit comments

Comments
 (0)