summaryrefslogtreecommitdiff
path: root/lib/byteback/disk_free.rb
diff options
context:
space:
mode:
authorMatthew Bloch <matthew@bytemark.co.uk>2014-10-31 02:43:35 +0000
committerMatthew Bloch <matthew@bytemark.co.uk>2014-10-31 02:43:35 +0000
commit1238c74fa01c009d7f76327f3beb30fee4b9f98f (patch)
tree2e0e0abde1b35f03ef515acc9ebd57f638af1c25 /lib/byteback/disk_free.rb
parentf23c6c91e2e2a8eb4154ec545199a5ecbe5136a1 (diff)
Refactored to improve logging and reduce cut & paste code, bumped Debian version number.
Diffstat (limited to 'lib/byteback/disk_free.rb')
-rwxr-xr-xlib/byteback/disk_free.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/byteback/disk_free.rb b/lib/byteback/disk_free.rb
new file mode 100755
index 0000000..33952a3
--- /dev/null
+++ b/lib/byteback/disk_free.rb
@@ -0,0 +1,41 @@
+
+module Byteback
+ # Icky way to find out free disc space on our mount
+ #
+ class DiskFree
+ def initialize(mount)
+ @mount = mount
+ end
+
+ def total
+ all[2]
+ end
+
+ def used
+ all[3]
+ end
+
+ def available
+ all[4]
+ end
+
+ def fraction_used
+ disk_device, disk_fs, disk_total, disk_used, disk_available, *rest = all
+ disk_used.to_f / disk_available
+ end
+
+ protected
+
+ def all
+ disk_device, disk_fs, disk_total, disk_used, disk_available, *rest =
+ df.
+ split("\n")[1].
+ split(/\s+/).
+ map { |i| /^[0-9]+$/.match(i) ? i.to_i : i }
+ end
+
+ def df
+ `/bin/df -T -P -B1 #{@mount}`
+ end
+ end
+end