lib/riemann/tools/diskstats.rb in riemann-tools-1.10.0 vs lib/riemann/tools/diskstats.rb in riemann-tools-1.11.0

- old
+ new

@@ -9,16 +9,18 @@ opt :devices, 'Devices to monitor', type: :strings, default: nil opt :ignore_devices, 'Devices to ignore', type: :strings, default: nil def initialize + super + @old_state = nil end def state f = File.read('/proc/diskstats') - state = f.split("\n").reject { |d| d =~ /(ram|loop)/ }.each_with_object({}) do |line, s| + state = f.split("\n").grep_v(/(ram|loop)/).each_with_object({}) do |line, s| next unless line =~ /^(?:\s+\d+){2}\s+([\w\d-]+) (.*)$/ dev = Regexp.last_match(1) ['reads reqs', @@ -41,17 +43,17 @@ end # Filter interfaces if (is = opts[:devices]) state = state.select do |service, _value| - is.include? service.split(' ').first + is.include? service.split.first end end if (ign = opts[:ignore_devices]) state = state.reject do |service, _value| - ign.include? service.split(' ').first + ign.include? service.split.first end end state end @@ -78,10 +80,10 @@ end next unless service =~ /io time$/ report( - service: "diskstats #{service.gsub(/time/, 'util')}", + service: "diskstats #{service.gsub('time', 'util')}", metric: (delta.to_f / (opts[:interval] * 1000)), state: 'ok', ) end end