require 'objspace' module ServState class ServicesManager class << self def start @usage = UsageManager.new LogManager.start @@services_thread = Thread.new do # thread for calculate cpu and network load and other long time operations while true @usage.update average_down = @usage.network_speed.map { |key, n| n[0] }.inject(:+) average_up = @usage.network_speed.map { |key, n| n[1] }.inject(:+) LogManager.update({ cpu: @usage.cpu_stat, ram: @usage.ram_usage[:ram_per], down: average_down, up: average_up }) GC.start sleep(5) end end end def json_for_dashboard { cpu: @usage.cpu_stat, uptime: @usage.uptime, mem_usage: @usage.ram_usage, disks_usage: @usage.disk_usage, interfaces: @usage.interfaces, network: @usage.network_speed }.to_json end def json_for_charts(type) LogManager.data(type).to_json end def hostname @usage.hostname end end end end