Class: Pier::PageRequest::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/pier/page_request/metric.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, namespace:) ⇒ Metric



7
8
9
10
# File 'lib/pier/page_request/metric.rb', line 7

def initialize(client:, namespace:)
  @client = client
  @namespace = namespace
end

Instance Method Details

#call(name, started, finished, unique_id, payload) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pier/page_request/metric.rb', line 12

def call(name, started, finished, unique_id, payload)
  client.increment(
    "#{namespace}.http",
    tags: tags(payload: payload)
  )
  client.histogram(
    "#{namespace}.http.response_time",
    payload[:view_runtime].to_f + payload[:db_runtime].to_f,
    tags: tags(payload: payload)
  )

  if payload[:view_runtime]
    client.histogram(
      "#{namespace}.http.response_time.views",
      payload[:view_runtime].to_f,
      tags: tags(payload: payload)
    )
  end

  if payload[:db_runtime]
    client.histogram(
      "#{namespace}.http.response_time.db",
      payload[:db_runtime].to_f,
      tags: tags(payload: payload)
    )
  end
end