Class: MPstat

Inherits:
Object
  • Object
show all
Includes:
RunCommand
Defined in:
lib/city_watch/commands/mpstat.rb

Instance Method Summary collapse

Methods included from RunCommand

#command_line, #command_output, included, #options, #set_opts, #supported?

Instance Method Details

#command_line_optsObject



7
8
9
# File 'lib/city_watch/commands/mpstat.rb', line 7

def command_line_opts
  "#{options[:interval]} #{options[:times]}"
end

#dataObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/city_watch/commands/mpstat.rb', line 11

def data
  headers = false
  command_output.split("\n").map {|line| line.split("\s") }.inject([]) do |output,line|
    if line[1] == "CPU"
      headers = line.map {|hdr| hdr.gsub(/%/,'').to_sym}
      headers[0] = :run
    elsif headers
      pkt = {}
      line.each_with_index do |itm,idx|
        pkt[headers[idx]] = itm
      end
      output << pkt
    end
    output
  end
end