aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2021-09-11 01:44:07 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2021-09-11 01:44:07 +0900
commitcbe0eca3c4d99cf8f5517beab103bdd66d0f4a27 (patch)
treec43ddfa6f9fecd68ce60ced4ae5ae9003196fe55
parentaefb1d36a95b7f42441cb1a7a657596d17825cbe (diff)
monitoring: Add inode monitoring procedure.
-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)) ...