Class: Graphiterb::Monitors::DiskSpace

Inherits:
PeriodicMonitor show all
Defined in:
lib/graphiterb/monitors/disk_space.rb

Overview

A monitor for how much space is available on a node.

Instance Attribute Summary

Attributes inherited from PeriodicMonitor

#current_iter, #iter, #iter_interval, #last_time, #main_scope, #options, #started_at, #time_interval

Instance Method Summary collapse

Methods inherited from PeriodicMonitor

#enough_iterations?, #enough_time?, #initialize, #inst_rate, #periodically, #rate, #run!, #scope, #sender, #since

Methods included from Utils::SystemInfo

#hostname

Constructor Details

This class inherits a constructor from Graphiterb::Monitors::PeriodicMonitor

Instance Method Details

#dfArray<Array>

Runs and parses ‘df’.

disk_space.df
#=> [["/dev/sda", "39373712", "20488716", "16884908", "55%", "/"], ["/dev/sdb", "920090332", "397413344", "475939088", "46%", "/home"]]

Returns:

  • (Array<Array>)


13
14
15
16
17
# File 'lib/graphiterb/monitors/disk_space.rb', line 13

def df
  `/bin/df`.chomp.split("\n").
    grep(%r{^/dev/}).
    map{|line| line.split(/\s+/) } rescue []
end

#get_metrics(metrics, since) ⇒ Object

Calls df and adds the space available metric.



20
21
22
23
24
25
26
# File 'lib/graphiterb/monitors/disk_space.rb', line 20

def get_metrics metrics, since
  #         "/dev/sdb1", "39373712", "20488716", "16884908", "55%", "/"
  df.each do |handle, size, spaceused, spacefree, percentfree, location|
    disk_name = handle.gsub(/^\//, '').split('/')
    metrics << [scope(hostname, disk_name, 'available'), spacefree.to_i]
  end
end