Class: LitmusPaper::Metric::CPULoad
- Inherits:
-
Object
- Object
- LitmusPaper::Metric::CPULoad
- Defined in:
- lib/litmus_paper/metric/cpu_load.rb
Instance Method Summary collapse
- #current_health ⇒ Object
-
#initialize(weight) ⇒ CPULoad
constructor
A new instance of CPULoad.
- #load_average ⇒ Object
- #processor_count ⇒ Object
- #stats ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(weight) ⇒ CPULoad
Returns a new instance of CPULoad.
4 5 6 |
# File 'lib/litmus_paper/metric/cpu_load.rb', line 4 def initialize(weight) @weight = weight end |
Instance Method Details
#current_health ⇒ Object
8 9 10 |
# File 'lib/litmus_paper/metric/cpu_load.rb', line 8 def current_health [@weight - (@weight * load_average / processor_count), 1].max end |
#load_average ⇒ Object
23 24 25 |
# File 'lib/litmus_paper/metric/cpu_load.rb', line 23 def load_average File.read('/proc/loadavg').split(' ').first.to_f end |
#processor_count ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/litmus_paper/metric/cpu_load.rb', line 12 def processor_count @processor_count ||= File.readlines('/proc/cpuinfo').reduce(0) do |memo, line| if line =~ /^processor/ memo + 1 else memo end end end |
#stats ⇒ Object
27 28 29 30 31 |
# File 'lib/litmus_paper/metric/cpu_load.rb', line 27 def stats { :cpu_load_average => load_average, } end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/litmus_paper/metric/cpu_load.rb', line 33 def to_s "Metric::CPULoad(#{@weight})" end |