aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tojo-tokyo/monitoring.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/tojo-tokyo/monitoring.scm b/tojo-tokyo/monitoring.scm
index b46f0a2..4f8ecf7 100644
--- a/tojo-tokyo/monitoring.scm
+++ b/tojo-tokyo/monitoring.scm
@@ -55,6 +55,31 @@
(string=? (substring fs 0 5) "/dev/"))))
(df))))
+(define (df-i)
+ (let ((port (open-input-pipe "df -i")))
+ (get-line port)
+ (let f ((line (get-line port)))
+ (cond ((eof-object? line)
+ (close-pipe port)
+ '())
+ (else
+ (cons (map cons
+ '(filesystem inodes iused ifree iuse% mounted-on)
+ (map match:substring (list-matches "[^ ]+" line)))
+ (f (get-line port))))))))
+
+(define-public (disk-iuse%-over? threshold)
+ (any (lambda (x)
+ (let ((iuse% (string->number (string-delete #\% (assoc-ref x 'iuse%)))))
+ (and iuse%
+ (< threshold iuse%))))
+ (filter (lambda (x)
+ (let ((fs (assoc-ref x 'filesystem)))
+ (and fs
+ (<= 5 (string-length fs))
+ (string=? (substring fs 0 5) "/dev/"))))
+ (df-i))))
+
(define-syntax-rule (heartbeat (p? body ...) ...)
(let ((heartbeat-cancel? #f))
(when p? body ... (set! heartbeat-cancel? #t)) ...