Class: RequestTrail::Collector
- Inherits:
-
Object
- Object
- RequestTrail::Collector
- Defined in:
- lib/request_trail/collector.rb
Constant Summary collapse
- THREAD_KEY =
:request_trail_collector
Instance Attribute Summary collapse
-
#action_duration_ms ⇒ Object
readonly
Returns the value of attribute action_duration_ms.
-
#cache_duration_ms ⇒ Object
readonly
Returns the value of attribute cache_duration_ms.
-
#cache_hits ⇒ Object
readonly
Returns the value of attribute cache_hits.
-
#cache_misses ⇒ Object
readonly
Returns the value of attribute cache_misses.
-
#cache_writes ⇒ Object
readonly
Returns the value of attribute cache_writes.
-
#http_count ⇒ Object
readonly
Returns the value of attribute http_count.
-
#http_duration_ms ⇒ Object
readonly
Returns the value of attribute http_duration_ms.
-
#sql_count ⇒ Object
readonly
Returns the value of attribute sql_count.
-
#sql_duration_ms ⇒ Object
readonly
Returns the value of attribute sql_duration_ms.
-
#view_duration_ms ⇒ Object
readonly
Returns the value of attribute view_duration_ms.
Class Method Summary collapse
Instance Method Summary collapse
- #elapsed_ms ⇒ Object
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
- #record_action(duration_ms:, view_duration_ms:) ⇒ Object
- #record_cache_read(hit:, duration_ms:) ⇒ Object
- #record_cache_write(duration_ms:) ⇒ Object
- #record_http(duration_ms:) ⇒ Object
- #record_sql(duration_ms) ⇒ Object
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/request_trail/collector.rb', line 24 def initialize @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) @sql_count = 0 @sql_duration_ms = 0.0 @cache_hits = 0 @cache_misses = 0 @cache_writes = 0 @cache_duration_ms = 0.0 @action_duration_ms = 0.0 @view_duration_ms = 0.0 @http_count = 0 @http_duration_ms = 0.0 end |
Instance Attribute Details
#action_duration_ms ⇒ Object (readonly)
Returns the value of attribute action_duration_ms.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def action_duration_ms @action_duration_ms end |
#cache_duration_ms ⇒ Object (readonly)
Returns the value of attribute cache_duration_ms.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def cache_duration_ms @cache_duration_ms end |
#cache_hits ⇒ Object (readonly)
Returns the value of attribute cache_hits.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def cache_hits @cache_hits end |
#cache_misses ⇒ Object (readonly)
Returns the value of attribute cache_misses.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def cache_misses @cache_misses end |
#cache_writes ⇒ Object (readonly)
Returns the value of attribute cache_writes.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def cache_writes @cache_writes end |
#http_count ⇒ Object (readonly)
Returns the value of attribute http_count.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def http_count @http_count end |
#http_duration_ms ⇒ Object (readonly)
Returns the value of attribute http_duration_ms.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def http_duration_ms @http_duration_ms end |
#sql_count ⇒ Object (readonly)
Returns the value of attribute sql_count.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def sql_count @sql_count end |
#sql_duration_ms ⇒ Object (readonly)
Returns the value of attribute sql_duration_ms.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def sql_duration_ms @sql_duration_ms end |
#view_duration_ms ⇒ Object (readonly)
Returns the value of attribute view_duration_ms.
7 8 9 |
# File 'lib/request_trail/collector.rb', line 7 def view_duration_ms @view_duration_ms end |
Class Method Details
.current ⇒ Object
12 13 14 |
# File 'lib/request_trail/collector.rb', line 12 def self.current Thread.current[THREAD_KEY] end |
.start ⇒ Object
16 17 18 |
# File 'lib/request_trail/collector.rb', line 16 def self.start Thread.current[THREAD_KEY] = new end |
.stop ⇒ Object
20 21 22 |
# File 'lib/request_trail/collector.rb', line 20 def self.stop Thread.current[THREAD_KEY] = nil end |
Instance Method Details
#elapsed_ms ⇒ Object
63 64 65 66 |
# File 'lib/request_trail/collector.rb', line 63 def elapsed_ms elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @started_at (elapsed * 1000).round(2) end |
#record_action(duration_ms:, view_duration_ms:) ⇒ Object
53 54 55 56 |
# File 'lib/request_trail/collector.rb', line 53 def record_action(duration_ms:, view_duration_ms:) @action_duration_ms = duration_ms @view_duration_ms = view_duration_ms end |
#record_cache_read(hit:, duration_ms:) ⇒ Object
43 44 45 46 |
# File 'lib/request_trail/collector.rb', line 43 def record_cache_read(hit:, duration_ms:) hit ? @cache_hits += 1 : @cache_misses += 1 @cache_duration_ms += duration_ms end |
#record_cache_write(duration_ms:) ⇒ Object
48 49 50 51 |
# File 'lib/request_trail/collector.rb', line 48 def record_cache_write(duration_ms:) @cache_writes += 1 @cache_duration_ms += duration_ms end |
#record_http(duration_ms:) ⇒ Object
58 59 60 61 |
# File 'lib/request_trail/collector.rb', line 58 def record_http(duration_ms:) @http_count += 1 @http_duration_ms += duration_ms end |
#record_sql(duration_ms) ⇒ Object
38 39 40 41 |
# File 'lib/request_trail/collector.rb', line 38 def record_sql(duration_ms) @sql_count += 1 @sql_duration_ms += duration_ms end |