Class: Diskstats

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/check-disk-io_gem.rb

Constant Summary collapse

COLUMNS =
[
  :major,
  :minor,
  :device_name,
  :reads_success,
  :reads_merged,
  :sectors_read,
  :read_time_ms,
  :writes_success,
  :writes_merged,
  :sectors_written,
  :write_time_ms,
  :current_ios,
  :io_time_ms,
  :weightd_io_time_ms
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats) ⇒ Diskstats

Returns a new instance of Diskstats.



51
52
53
# File 'lib/check-disk-io_gem.rb', line 51

def initialize(stats)
  @raw_stats = stats
end

Instance Attribute Details

#laterObject (readonly)

Returns the value of attribute later.



49
50
51
# File 'lib/check-disk-io_gem.rb', line 49

def later
  @later
end

#nowObject (readonly)

Returns the value of attribute now.



49
50
51
# File 'lib/check-disk-io_gem.rb', line 49

def now
  @now
end

#raw_statsObject (readonly)

Returns the value of attribute raw_stats.



49
50
51
# File 'lib/check-disk-io_gem.rb', line 49

def raw_stats
  @raw_stats
end

Class Method Details

.from_procObject



65
66
67
# File 'lib/check-disk-io_gem.rb', line 65

def self.from_proc
  new(File.read('/proc/diskstats'))
end

Instance Method Details

#each(&block) ⇒ Object



61
62
63
# File 'lib/check-disk-io_gem.rb', line 61

def each(&block)
  rows.each(&block)
end

#rowsObject



55
56
57
58
59
# File 'lib/check-disk-io_gem.rb', line 55

def rows
  @rows ||= raw_stats.lines.map do |line|
    OpenStruct.new(Hash[COLUMNS.zip(line.strip.split)])
  end
end