From cbe0eca3c4d99cf8f5517beab103bdd66d0f4a27 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sat, 11 Sep 2021 01:44:07 +0900 Subject: monitoring: Add inode monitoring procedure. --- tojo-tokyo/monitoring.scm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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)) ... -- cgit v1.2.3