From 1238c74fa01c009d7f76327f3beb30fee4b9f98f Mon Sep 17 00:00:00 2001 From: Matthew Bloch Date: Fri, 31 Oct 2014 02:43:35 +0000 Subject: Refactored to improve logging and reduce cut & paste code, bumped Debian version number. --- lib/byteback/disk_free.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 lib/byteback/disk_free.rb (limited to 'lib/byteback/disk_free.rb') 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 -- cgit v1.2.1