0.2.0: card Memoria toccabile con dettaglio RAM per servizio/container
This commit is contained in:
1 parent
99aba8fa03
commit
714c4d5189
8 files changed
+237
-10
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
# harbour-server
|
# harbour-server
|
||||||
|
|
||||||
App **Sailfish OS** che mostra i parametri di un server Linux in **una sola
|
App **Sailfish OS** che mostra i parametri di un server Linux in **una sola
|
||||||
schermata**: CPU, memoria (RAM e swap), disco, container, backup, servizi in
|
schermata**: CPU, memoria (RAM e swap), disco, container, backup, UPS, servizi
|
||||||
errore, tentativi SSH, aggiornamenti e stato VPN.
|
in errore, tentativi SSH, aggiornamenti e stato VPN.
|
||||||
|
|
||||||
Sola lettura. Nessuna credenziale di sistema: legge un endpoint JSON
|
Sola lettura. Nessuna credenziale di sistema: legge un endpoint JSON
|
||||||
documentato, quindi funziona con qualunque host che parli lo stesso formato.
|
documentato, quindi funziona con qualunque host che parli lo stesso formato.
|
||||||
@@ -20,7 +20,13 @@ client non deve assumere la presenza di un campo.
|
|||||||
|
|
||||||
Card impilate con valore, dettaglio e barra; soglie: verde, giallo all'85%,
|
Card impilate con valore, dettaglio e barra; soglie: verde, giallo all'85%,
|
||||||
rosso al 95%. Pull-to-refresh, aggiornamento automatico ogni 60 s, copertina
|
rosso al 95%. Pull-to-refresh, aggiornamento automatico ogni 60 s, copertina
|
||||||
con la percentuale di CPU, badge rosso sulle card fuori soglia.
|
con CPU/RAM/disco in percentuale, badge rosso sulle card fuori soglia.
|
||||||
|
|
||||||
|
La card **Memoria** è toccabile (chevron a destra) e apre il dettaglio dei
|
||||||
|
consumatori di RAM ordinati dal più grande. Con `/proc` montato `hidepid=invisible`
|
||||||
|
il singolo PID degli altri utenti non è leggibile senza root: l'unità è quindi
|
||||||
|
il **servizio o il contenitore** (memoria anonima dei cgroup v2), che è la stessa
|
||||||
|
grandezza mostrata dalla card.
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
@@ -34,7 +40,7 @@ Requisiti: SDK Sailfish in `~/SailfishOS`, build engine Docker.
|
|||||||
## Installazione sul telefono
|
## Installazione sul telefono
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
devel-su rpm -Uvh harbour-server-0.1.6-1.aarch64.rpm
|
devel-su rpm -Uvh harbour-server-0.2.0-1.aarch64.rpm
|
||||||
```
|
```
|
||||||
|
|
||||||
Poi, all'apertura: indicare indirizzo (es. `http://192.168.3.21:8792`) e token.
|
Poi, all'apertura: indicare indirizzo (es. `http://192.168.3.21:8792`) e token.
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ Rectangle {
|
|||||||
property string detail
|
property string detail
|
||||||
property real progress: -1
|
property real progress: -1
|
||||||
property int level: 0
|
property int level: 0
|
||||||
|
// Una card toccabile mostra il chevron e porta a una pagina di dettaglio.
|
||||||
|
property bool interactive: false
|
||||||
|
|
||||||
|
signal clicked()
|
||||||
|
|
||||||
function levelColor() {
|
function levelColor() {
|
||||||
if (level === 2) return "#e53935"
|
if (level === 2) return "#e53935"
|
||||||
@@ -38,7 +42,7 @@ Rectangle {
|
|||||||
text: card.title
|
text: card.title
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Theme.secondaryColor
|
color: Theme.secondaryColor
|
||||||
width: parent.width * 0.55
|
width: parent.width * (card.interactive ? 0.50 : 0.55)
|
||||||
truncationMode: TruncationMode.Fade
|
truncationMode: TruncationMode.Fade
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +51,18 @@ Rectangle {
|
|||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: card.level === 0 ? Theme.primaryColor : card.levelColor()
|
color: card.level === 0 ? Theme.primaryColor : card.levelColor()
|
||||||
horizontalAlignment: Text.AlignRight
|
horizontalAlignment: Text.AlignRight
|
||||||
width: parent.width * 0.45
|
width: parent.width * (card.interactive ? 0.40 : 0.45)
|
||||||
truncationMode: TruncationMode.Fade
|
truncationMode: TruncationMode.Fade
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
visible: card.interactive
|
||||||
|
text: "›"
|
||||||
|
width: parent.width * 0.10
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
|
color: Theme.secondaryColor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
@@ -76,4 +89,10 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
enabled: card.interactive
|
||||||
|
onClicked: card.clicked()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import QtQuick 2.0
|
||||||
|
import Sailfish.Silica 1.0
|
||||||
|
|
||||||
|
// Dettaglio della card Memoria: chi occupa la RAM, dal più grande.
|
||||||
|
// La fonte è la memoria ANONIMA dei cgroup: con hidepid=invisible i processi
|
||||||
|
// degli altri utenti non sono leggibili da /proc, quindi l'unità di misura è
|
||||||
|
// il servizio o il contenitore, non il singolo PID.
|
||||||
|
Page {
|
||||||
|
id: page
|
||||||
|
allowedOrientations: Orientation.All
|
||||||
|
|
||||||
|
function list() {
|
||||||
|
var d = statusClient.data
|
||||||
|
if (!d || !d.memory || !d.memory.consumers) return []
|
||||||
|
return d.memory.consumers
|
||||||
|
}
|
||||||
|
function totalBytes() {
|
||||||
|
var d = statusClient.data
|
||||||
|
return (d && d.memory && d.memory.total_bytes) ? d.memory.total_bytes : 0
|
||||||
|
}
|
||||||
|
function maxBytes() {
|
||||||
|
var l = list()
|
||||||
|
return (l.length > 0 && l[0].bytes > 0) ? l[0].bytes : 1
|
||||||
|
}
|
||||||
|
function sharePct(bytes) {
|
||||||
|
var t = totalBytes()
|
||||||
|
return t > 0 ? bytes / t * 100 : 0
|
||||||
|
}
|
||||||
|
function usedText() {
|
||||||
|
var d = statusClient.data
|
||||||
|
if (!d || !d.memory) return ""
|
||||||
|
return qsTr("usata ") + statusClient.fmtNum(d.memory.percent, 0) + "% · "
|
||||||
|
+ qsTr("su ") + statusClient.fmtBytes(d.memory.total_bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
SilicaListView {
|
||||||
|
id: view
|
||||||
|
anchors.fill: parent
|
||||||
|
model: page.list()
|
||||||
|
|
||||||
|
header: Column {
|
||||||
|
width: view.width
|
||||||
|
spacing: Theme.paddingSmall
|
||||||
|
|
||||||
|
PageHeader { title: qsTr("Memoria") }
|
||||||
|
|
||||||
|
Label {
|
||||||
|
x: Theme.paddingLarge
|
||||||
|
width: parent.width - 2 * Theme.paddingLarge
|
||||||
|
text: page.usedText()
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.secondaryColor
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
x: Theme.paddingLarge
|
||||||
|
width: parent.width - 2 * Theme.paddingLarge
|
||||||
|
text: qsTr("Memoria anonima per servizio e contenitore, ordinata dal più grande.")
|
||||||
|
font.pixelSize: Theme.fontSizeExtraSmall
|
||||||
|
color: Theme.secondaryColor
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { width: 1; height: Theme.paddingSmall }
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: Column {
|
||||||
|
x: Theme.paddingLarge
|
||||||
|
width: view.width - 2 * Theme.paddingLarge
|
||||||
|
spacing: Theme.paddingSmall / 2
|
||||||
|
|
||||||
|
Row {
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: modelData.name + (modelData.kind === "container" ? qsTr(" · contenitore") : "")
|
||||||
|
width: parent.width * 0.50
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
truncationMode: TruncationMode.Fade
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: statusClient.fmtBytes(modelData.bytes)
|
||||||
|
width: parent.width * 0.32
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.highlightColor
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: statusClient.fmtNum(page.sharePct(modelData.bytes), 1) + "%"
|
||||||
|
width: parent.width * 0.18
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
font.pixelSize: Theme.fontSizeExtraSmall
|
||||||
|
color: Theme.secondaryColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Barra relativa al primo della lista: serve a confrontare le
|
||||||
|
// grandezze fra loro, mentre la percentuale è sul totale della RAM.
|
||||||
|
Rectangle {
|
||||||
|
width: parent.width * Math.max(2, Math.min(100, modelData.bytes / page.maxBytes() * 100)) / 100
|
||||||
|
height: 3
|
||||||
|
radius: 1.5
|
||||||
|
color: Theme.rgba(Theme.highlightColor, 0.5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
footer: Item {
|
||||||
|
width: view.width
|
||||||
|
height: Theme.paddingLarge * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewPlaceholder {
|
||||||
|
enabled: page.list().length === 0
|
||||||
|
text: qsTr("Nessun dato")
|
||||||
|
hintText: qsTr("Lo snapshot del server non è ancora arrivato")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -225,6 +225,8 @@ Page {
|
|||||||
detail: memText() + " · swap " + statusClient.fmtNum(swapPercent(), 0) + " %"
|
detail: memText() + " · swap " + statusClient.fmtNum(swapPercent(), 0) + " %"
|
||||||
progress: memPercent()
|
progress: memPercent()
|
||||||
level: Math.max(levelFor(memPercent(), 85, 95), levelFor(swapPercent(), 80, 95))
|
level: Math.max(levelFor(memPercent(), 85, 95), levelFor(swapPercent(), 80, 95))
|
||||||
|
interactive: true
|
||||||
|
onClicked: pageStack.push(Qt.resolvedUrl("ProcessPage.qml"))
|
||||||
}
|
}
|
||||||
|
|
||||||
MetricCard {
|
MetricCard {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Name: harbour-server
|
Name: harbour-server
|
||||||
Summary: Parametri del server in una schermata
|
Summary: Parametri del server in una schermata
|
||||||
Version: 0.1.6
|
Version: 0.2.0
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: Qt/Qt
|
Group: Qt/Qt
|
||||||
License: MIT
|
License: MIT
|
||||||
@@ -23,6 +23,12 @@ schermata sola. Il formato consumato (schema status/1) non dipende dalla
|
|||||||
macchina: qualunque host che serva lo stesso JSON funziona senza modifiche.
|
macchina: qualunque host che serva lo stesso JSON funziona senza modifiche.
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sat Oct 31 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.2.0-1
|
||||||
|
- Card Memoria toccabile: apre ProcessPage con i consumatori di RAM ordinati
|
||||||
|
dal più grande (MB, % sul totale, barra comparativa)
|
||||||
|
- Collector: nuova chiave memory.consumers, memoria anonima per cgroup con i
|
||||||
|
discendenti sottratti; con hidepid=invisible l'unità è il servizio o il
|
||||||
|
contenitore, non il PID
|
||||||
* Sat Oct 31 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.1.6-1
|
* Sat Oct 31 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.1.6-1
|
||||||
- Card UPS: sotto il 10% di carico si legge "carico basso" invece di una
|
- Card UPS: sotto il 10% di carico si legge "carico basso" invece di una
|
||||||
percentuale: questi firmware (MEC0003/Qx) riportano il carico a passi del
|
percentuale: questi firmware (MEC0003/Qx) riportano il carico a passi del
|
||||||
|
|||||||
+3
-1
@@ -80,7 +80,9 @@ Nessun log HTTP: il token non finisce su disco. Il server non ha altre rotte.
|
|||||||
"boot_time": "…", "load": [0.3, 0.57, 0.48] },
|
"boot_time": "…", "load": [0.3, 0.57, 0.48] },
|
||||||
"cpu": { "percent": 7.1, "temp_c": 41.0, "cores": 4 },
|
"cpu": { "percent": 7.1, "temp_c": 41.0, "cores": 4 },
|
||||||
"memory": { "total_bytes": 0, "used_bytes": 0, "percent": 0,
|
"memory": { "total_bytes": 0, "used_bytes": 0, "percent": 0,
|
||||||
"swap_total_bytes": 0, "swap_used_bytes": 0 },
|
"swap_total_bytes": 0, "swap_used_bytes": 0,
|
||||||
|
"consumers": [ { "name": "hermes-webui", "kind": "service",
|
||||||
|
"bytes": 693108736 } ] },
|
||||||
"disks": [ { "mount": "/", "used_bytes": 0, "total_bytes": 0, "percent": 0 } ],
|
"disks": [ { "mount": "/", "used_bytes": 0, "total_bytes": 0, "percent": 0 } ],
|
||||||
"containers": { "running": [ { "name": "…", "status": "Up 2 days", "ok": true } ],
|
"containers": { "running": [ { "name": "…", "status": "Up 2 days", "ok": true } ],
|
||||||
"available": true },
|
"available": true },
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ DEFAULT_PORT = 8792
|
|||||||
# riavvii. Creato con una riga di root, vedi README.
|
# riavvii. Creato con una riga di root, vedi README.
|
||||||
BORG_MARKER = "/var/lib/borg-last-run"
|
BORG_MARKER = "/var/lib/borg-last-run"
|
||||||
|
|
||||||
|
CGROUP_ROOT = Path("/sys/fs/cgroup")
|
||||||
|
|
||||||
|
|
||||||
# ── helper ────────────────────────────────────────────────────────────────
|
# ── helper ────────────────────────────────────────────────────────────────
|
||||||
def run(cmd: list[str], timeout: float = 4.0) -> str:
|
def run(cmd: list[str], timeout: float = 4.0) -> str:
|
||||||
@@ -95,6 +97,75 @@ def cpu_info(sample: float = 0.1) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _cgroup_anon(path: Path) -> int | None:
|
||||||
|
"""Memoria anonima (heap, stack: RAM vera) di un cgroup, in byte."""
|
||||||
|
try:
|
||||||
|
with open(path / "memory.stat") as fh:
|
||||||
|
for line in fh:
|
||||||
|
if line.startswith("anon "):
|
||||||
|
return int(line.split()[1])
|
||||||
|
except OSError:
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def memory_consumers(limit: int = 12, min_mb: int = 16) -> list[dict]:
|
||||||
|
"""Chi occupa la RAM, ordinato dal più grande.
|
||||||
|
|
||||||
|
/proc è montato con hidepid=invisible: i processi degli altri utenti sono
|
||||||
|
invisibili, quindi il dettaglio per PID non è ottenibile senza root. I
|
||||||
|
cgroup v2 invece sono leggibili e danno la memoria anonima per unità o
|
||||||
|
contenitore. Sottraggo i discendenti, altrimenti un genitore conterebbe
|
||||||
|
anche i figli e la somma sballerebbe.
|
||||||
|
"""
|
||||||
|
anon: dict[str, int] = {}
|
||||||
|
stack = [CGROUP_ROOT]
|
||||||
|
while stack:
|
||||||
|
path = stack.pop()
|
||||||
|
try:
|
||||||
|
stack.extend(p for p in path.iterdir() if p.is_dir())
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
value = _cgroup_anon(path)
|
||||||
|
if value:
|
||||||
|
anon[str(path)] = value
|
||||||
|
|
||||||
|
# system.slice/docker-<id>.scope -> nome del contenitore
|
||||||
|
docker_names = {}
|
||||||
|
for line in run(["docker", "ps", "--format", "{{.ID}} {{.Names}}"]).splitlines():
|
||||||
|
parts = line.split()
|
||||||
|
if len(parts) >= 2:
|
||||||
|
docker_names[parts[0]] = parts[1]
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
for path, value in anon.items():
|
||||||
|
children = sum(
|
||||||
|
v for p, v in anon.items() if p != path and p.startswith(path + "/")
|
||||||
|
)
|
||||||
|
exclusive = value - children
|
||||||
|
if exclusive < min_mb * 1024 * 1024:
|
||||||
|
continue
|
||||||
|
leaf = path.rsplit("/", 1)[-1]
|
||||||
|
kind = "service"
|
||||||
|
name = leaf
|
||||||
|
if leaf.startswith("docker-") and leaf.endswith(".scope"):
|
||||||
|
cid = leaf[len("docker-") : -len(".scope")]
|
||||||
|
name = docker_names.get(cid[:12], cid[:12])
|
||||||
|
kind = "container"
|
||||||
|
elif leaf.endswith(".service"):
|
||||||
|
name = leaf[: -len(".service")]
|
||||||
|
elif leaf.endswith(".scope"):
|
||||||
|
name = leaf[: -len(".scope")]
|
||||||
|
kind = "session"
|
||||||
|
elif leaf.endswith(".slice"):
|
||||||
|
name = leaf[: -len(".slice")]
|
||||||
|
kind = "slice"
|
||||||
|
rows.append({"name": name, "kind": kind, "bytes": exclusive})
|
||||||
|
|
||||||
|
rows.sort(key=lambda row: -row["bytes"])
|
||||||
|
return rows[:limit]
|
||||||
|
|
||||||
|
|
||||||
def memory_info() -> dict:
|
def memory_info() -> dict:
|
||||||
mem = {}
|
mem = {}
|
||||||
for line in Path("/proc/meminfo").read_text().splitlines():
|
for line in Path("/proc/meminfo").read_text().splitlines():
|
||||||
@@ -109,6 +180,7 @@ def memory_info() -> dict:
|
|||||||
"percent": pct(total - avail, total),
|
"percent": pct(total - avail, total),
|
||||||
"swap_total_bytes": swap_total,
|
"swap_total_bytes": swap_total,
|
||||||
"swap_used_bytes": swap_used,
|
"swap_used_bytes": swap_used,
|
||||||
|
"consumers": memory_consumers(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -15,9 +15,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
|||||||
// AppConfigLocation = ~/.config/harbour/server (zona persistente).
|
// AppConfigLocation = ~/.config/harbour/server (zona persistente).
|
||||||
app->setOrganizationName(QStringLiteral("harbour"));
|
app->setOrganizationName(QStringLiteral("harbour"));
|
||||||
app->setApplicationName(QStringLiteral("server"));
|
app->setApplicationName(QStringLiteral("server"));
|
||||||
app->setApplicationVersion(QStringLiteral("0.1.6"));
|
app->setApplicationVersion(QStringLiteral("0.2.0"));
|
||||||
|
|
||||||
qDebug() << "harbour-server v0.1.6 build" << __DATE__ << __TIME__;
|
qDebug() << "harbour-server v0.2.0 build" << __DATE__ << __TIME__;
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
StatusClient status(&settings);
|
StatusClient status(&settings);
|
||||||
|
|||||||
Reference in new issue
Block a user