Sha256: 68cc868c1bd362c3c00fbe5b9d808dfb2cdefc97a330ec6918fbd9a2f1f72c14

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

class Riemann::Babbler::Diskstat < Riemann::Babbler

  WORDS = [
    'reads reqs',
    'reads merged',
    'reads sector',
    'reads time',
    'writes reqs',
    'writes merged',
    'writes sector',
    'writes time',
    'io reqs',
    'io time',
    'io weighted'
  ]

  def init
    plugin.set_default(:service, 'diskstat')
    plugin.set_default(:interval, 60)
    plugin.set_default(:filter, ['reads reqs', 'writes reqs'])
  end

  def collect
    status = Array.new
    f = File.read('/proc/diskstats')
    state = f.split("\n").reject { |d| d =~ /(ram|loop| md| dm| sr)/ }.inject({}) do |s, line|
      if line =~ /^(?:\s+\d+){2}\s+([\w\d]+) (.*)$/
        dev = $1

        WORDS.map do |service|
          next unless plugin.filter.include?(service) #TODO hardcode
          "#{plugin.service} #{dev} #{service}"
        end.zip(
          $2.split(/\s+/).map { |str| str.to_i }
        ).each do |service, value|
          next if service.nil? #TODO hardcode
          status << { :service => service, :metric => value, :as_diff => true}
        end
      end 
    end
    status
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-babbler-1.3.5 lib/riemann/babbler/plugins/diskstat.rb