Class: OsCtl::Cli::Top::Host::Cpu

Inherits:
Struct
  • Object
show all
Defined in:
lib/osctl/cli/top/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_) ⇒ Cpu

Returns a new instance of Cpu.



20
21
22
23
# File 'lib/osctl/cli/top/host.rb', line 20

def initialize(*_)
  super
  @time = Time.now
end

Instance Attribute Details

#guestObject

Returns the value of attribute guest

Returns:

  • (Object)

    the current value of guest



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def guest
  @guest
end

#guest_niceObject

Returns the value of attribute guest_nice

Returns:

  • (Object)

    the current value of guest_nice



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def guest_nice
  @guest_nice
end

#idleObject

Returns the value of attribute idle

Returns:

  • (Object)

    the current value of idle



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def idle
  @idle
end

#iowaitObject

Returns the value of attribute iowait

Returns:

  • (Object)

    the current value of iowait



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def iowait
  @iowait
end

#irqObject

Returns the value of attribute irq

Returns:

  • (Object)

    the current value of irq



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def irq
  @irq
end

#niceObject

Returns the value of attribute nice

Returns:

  • (Object)

    the current value of nice



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def nice
  @nice
end

#softirqObject

Returns the value of attribute softirq

Returns:

  • (Object)

    the current value of softirq



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def softirq
  @softirq
end

#stealObject

Returns the value of attribute steal

Returns:

  • (Object)

    the current value of steal



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def steal
  @steal
end

#systemObject

Returns the value of attribute system

Returns:

  • (Object)

    the current value of system



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def system
  @system
end

#timeObject (readonly)

Returns the value of attribute time.



18
19
20
# File 'lib/osctl/cli/top/host.rb', line 18

def time
  @time
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



6
7
8
# File 'lib/osctl/cli/top/host.rb', line 6

def user
  @user
end

Instance Method Details

#diff(other) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/osctl/cli/top/host.rb', line 25

def diff(other)
  ret = self.class.new
  delta = time - other.time

  other.each_pair do |k, v|
    ret[k] = (self[k] - v) / delta.to_f
  end

  ret
end

#totalObject



50
51
52
53
54
# File 'lib/osctl/cli/top/host.rb', line 50

def total
  return @total if @total

  @total = reduce(:+)
end

#total_usedObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/osctl/cli/top/host.rb', line 36

def total_used
  return @total_used if @total_used

  sum = 0

  each_pair do |k, v|
    next if k == :idle

    sum += v
  end

  @total_used = sum
end