From ae7793bd655ecef353288e41982e3040adccb117 Mon Sep 17 00:00:00 2001 From: Luis Guilherme Coelho Date: Mon, 12 Feb 2024 02:01:12 -0300 Subject: [PATCH] system: monitoring: Add a procedure to get the total available ram in the current system in bytes --- modules/radix/system/monitoring.scm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/radix/system/monitoring.scm b/modules/radix/system/monitoring.scm index 787b8c6..b023788 100644 --- a/modules/radix/system/monitoring.scm +++ b/modules/radix/system/monitoring.scm @@ -4,6 +4,7 @@ #:export (current-memory-info current-ram-usage current-swap-usage + ram-total current-battery-capacity)) @@ -29,6 +30,13 @@ (cut string-split <> #\:)) lines))) +(define (ram-total) + (let* ((port (open "/proc/meminfo" O_RDONLY)) + (_ (read port)) + (mem-in-b (* (read port) 1024))) + (close-input-port port) + mem-in-b)) + (define (current-ram-usage) (apply - (map (cut assoc-ref (current-memory-info) <>) '("MemTotal" "MemFree" "Buffers" "Cached" "SReclaimable"))))