Module: Pace::LoadAverage

Defined in:
lib/pace/load_average.rb

Constant Summary collapse

INTERVAL =

sec

5.0
FSHIFT =
11
FIXED_1 =
1 << FSHIFT
EXP_1 =

1/exp(5sec/1min) as fixed-point

1884.0
EXP_5 =

1/exp(5sec/5min)

2014.0
EXP_15 =

1/exp(5sec/15min)

2037.0

Class Method Summary collapse

Class Method Details

.average(load, exp, n) ⇒ Object



23
24
25
26
27
# File 'lib/pace/load_average.rb', line 23

def average(load, exp, n)
  load *= exp
  load += n*(FIXED_1-exp)
  (((load * 1000).to_i >> FSHIFT) / 1000.0).round(2)
end

.computeObject



13
14
15
16
17
18
19
20
21
# File 'lib/pace/load_average.rb', line 13

def compute
  per_second = $ticks / INTERVAL
  $load[0] = per_second
  $load[1] = average($load[1], EXP_1, per_second)
  $load[2] = average($load[2], EXP_5, per_second)
  $load[3] = average($load[3], EXP_15, per_second)
  $ticks = 0
  $load
end

.tickObject



29
30
31
# File 'lib/pace/load_average.rb', line 29

def tick
  $ticks += 1
end