module Vidibus::Sysinfo::Storage
Returns consumed storage in gigabytes.
Calls `df`
Public Class Methods
call(mount_point)
click to toggle source
# File lib/vidibus/sysinfo/storage.rb, line 33 def call(mount_point) cmd = command(mount_point) output, error = perform(cmd) respond(output, error) end
command(mount_point)
click to toggle source
# File lib/vidibus/sysinfo/storage.rb, line 24 def command(mount_point) if !mount_point || mount_point == '' mp = '/' else mp = mount_point.gsub(/[^\/a-z0-9]/, '') end "df -m | grep '#{mp}$'" end
parse(output)
click to toggle source
# File lib/vidibus/sysinfo/storage.rb, line 39 def parse(output) device = /(?:[\/a-z0-9]+)/ size = /\s+(\d+)\i?/ if matches = output.match(/#{device}#{size}#{size}#{size}/m) total = $1.to_f used = $2.to_f free = $3.to_f Result.new({ total: gigabytes(total, 'M'), used: gigabytes(used, 'M'), free: gigabytes(free, 'M') }) end end