Sha256: 210958d48d4fb478cb48db625223fdc7e3d6d714734b4332f34f221eccc04fd4

Contents?: true

Size: 969 Bytes

Versions: 12

Compression:

Stored size: 969 Bytes

Contents

module Graphiterb
  module Monitors

    # A monitor for how much space is available on a node.
    class DiskSpace < Graphiterb::Monitors::PeriodicMonitor

      # Runs and parses `df'.
      #
      #   disk_space.df
      #   #=> [["/dev/sda", "39373712", "20488716", "16884908", "55%", "/"], ["/dev/sdb", "920090332", "397413344", "475939088", "46%", "/home"]]
      #
      # @return [Array<Array>]
      def df
        `/bin/df`.chomp.split("\n").
          grep(%r{^/dev/}).
          map{|line| line.split(/\s+/) } rescue []
      end

      # Calls +df+ and adds the space available metric.
      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
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphiterb-0.2.12 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.11 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.10 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.9 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.7 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.6 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.5 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.4 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.3 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.2 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.1 lib/graphiterb/monitors/disk_space.rb
graphiterb-0.2.0 lib/graphiterb/monitors/disk_space.rb