Class: Philiprehberger::HttpClient::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/http_client/metrics.rb

Overview

Timing metrics for an HTTP request. Captures DNS, connect, TLS, first byte, and total durations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetrics

Returns a new instance of Metrics.



10
11
12
13
14
15
16
# File 'lib/philiprehberger/http_client/metrics.rb', line 10

def initialize
  @dns_time = 0.0
  @connect_time = 0.0
  @tls_time = 0.0
  @first_byte_time = 0.0
  @total_time = 0.0
end

Instance Attribute Details

#connect_timeObject (readonly)

Returns the value of attribute connect_time.



8
9
10
# File 'lib/philiprehberger/http_client/metrics.rb', line 8

def connect_time
  @connect_time
end

#dns_timeObject (readonly)

Returns the value of attribute dns_time.



8
9
10
# File 'lib/philiprehberger/http_client/metrics.rb', line 8

def dns_time
  @dns_time
end

#first_byte_timeObject (readonly)

Returns the value of attribute first_byte_time.



8
9
10
# File 'lib/philiprehberger/http_client/metrics.rb', line 8

def first_byte_time
  @first_byte_time
end

#tls_timeObject (readonly)

Returns the value of attribute tls_time.



8
9
10
# File 'lib/philiprehberger/http_client/metrics.rb', line 8

def tls_time
  @tls_time
end

#total_timeObject (readonly)

Returns the value of attribute total_time.



8
9
10
# File 'lib/philiprehberger/http_client/metrics.rb', line 8

def total_time
  @total_time
end

Instance Method Details

#record(field, value) ⇒ Object

Record a timing measurement.

Parameters:

  • field (Symbol)

    one of :dns_time, :connect_time, :tls_time, :first_byte_time, :total_time

  • value (Float)

    duration in seconds



22
23
24
# File 'lib/philiprehberger/http_client/metrics.rb', line 22

def record(field, value)
  instance_variable_set(:"@#{field}", value)
end

#to_hHash{Symbol => Float}

Return all timings as a hash.

Returns:

  • (Hash{Symbol => Float})


29
30
31
32
33
34
35
36
37
# File 'lib/philiprehberger/http_client/metrics.rb', line 29

def to_h
  {
    dns_time: @dns_time,
    connect_time: @connect_time,
    tls_time: @tls_time,
    first_byte_time: @first_byte_time,
    total_time: @total_time
  }
end