Class: RorVsWild::Metrics::Cpu::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/rorvswild/metrics/cpu.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice) ⇒ Stat

Returns a new instance of Stat.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rorvswild/metrics/cpu.rb', line 31

def initialize(user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice)
  @user = user
  @nice = nice
  @system = system
  @idle = idle
  @iowait = iowait
  @irq = irq
  @softirq = softirq
  @steal = steal
  @guest = guest
  @guest_nice = guest_nice
  @total = user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice
end

Instance Attribute Details

#guestObject (readonly)

Returns the value of attribute guest.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def guest
  @guest
end

#guest_niceObject (readonly)

Returns the value of attribute guest_nice.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def guest_nice
  @guest_nice
end

#idleObject (readonly)

Returns the value of attribute idle.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def idle
  @idle
end

#iowaitObject (readonly)

Returns the value of attribute iowait.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def iowait
  @iowait
end

#irqObject (readonly)

Returns the value of attribute irq.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def irq
  @irq
end

#niceObject (readonly)

Returns the value of attribute nice.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def nice
  @nice
end

#softirqObject (readonly)

Returns the value of attribute softirq.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def softirq
  @softirq
end

#stealObject (readonly)

Returns the value of attribute steal.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def steal
  @steal
end

#systemObject (readonly)

Returns the value of attribute system.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def system
  @system
end

#totalObject (readonly)

Returns the value of attribute total.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def total
  @total
end

#userObject (readonly)

Returns the value of attribute user.



29
30
31
# File 'lib/rorvswild/metrics/cpu.rb', line 29

def user
  @user
end

Class Method Details

.parse(string) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/rorvswild/metrics/cpu.rb', line 45

def self.parse(string)
  for row in string.lines
    if row.start_with?("cpu ")
      array = row.split[1..-1].map(&:to_i)[0,10]
      array.fill(0, array.size, 10 - array.size) if array.size < 10
      return new(*array)
    end
  end
  nil
end

.readObject



56
57
58
# File 'lib/rorvswild/metrics/cpu.rb', line 56

def self.read
  parse(File.read("/proc/stat")) if File.readable?("/proc/stat")
end