Sha256: 5fa07ad7925e309da3271fac210397b9a4ce0c92692c1e498ac80f4a328ddb9e

Contents?: true

Size: 877 Bytes

Versions: 2

Compression:

Stored size: 877 Bytes

Contents

require 'sys/filesystem'

module Ganymed
  class Collector
    class Disk < Base
      def collect!
        Sys::Filesystem.mounts do |mount|
          st = Sys::Filesystem.stat(mount.mount_point)
          next if st.blocks == 0 or st.files == 0

          name = name(mount.mount_point)
          next if @config.exclude.map {|e| Regexp.new(e).match(name)}.any?

          block_pc = 1.0 - (st.blocks_free.to_f / st.blocks.to_f)
          @processor.event("os.disk.#{name}.blocks", block_pc)

          files_pc = 1.0 - (st.files_free.to_f / st.files.to_f)
          @processor.event("os.disk.#{name}.files", block_pc)
        end
      end

      private

      def name(mount)
        case mount
        when '/'
          'rootfs'
        when /^\/.+$/
          mount[1..-1].tr('^[a-z][0-9]', '-')
        else
          'unknown'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ganymed-0.1.2 lib/ganymed/collector/disk.rb
ganymed-0.1.1 lib/ganymed/collector/disk.rb