refactor: move items from (radix utils memory) to more general module (radix system monitoring)

pull/1/head
anemofilia 2023-09-05 12:11:42 -03:00
parent 7b0fcc8543
commit b34de78f5e
No known key found for this signature in database
GPG Key ID: 5A8F3D62C87A2B33
1 changed files with 14 additions and 2 deletions

View File

@ -1,10 +1,13 @@
(define-module (radix utils memory) (define-module (radix utils monitoring)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:export (current-memory-info #:export (current-memory-info
current-ram-usage current-ram-usage
current-swap-usage)) current-swap-usage
current-battery-capacity))
#|memory usage monitoring utilities|#
(define (current-memory-info) (define (current-memory-info)
(let* ((port (open "/proc/meminfo" O_RDONLY)) (let* ((port (open "/proc/meminfo" O_RDONLY))
(lines (let loop ((line (read-line port)) (lines (let loop ((line (read-line port))
@ -33,3 +36,12 @@
(define (current-swap-usage) (define (current-swap-usage)
(apply - (map (cut assoc-ref (current-memory-info) <>) (apply - (map (cut assoc-ref (current-memory-info) <>)
'("SwapTotal" "SwapFree")))) '("SwapTotal" "SwapFree"))))
#|battery usage monitoring utilities|#
(define (current-battery-capacity)
(let* ((port (open "/sys/class/power_supply/BAT0/capacity"
O_RDONLY))
(battery-level (read port)))
(close-input-port port)
battery-level))