From b34de78f5ec3144077b110989cde02c72deff3f0 Mon Sep 17 00:00:00 2001 From: anemofilia Date: Tue, 5 Sep 2023 12:11:42 -0300 Subject: [PATCH] refactor: move items from (radix utils memory) to more general module (radix system monitoring) --- .../{utils/memory.scm => system/monitoring.scm} | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) rename modules/radix/{utils/memory.scm => system/monitoring.scm} (74%) mode change 100755 => 100644 diff --git a/modules/radix/utils/memory.scm b/modules/radix/system/monitoring.scm old mode 100755 new mode 100644 similarity index 74% rename from modules/radix/utils/memory.scm rename to modules/radix/system/monitoring.scm index c0c5361..a8e6d3e --- a/modules/radix/utils/memory.scm +++ b/modules/radix/system/monitoring.scm @@ -1,10 +1,13 @@ -(define-module (radix utils memory) +(define-module (radix utils monitoring) #:use-module (srfi srfi-26) #:use-module (ice-9 rdelim) #:export (current-memory-info current-ram-usage - current-swap-usage)) + current-swap-usage + current-battery-capacity)) + +#|memory usage monitoring utilities|# (define (current-memory-info) (let* ((port (open "/proc/meminfo" O_RDONLY)) (lines (let loop ((line (read-line port)) @@ -33,3 +36,12 @@ (define (current-swap-usage) (apply - (map (cut assoc-ref (current-memory-info) <>) '("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)) +