Class: Brewer::Stats::Logger
- Inherits:
-
Object
- Object
- Brewer::Stats::Logger
- Defined in:
- lib/brewer/stats/logger.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#state ⇒ Object
Returns the value of attribute state.
-
#stats_dir ⇒ Object
readonly
Returns the value of attribute stats_dir.
Instance Method Summary collapse
-
#capture_snapshot ⇒ Object
:nocov:.
- #clear_log_file ⇒ Object
- #create_log_file ⇒ Object
- #create_stats_directory ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
-
#log(interval: 15) ⇒ Object
:nocov:.
- #store ⇒ Object
Constructor Details
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
5 6 7 |
# File 'lib/brewer/stats/logger.rb', line 5 def controller @controller end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/brewer/stats/logger.rb', line 6 def state @state end |
#stats_dir ⇒ Object (readonly)
Returns the value of attribute stats_dir.
5 6 7 |
# File 'lib/brewer/stats/logger.rb', line 5 def stats_dir @stats_dir end |
Instance Method Details
#capture_snapshot ⇒ Object
:nocov:
26 27 28 29 |
# File 'lib/brewer/stats/logger.rb', line 26 def capture_snapshot @state['pv'] = @controller.pv @state end |
#clear_log_file ⇒ Object
50 51 52 53 |
# 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 ⇒ Object
45 46 47 48 |
# 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 ⇒ Object
40 41 42 43 |
# 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) ⇒ Object
:nocov:
17 18 19 20 21 22 23 |
# File 'lib/brewer/stats/logger.rb', line 17 def log(interval: 15) while true do capture_snapshot store sleep(interval) end end |
#store ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 |