bin/metrics-disk-capacity.rb in sensu-plugins-disk-checks-3.0.1 vs bin/metrics-disk-capacity.rb in sensu-plugins-disk-checks-3.1.0

- old
+ new

@@ -55,17 +55,22 @@ # Main function # def run # Get capacity metrics from DF as they don't appear in /proc - `df -PT`.split("\n").drop(1).each do |line| + command = if Gem::Platform.local.os == 'solaris' + 'df -k' + else + 'df -PT' + end + `#{command}`.split("\n").drop(1).each do |line| begin fs, _type, _blocks, used, avail, capacity, _mnt = line.split timestamp = Time.now.to_i if fs =~ /\/dev/ - fs = fs.gsub('/dev/', '') + fs = fs.tr('/dev/', '') metrics = { disk: { "#{fs}.used" => used, "#{fs}.avail" => avail, "#{fs}.capacity" => capacity.delete('%') @@ -81,31 +86,33 @@ unknown "malformed line from df: #{line}" end end # Get inode capacity metrics - `df -Pi`.split("\n").drop(1).each do |line| - begin - fs, _inodes, used, avail, capacity, _mnt = line.split + if Gem::Platform.local.os != 'solaris' + `df -Pi`.split("\n").drop(1).each do |line| + begin + fs, _inodes, used, avail, capacity, _mnt = line.split - timestamp = Time.now.to_i - if fs =~ /\/dev/ - fs = fs.gsub('/dev/', '') - metrics = { - disk: { - "#{fs}.iused" => used, - "#{fs}.iavail" => avail, - "#{fs}.icapacity" => capacity.delete('%') + timestamp = Time.now.to_i + if fs =~ /\/dev/ + fs = fs.tr('/dev/', '') + metrics = { + disk: { + "#{fs}.iused" => used, + "#{fs}.iavail" => avail, + "#{fs}.icapacity" => capacity.delete('%') + } } - } - metrics.each do |parent, children| - children.each do |child, value| - output [config[:scheme], parent, child].join('.'), value, timestamp + metrics.each do |parent, children| + children.each do |child, value| + output [config[:scheme], parent, child].join('.'), value, timestamp + end end end + rescue StandardError + unknown "malformed line from df: #{line}" end - rescue StandardError - unknown "malformed line from df: #{line}" end end ok end end