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



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

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

Instance Attribute Details

#guestObject

Returns the value of attribute guest

Returns:

  • (Object)

    the current value of guest



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

def guest
  @guest
end

#guest_niceObject

Returns the value of attribute guest_nice

Returns:

  • (Object)

    the current value of guest_nice



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

def guest_nice
  @guest_nice
end

#idleObject

Returns the value of attribute idle

Returns:

  • (Object)

    the current value of idle



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

def idle
  @idle
end

#iowaitObject

Returns the value of attribute iowait

Returns:

  • (Object)

    the current value of iowait



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

def iowait
  @iowait
end

#irqObject

Returns the value of attribute irq

Returns:

  • (Object)

    the current value of irq



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

def irq
  @irq
end

#niceObject

Returns the value of attribute nice

Returns:

  • (Object)

    the current value of nice



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

def nice
  @nice
end

#softirqObject

Returns the value of attribute softirq

Returns:

  • (Object)

    the current value of softirq



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

def softirq
  @softirq
end

#stealObject

Returns the value of attribute steal

Returns:

  • (Object)

    the current value of steal



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

def steal
  @steal
end

#systemObject

Returns the value of attribute system

Returns:

  • (Object)

    the current value of system



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

def system
  @system
end

#timeObject (readonly)

Returns the value of attribute time



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

def time
  @time
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



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

def user
  @user
end

Instance Method Details

#diff(other) ⇒ Object



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

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



48
49
50
51
# File 'lib/osctl/cli/top/host.rb', line 48

def total
  return @total if @total
  @total = reduce(:+)
end

#total_usedObject



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

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