Module: Grifter::Instrumentation

Included in:
Grifter
Defined in:
lib/grifter/instrumentation.rb

Defined Under Namespace

Classes: Sample

Instance Method Summary collapse

Instance Method Details

#metrics_all_requestsObject



26
27
28
# File 'lib/grifter/instrumentation.rb', line 26

def metrics_all_requests
  @all_requests
end

#start_instrumentationObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/grifter/instrumentation.rb', line 7

def start_instrumentation
  @all_requests ||= []
  ActiveSupport::Notifications.subscribe('request.grifter') do |name, start_time, end_time, _, data|
    #do nothing if exception happened, else we might interfere with exception handling
    unless data[:exception]
      duration_ms = ((end_time.to_f - start_time.to_f) * 1000).to_i
      #$stderr.puts '[%s] %s %s (%.3f s)' % [url.host, http_method, url.request_uri, duration]
      @all_requests << Sample.new(
        data[:service],
        data[:method].intern,
        data[:path],
        data[:response].status.to_s.intern,
        duration_ms,
        end_time
      )
    end
  end
end