class ServState::LogManager
Public Class Methods
data(type)
click to toggle source
# File lib/ServState/log_manager.rb, line 20 def data(type) case type when '1day' then get_hash(@@day) when '10min' then get_hash(@@min) end end
start()
click to toggle source
# File lib/ServState/log_manager.rb, line 6 def start @@min = Rotator.new(120) # with 5 sec delay => 10 minutes @@day = Rotator.new(150) @@counter = 0 end
update(params)
click to toggle source
# File lib/ServState/log_manager.rb, line 12 def update(params) @@counter += 1 @@min.append(params) if @@counter % @@min.size == 0 @@day.append(normalize(@@min.data)) end end
Private Class Methods
get_hash(object)
click to toggle source
# File lib/ServState/log_manager.rb, line 29 def get_hash(object) { cpu: object.data.each_with_index.map{ |x, i| { x: i, y: x[0] } }, ram: object.data.each_with_index.map{ |x, i| { x: i, y: x[1] } }, down: object.data.each_with_index.map{ |x, i| { x: i, y: x[2] } }, up: object.data.each_with_index.map{ |x, i| { x: i, y: x[3] } } } end
normalize(data)
click to toggle source
# File lib/ServState/log_manager.rb, line 36 def normalize(data) result = Hash.new result[:cpu] = data.inject(0){ |sum, n| sum + n[0] } / data.size result[:ram] = data.inject(0){ |sum, n| sum + n[1] } / data.size result[:down] = data.inject(0){ |sum, n| sum + n[2] } / data.size result[:up] = data.inject(0){ |sum, n| sum + n[3] } / data.size result end