refactor: add SystemStats singleton + nova-stats daemon for cpu/mem polling
This commit is contained in:
parent
71a843e0f3
commit
136ff53cb5
13 changed files with 371 additions and 196 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import "." as M
|
||||
|
||||
M.BarSection {
|
||||
|
|
@ -7,45 +6,12 @@ M.BarSection {
|
|||
spacing: Math.max(1, M.Theme.moduleSpacing - 2)
|
||||
tooltip: ""
|
||||
|
||||
property int percent: 0
|
||||
property real usedGb: 0
|
||||
property real totalGb: 0
|
||||
property real availGb: 0
|
||||
property real cachedGb: 0
|
||||
property real buffersGb: 0
|
||||
|
||||
FileView {
|
||||
id: meminfo
|
||||
path: "/proc/meminfo"
|
||||
onLoaded: {
|
||||
const m = {};
|
||||
text().split("\n").forEach(l => {
|
||||
const [k, v] = l.split(":");
|
||||
if (v)
|
||||
m[k.trim()] = parseInt(v.trim());
|
||||
});
|
||||
const total = m.MemTotal || 0;
|
||||
const avail = m.MemAvailable || 0;
|
||||
const buffers = m.Buffers || 0;
|
||||
const cached = (m.Cached || 0) + (m.SReclaimable || 0);
|
||||
const used = total - avail;
|
||||
if (total > 0) {
|
||||
root.percent = Math.round(used / total * 100);
|
||||
root.usedGb = used / 1048576;
|
||||
root.totalGb = total / 1048576;
|
||||
root.availGb = avail / 1048576;
|
||||
root.cachedGb = cached / 1048576;
|
||||
root.buffersGb = buffers / 1048576;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: M.Modules.memory.interval || 2000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: meminfo.reload()
|
||||
}
|
||||
property int percent: M.SystemStats.memPercent
|
||||
property real usedGb: M.SystemStats.memUsedGb
|
||||
property real totalGb: M.SystemStats.memTotalGb
|
||||
property real availGb: M.SystemStats.memAvailGb
|
||||
property real cachedGb: M.SystemStats.memCachedGb
|
||||
property real buffersGb: M.SystemStats.memBuffersGb
|
||||
|
||||
function _fmt(gb) {
|
||||
return gb >= 10 ? gb.toFixed(1) + "G" : gb.toFixed(2) + "G";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue