Fix cpu/memory stats widget

This commit is contained in:
Laura Hausmann 2023-07-23 12:14:33 +02:00
parent cae79a3383
commit 5639ba6863
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
4 changed files with 7 additions and 6 deletions

View file

@ -37,6 +37,7 @@ export default function () {
mem: {
used: round(memStats.used - memStats.buffers - memStats.cached),
active: round(memStats.active),
total: round(memStats.total),
},
net: {
rx: round(Math.max(0, netStats.rx_sec)),

View file

@ -84,8 +84,8 @@ const diskAvailable = $computed(() => meta.fs.total - meta.fs.used);
function onStats(stats) {
cpuUsage = stats.cpu;
memUsage = stats.mem.active / meta.mem.total;
memTotal = meta.mem.total;
memUsage = stats.mem.active / stats.mem.total;
memTotal = stats.mem.total;
memUsed = stats.mem.active;
memFree = memTotal - memUsed;

View file

@ -131,7 +131,7 @@ function onStats(connStats) {
]);
const memPolylinePointsStats = stats.map((s, i) => [
viewBoxX - (stats.length - 1 - i),
(1 - s.mem.active / props.meta.mem.total) * viewBoxY,
(1 - s.mem.active / s.mem.total) * viewBoxY,
]);
cpuPolylinePoints = cpuPolylinePointsStats
.map((xy) => `${xy[0]},${xy[1]}`)
@ -153,7 +153,7 @@ function onStats(connStats) {
memHeadY = memPolylinePointsStats[memPolylinePointsStats.length - 1][1];
cpuP = (connStats.cpu * 100).toFixed(0);
memP = ((connStats.mem.active / props.meta.mem.total) * 100).toFixed(0);
memP = ((connStats.mem.active / connStats.mem.total) * 100).toFixed(0);
}
function onStatsLog(statsLog) {

View file

@ -26,8 +26,8 @@ let usage: number = $ref(0),
free: number = $ref(0);
function onStats(stats) {
usage = stats.mem.active / props.meta.mem.total;
total = props.meta.mem.total;
usage = stats.mem.active / stats.mem.total;
total = stats.mem.total;
used = stats.mem.active;
free = total - used;
}