Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(www): report system load average #455

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mtda/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EVENTS:
POWER = "POWER"
SESSION = "SESSION"
STORAGE = "STORAGE"
SYSTEM = "SYSTEM"


class IMAGE(Enum):
Expand Down
17 changes: 15 additions & 2 deletions mtda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1786,8 +1786,7 @@ def start(self):

if self.is_server is True:
from mtda.utils import RepeatTimer
handler = self.session_check
self._session_timer = RepeatTimer(10, handler)
self._session_timer = RepeatTimer(5, self._timer)
self._session_timer.start()

# Start from a known state
Expand Down Expand Up @@ -1901,3 +1900,17 @@ def _check_locked(self, session):

self.mtda.debug(3, f"main._check_locked: {result}")
return result

def _system_monitor(self):
loadavg = 0.0
with open('/proc/loadavg') as f:
stats = f.readline().split()
loadavg = stats[0]
self.notify(CONSTS.EVENTS.SYSTEM, f'{loadavg}')

def _timer(self):
# Check for inative sessions
self.session_check()

# System health checks
self._system_monitor()
31 changes: 31 additions & 0 deletions mtda/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
height: "340px",
hidden: true
});

sysWindow = new WinBox("System", {
html: "<canvas id='sysLoadCanvas' width='220' height='100'></canvas>",
class: ["no-full", "no-max", "modern"],
width: "250px",
height: "150px",
hidden: true
});
var sysLoadChart;
var sysLoadSeries = new TimeSeries();

xferWindow = new WinBox("Transferring", {
html: "<svg width='100' height='100' viewBox='0 0 100 100'>" +
"<circle cx='50' cy='50' r='40' stroke='#eee' stroke-width='8' fill='none'/>" +
Expand All @@ -127,6 +138,7 @@
});
var xferChart;
var xferSeries = new TimeSeries();

consoleWindow.focus()
</script>
<script src="./assets/jquery.min.js"></script>
Expand Down Expand Up @@ -270,6 +282,7 @@
case 'POWER': power_event(message); break;
case 'SESSION': ignore_message(message); break;
case 'STORAGE': storage_event(message); break;
case 'SYSTEM': system_event(message); break;
case 'console-output': console_output(message); break;
case 'mtda-version': mtda_version(message); break;
case 'session': session_set_id(message); break;
Expand Down Expand Up @@ -407,6 +420,24 @@
}
});

function system_event(data) {
data = data.event.split(" ");
let loadavg = data[0];

if (sysWindow.hidden) {
sysWindow.show();
sysLoadChart = new SmoothieChart({
millisPerPixel: 100,
maxValueScale: 1.2,
minValueScale: 1.2,
grid: { fillStyle: 'rgba(40, 40, 40, 0.2)', strokeStyle: 'rgba(90, 90, 90, 0.2)', verticalSections: 4 },
});
sysLoadChart.streamTo(document.getElementById("sysLoadCanvas"), 5000);
sysLoadChart.addTimeSeries(sysLoadSeries, { strokeStyle: 'rgb(0, 255, 0)', lineWidth: 2 });
}
sysLoadSeries.append(Date.now(), loadavg);
}

function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down