Class: RequestLog::Profiler
- Inherits:
-
Object
- Object
- RequestLog::Profiler
- Defined in:
- lib/request_log/profiler.rb
Class Method Summary collapse
- .attribute_names ⇒ Object
- .attributes ⇒ Object
- .call(options = {}) ⇒ Object
- .default_values ⇒ Object
- .failure_ratio ⇒ Object
- .persist! ⇒ Object
- .reset ⇒ Object
- .should_persist? ⇒ Boolean
- .to_s ⇒ Object
- .total_count ⇒ Object
Class Method Details
.attribute_names ⇒ Object
16 17 18 |
# File 'lib/request_log/profiler.rb', line 16 def self.attribute_names default_values.keys end |
.attributes ⇒ Object
66 67 68 69 70 71 |
# File 'lib/request_log/profiler.rb', line 66 def self.attributes attribute_names.inject({}) do |hash, attribute| hash[attribute] = send(attribute) hash end end |
.call(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/request_log/profiler.rb', line 44 def self.call( = {}) if [:result] == :success self.success_count += 1 update_times([:elapsed_time]) else self.failure_count += 1 if [:exception] failure_exceptions[[:exception].class.name] ||= 0 failure_exceptions[[:exception].class.name] += 1 end end persist! if should_persist? end |
.default_values ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/request_log/profiler.rb', line 3 def self.default_values { :success_count => 0, :failure_count => 0, :failure_exceptions => {}, :min_time => nil, :max_time => nil, :avg_time => nil, :persist_enabled => false, :persist_frequency => 2000 } end |
.failure_ratio ⇒ Object
62 63 64 |
# File 'lib/request_log/profiler.rb', line 62 def self.failure_ratio failure_count.to_f/total_count end |
.persist! ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/request_log/profiler.rb', line 73 def self.persist! ::RequestLog::Db.profiling.insert( :total_count => total_count, :failure_ratio => failure_ratio, :max_time => max_time, :avg_time => avg_time, :data => attributes ) end |
.reset ⇒ Object
35 36 37 38 39 40 |
# File 'lib/request_log/profiler.rb', line 35 def self.reset attribute_names.each do |attribute| send("#{attribute}=", default_values[attribute]) end self end |
.should_persist? ⇒ Boolean
83 84 85 |
# File 'lib/request_log/profiler.rb', line 83 def self.should_persist? persist_enabled && (total_count % persist_frequency == 0) end |
.to_s ⇒ Object
87 88 89 |
# File 'lib/request_log/profiler.rb', line 87 def self.to_s attributes.inspect end |
.total_count ⇒ Object
58 59 60 |
# File 'lib/request_log/profiler.rb', line 58 def self.total_count success_count + failure_count end |