aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/modules/stats.py
diff options
context:
space:
mode:
Diffstat (limited to 'deckit/modules/stats.py')
-rw-r--r--deckit/modules/stats.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/deckit/modules/stats.py b/deckit/modules/stats.py
index a60605e..947b334 100644
--- a/deckit/modules/stats.py
+++ b/deckit/modules/stats.py
@@ -14,17 +14,20 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""System stats: CPU, memory, GPU (Intel xe), network, uptime.
+"""System stats: CPU, memory, GPU (Intel xe), network, uptime, pending updates.
The Arc driver exposes temperature and fan through hwmon and no VRAM capacity;
VRAM in use comes from the DRM fdinfo scan, as quickshell's perf panel does.
"""
+import json
+import os
import platform
import re
import shlex
import socket
import subprocess
+import threading
import time
from pathlib import Path
@@ -148,8 +151,31 @@ def _net_iface(hw):
return None
+def _to_install(doc):
+ """updatesctl's JSON -> what keystone's tile counts "to install"."""
+ sw = doc.get("slackware", {})
+ return sum(len(sw.get(k, [])) for k in ("upgrade", "new", "removed")) + len(doc.get("upgrade", []))
+
+
def make(cfg: dict) -> Module:
hw = cfg.get("hardware", {})
+ updatesctl = os.path.expanduser(cfg.get("dashboard", {}).get("updates", ""))
+ upd = {"n": None, "t": 0, "busy": False}
+
+ def read_updates():
+ try:
+ out = subprocess.run([updatesctl], capture_output=True, text=True, timeout=30).stdout
+ upd["n"] = _to_install(json.loads(out))
+ except (OSError, subprocess.TimeoutExpired, ValueError):
+ pass
+ upd.update(t=time.monotonic(), busy=False)
+
+ def updates():
+ # ponytail: re-read every 5 min in a thread, so the NAS reads never stall the 1 s poll
+ if updatesctl and not upd["busy"] and (not upd["t"] or time.monotonic() - upd["t"] > 300):
+ upd["busy"] = True
+ threading.Thread(target=read_updates, daemon=True).start()
+ return upd["n"]
cpu_sensor = _cpu_sensor(hw)
battery = _battery(hw)
gpu = _gpu(hw)
@@ -218,6 +244,7 @@ def make(cfg: dict) -> Module:
"battery": {"level": int(_read(battery / "capacity", "0")), "status": _read(battery / "status")}
if battery else None,
"net": {"down": down, "up": up},
+ "updates": updates(),
}
return Module(name="stats", title="System", state=state)