Sha256: 48cdeb595d8a5e1198bb67dd0fcafe3870597dd4b54881ef546afc70e368c817

Contents?: true

Size: 1.57 KB

Versions: 37

Compression:

Stored size: 1.57 KB

Contents

class Riemann::Babbler::Plugin::DiskStat < Riemann::Babbler::Plugin

  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 |_, 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)].to_f/plugin.interval, :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.to_f/plugin.interval, :as_diff => true }
      end
    end
    status
  end

end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.8.4 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.8.3 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.8.2 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.8.1 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.8.0 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.6.0 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.9 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.8 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.7 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.6 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.5 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.4 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.3 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.2 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.1 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.5.0 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.1.5 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.1.4 lib/riemann/babbler/plugins/disk_stat.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/plugins/disk_stat.rb