Sha256: 8326784ab7f3dcab71710a7236ba4990c03fb5c61cdd8398b2d13f3c2b89881a

Contents?: true

Size: 1.62 KB

Versions: 32

Compression:

Stored size: 1.62 KB

Contents

#encoding: utf-8

class Riemann::Babbler::Disk < Riemann::Babbler

  require 'sys/filesystem'
  include Sys

  NOT_MONITORING_FS = %w(sysfs nfs devpts squashfs proc devtmpfs)

  def collect
    # собираем только необходимые для мониторинга маунт-поинты
    # точнее выбираем из mounts только те, у которых fstype не попадает
    # в NOT_MONITORING_FS
    monit_points = [] 
    File.read('/proc/mounts').split("\n").each do |line|
      mtab = line.split(/\s+/)
      monit_points << mtab[1] unless NOT_MONITORING_FS.include? mtab[2] 
    end
    disk = Array.new
    monit_points.each do |point|
      point_stat = Filesystem.stat point
      human_point = point == '/' ? '/root' : point
      human_point = human_point.gsub(/^\//, '').gsub(/\//, '_')
      disk << { :service => plugin.service + " #{human_point} % block", :description => "Disk usage #{point}, %", :metric => (1- point_stat.blocks_available.to_f/point_stat.blocks).round(2) * 100 }
      disk << { :service => plugin.service + " #{human_point} % inode", :description => "Disk usage #{point}, inodes %", :metric => (1 - point_stat.files_available.to_f/point_stat.files).round(2) * 100 }
      disk << { :service => plugin.service + " #{human_point} abs free", :description => "Disk free #{point}, B", :metric =>  point_stat.blocks_free * point_stat.block_size, :state => 'ok'}
      disk << { :service => plugin.service + " #{human_point} abs total", :description => "Disk space #{point}, B",  :metric =>  point_stat.blocks * point_stat.block_size, :state => 'ok'}
    end
    disk
  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
riemann-babbler-1.0.5.5 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.5.4 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.5.3 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.5.2 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.5.1 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.5 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.4 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.3 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.2 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.1 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-1.0.0 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.9 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.8.1 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.8 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.7 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.6 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.5 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.4 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.3 lib/riemann/babbler/plugins/disk.rb
riemann-babbler-0.9.9.2 lib/riemann/babbler/plugins/disk.rb