lib/zabbix-ruby-client/plugins/disk.rb in zabbix-ruby-client-0.1.2 vs lib/zabbix-ruby-client/plugins/disk.rb in zabbix-ruby-client-0.1.3

- old
+ new

@@ -15,11 +15,10 @@ dev = args[1] mapped = args[3] || dev info = get_info(dev, mapped) if info - time = Time.now.to_i back = [] back << "#{host} disk.space[#{mapped},size] #{time} #{to_m(info[1])}" back << "#{host} disk.space[#{mapped},used] #{time} #{to_m(info[2])}" back << "#{host} disk.space[#{mapped},available] #{time} #{to_m(info[3])}" back << "#{host} disk.space[#{mapped},percent_used] #{time} #{info[4].gsub(/%/,'')}" @@ -54,21 +53,42 @@ def get_info(disk, device) info = diskinfo(device) if info back = info.split(/\s+/) - io = getline("/proc/diskstats", " #{disk} ") - if io - back += io.split(/\s+/) + case os + when :linux + io = getline("/proc/diskstats", " #{disk} ") + if io + back += io.split(/\s+/) + end + when :unix + output = `iostat -x | grep "#{disk}"` + data = output.split(/\s+/) + back << 0 # -- + back << 0 # -- + back << 0 # -- + back << data[3] # read_ok + back << 0 # read_merged + back << 0 # read_sector + back << 0 # read_time + back << data[4] # write_ok + back << 0 # write_merged + back << 0 # write_sector + back << 0 # write_time + back << 0 # io_time + back << 0 # io_merged + else + return false end back else false end end def diskinfo(disk) - output = `df | grep "#{disk}"` + output = `df -k | grep "#{disk}"` if $?.to_i == 0 Log.debug self Log.debug output output else