Sha256: 36a85800e5cad8d0d467f8f7a8ab45a88529f6727644e7420e1f7a9d6e9173b4

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 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 run_plugin
    File.exists? '/proc/diskstats'
  end

  def collect
    status = Array.new
    f = File.read('/proc/diskstats')
    f.split("\n").reject { |d| d =~ /(ram|loop)/ }.inject({}) do |s, line|
      if line =~ /^(?:\s+\d+){2}\s+([\w\d]+) (.*)$/
        dev = $1
        values = $2.split(/\s+/).map { |str| str.to_i }
        # пропускаем неинтересные девайсы
        # которые закнчиваются на число, но при этом не пропускаем xvd
        next if !!(dev.match /\d+$/ || !(dev.match =~ /^xvd/))
        # читаем все фильтры
        plugin.filter.each do |filter|
          status << { :service => "#{plugin.service} #{dev} #{filter}", :metric => values[WORDS.index(filter)], :as_diff => true}
        end
        # добавляем iops
        iops = values[WORDS.index('reads reqs')].to_i + values[WORDS.index('writes reqs')].to_i
        status << { :service => "#{plugin.service} #{dev} iops", :metric => iops, :as_diff => true}
      end 
    end
    status
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
riemann-babbler-1.4.0 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9.7 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9.6 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9.5 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9.4 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9.3 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9.1 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.9 lib/riemann/babbler/plugins/diskstat.rb
riemann-babbler-1.3.8 lib/riemann/babbler/plugins/diskstat.rb