disk.lisp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (in-package :stumpwm)
  2. (defun disk-free (target &key remote (standby ""))
  3. (let* ((standby?
  4. (if (string= standby "")
  5. nil
  6. (string= (car
  7. (last (split-string
  8. (string-trim
  9. '(#\Newline)
  10. (run-shell-command (format nil "sudo hdparm -C ~a" standby) t))
  11. '(#\space))))
  12. "standby")))
  13. (size (if standby?
  14. "standby"
  15. (fourth (split-string (second (split-string (run-shell-command (if remote
  16. (format nil "ssh ~a -- df -h ~a" remote target)
  17. (format nil "df -h ~a" target))
  18. t)
  19. '(#\newline)))
  20. '(#\space))))))
  21. (cond ((uiop/utility:string-suffix-p size "G")
  22. (format nil "~a GB" (delete #\G size)))
  23. ((uiop/utility:string-suffix-p size "M")
  24. (format nil "~a MB" (delete #\M size)))
  25. ((uiop/utility:string-suffix-p size "T")
  26. (format nil "~a TB" (delete #\T size)))
  27. ((string= "standby" size)
  28. "standby")
  29. (t size))))
  30. (defvar *disk-free-root-counter* 0)
  31. (defcommand disk-free-root-update-counter () ()
  32. (setq *disk-free-root-counter* (disk-free "/")))
  33. (defvar *disk-free-srv-counter* 0)
  34. (defcommand disk-free-srv-update-counter () ()
  35. (setq *disk-free-srv-counter*
  36. (disk-free "/srv" :standby "/dev/disk/by-label/data18")))
  37. (defun mountpoint-free? (mountpoint &optional (use-percent 80))
  38. (< use-percent
  39. (parse-integer
  40. (string-trim '(#\Newline)
  41. (run-shell-command
  42. (format nil "df ~a | jc --df | jq '.[] | .use_percent'"
  43. mountpoint)
  44. t)))))