summaryrefslogtreecommitdiff
path: root/lib/byteback/disk_free.rb
blob: 33952a31679f961503613e82189e9d678da58f41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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