Class: OsCtld::Container::Hints::CpuDaily
- Inherits:
-
Object
- Object
- OsCtld::Container::Hints::CpuDaily
- Defined in:
- lib/osctld/container/hints.rb
Instance Attribute Summary collapse
-
#system_us ⇒ Object
readonly
Returns the value of attribute system_us.
-
#usage_us ⇒ Object
readonly
Returns the value of attribute usage_us.
-
#user_us ⇒ Object
readonly
Returns the value of attribute user_us.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(user_us: 0, system_us: 0) ⇒ CpuDaily
constructor
A new instance of CpuDaily.
- #update(new_user_us, new_system_us, runtime_secs) ⇒ Object
Constructor Details
#initialize(user_us: 0, system_us: 0) ⇒ CpuDaily
Returns a new instance of CpuDaily.
13 14 15 16 17 |
# File 'lib/osctld/container/hints.rb', line 13 def initialize(user_us: 0, system_us: 0) @user_us = user_us @system_us = system_us @usage_us = user_us + system_us end |
Instance Attribute Details
#system_us ⇒ Object (readonly)
Returns the value of attribute system_us.
11 12 13 |
# File 'lib/osctld/container/hints.rb', line 11 def system_us @system_us end |
#usage_us ⇒ Object (readonly)
Returns the value of attribute usage_us.
11 12 13 |
# File 'lib/osctld/container/hints.rb', line 11 def usage_us @usage_us end |
#user_us ⇒ Object (readonly)
Returns the value of attribute user_us.
11 12 13 |
# File 'lib/osctld/container/hints.rb', line 11 def user_us @user_us end |
Class Method Details
.load(cfg) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/osctld/container/hints.rb', line 4 def self.load(cfg) new( user_us: cfg.fetch('user_us', 0), system_us: cfg.fetch('system_us', 0) ) end |
Instance Method Details
#dump ⇒ Object
41 42 43 44 45 46 |
# File 'lib/osctld/container/hints.rb', line 41 def dump { 'user_us' => user_us, 'system_us' => system_us } end |
#update(new_user_us, new_system_us, runtime_secs) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/osctld/container/hints.rb', line 19 def update(new_user_us, new_system_us, runtime_secs) runtime_days = runtime_secs / 60.0 / 60 cur_user_us = new_user_us / runtime_days @user_us = if @user_us > 0 ((@user_us + cur_user_us) / 2).round else cur_user_us.round end cur_system_us = new_system_us / runtime_days @system_us = if @system_us > 0 ((@system_us + cur_system_us) / 2).round else cur_system_us.round end @usage_us = @user_us + @system_us end |