class Brewer::Stats::Logger
Attributes
controller[R]
state[RW]
stats_dir[R]
Public Class Methods
new()
click to toggle source
# File lib/brewer/stats/logger.rb, line 8 def initialize @controller = Brewer::Controller.new @state = {} create_stats_directory create_log_file end
Public Instance Methods
capture_snapshot()
click to toggle source
:nocov:
# File lib/brewer/stats/logger.rb, line 26 def capture_snapshot @state['pv'] = @controller.pv @state end
clear_log_file()
click to toggle source
# File lib/brewer/stats/logger.rb, line 50 def clear_log_file File.open($log_file, 'w') {|file| file.truncate(0) } true end
create_log_file()
click to toggle source
# File lib/brewer/stats/logger.rb, line 45 def create_log_file File.open($log_file, 'w') unless File.exists?($log_file) true end
create_stats_directory()
click to toggle source
# File lib/brewer/stats/logger.rb, line 40 def create_stats_directory Dir.mkdir($stats_dir) unless File.exists?($stats_dir) true end
log(interval: 15)
click to toggle source
:nocov:
# File lib/brewer/stats/logger.rb, line 17 def log(interval: 15) while true do capture_snapshot store sleep(interval) end end
store()
click to toggle source
# File lib/brewer/stats/logger.rb, line 31 def store store = YAML::Store.new $log_file store.transaction { @state.each do |k, v| store[Time.now.to_i] = {k => v} end } end