nicer graphs

This commit is contained in:
2026-08-11 19:10:05 +02:00
parent 8ebf939e81
commit 7fe7bb02fb
3 changed files with 48 additions and 15 deletions
+8 -2
View File
@@ -14,7 +14,7 @@ import time
DEFAULT_CONFIG = "/opt/cheap_system_monitor/monitor.conf"
DS_NAMES = (
"load1", "load5", "load15", "cpu_user", "cpu_system", "cpu_nice",
"net_in", "net_out", "disk_root", "disk_1", "disk_2", "memory",
"net_in", "net_out", "disk_root", "disk_1", "disk_2", "memory", "uptime",
)
@@ -49,6 +49,7 @@ def create_rrd(path: Path) -> None:
"DS:net_in:DERIVE:180:0:U", "DS:net_out:DERIVE:180:0:U",
"DS:disk_root:GAUGE:180:0:100", "DS:disk_1:GAUGE:180:0:100",
"DS:disk_2:GAUGE:180:0:100", "DS:memory:GAUGE:180:0:100",
"DS:uptime:GAUGE:180:0:U",
]
# 1-minute data for a day, 5-minute data for two weeks, hourly for a year.
archives = [
@@ -91,6 +92,11 @@ def memory_percent() -> float:
return 100.0 * (total - available) / total
def uptime_days() -> float:
seconds = float(Path("/proc/uptime").read_text().split()[0])
return seconds / 86400.0
def disk_percent(mountpoint: str) -> float:
stats = os.statvfs(mountpoint)
used = stats.f_blocks - stats.f_bfree
@@ -124,7 +130,7 @@ def collect(config: configparser.SectionProxy) -> list[float | int | str]:
raise SystemExit("At most three mountpoints are supported (including /)")
disks: list[float | str] = [disk_percent(item) for item in mounts]
disks.extend(["U"] * (3 - len(disks)))
return [*load, *cpu, *net, *disks, memory_percent()]
return [*load, *cpu, *net, *disks, memory_percent(), uptime_days()]
def main() -> None: