system: monitoring: Add a procedure to get the total available ram in the current system in bytes

sioyek
Luis Guilherme Coelho 2024-02-12 02:01:12 -03:00
parent 57c0fc0644
commit ae7793bd65
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
1 changed files with 8 additions and 0 deletions

View File

@ -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"))))