Module: NewRelic::IA::IostatReader::Linux

Defined in:
lib/new_relic/ia/iostat_reader/linux.rb

Instance Method Summary collapse

Instance Method Details

#cmdObject



3
# File 'lib/new_relic/ia/iostat_reader/linux.rb', line 3

def cmd; "iostat -dck 15"  ; end

#initObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/new_relic/ia/iostat_reader/linux.rb', line 4

def init
  # read to "Device:"
  line = @pipe.gets until line =~ /^Device:/
  
  # read to first blank line
  @disk_count = 0
  line = @pipe.gets
  until line =~ /^\s*$/
    @disk_count += 1
    line = @pipe.gets
  end
end

#read_nextObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/new_relic/ia/iostat_reader/linux.rb', line 16

def read_next
  # read up to the next header
  begin 
    line = @pipe.gets.chomp
  end until line =~ /avg-cpu/
  line = @pipe.gets
  # Get the CPU stats
  values             = line.strip.split /\s+/
  user, nice, system = values.map { |v| v.to_f }
  log.debug "CPU #{user}% (user), #{system}% (system)"
  user_cpu.record_data_point user
  system_cpu.record_data_point system
  # skip two lines
  @pipe.gets
  @pipe.gets
  # Iterate over each disk's stats
  @disk_count.times do | disk_number |
    line = @pipe.gets.chomp.strip
    values = line.split /\s+/
    usage = values[4].to_f + values[5].to_f
    log.debug "Disk #{values[0]}: #{usage}kb (processed '#{values.inspect}'"
    io_stats.record_data_point(usage * 1024)
  end
end