class SolarisStats::DiskUsageMetrics
Public Instance Methods
run()
click to toggle source
Main function
# File lib/solaris_stats.rb, line 51 def run delim = config[:flatten] == true ? '_' : '.' # Get disk usage from df with used and avail in megabytes # #YELLOW command = if Gem::Platform.local.os == 'solaris' "df -k #{config[:local] ? '-l' : ''}" else "df -PB#{config[:block_size]} #{config[:local] ? '-l' : ''}" end `#{command}`.split("\n").drop(1).each do |line| _, _, used, avail, used_p, mnt = line.split unless %r{/sys[/|$]|/dev[/|$]|/run[/|$]} =~ mnt next if config[:ignore_mnt] && config[:ignore_mnt].find { |x| mnt.match(x) } next if config[:include_mnt] && !config[:include_mnt].find { |x| mnt.match(x) } mnt = if config[:flatten] mnt.eql?('/') ? 'root' : mnt.gsub(/^\//, '') else # If mnt is only / replace that with root if its /tmp/foo # replace first occurance of / with root. mnt.length == 1 ? 'root' : mnt.gsub(/^\//, 'root.') end # Fix subsequent slashes mnt = mnt.gsub '/', delim output [config[:scheme], mnt, 'used'].join('.'), used.gsub(config[:block_size], '') output [config[:scheme], mnt, 'avail'].join('.'), avail.gsub(config[:block_size], '') output [config[:scheme], mnt, 'used_percentage'].join('.'), used_p.delete('%') end end ok end