Sha256: e9070fc1bb8408788827222d2c44b369e0f749f9767d5ac9b681178875bdb64d

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 KB

Contents

class LHC::Prometheus < LHC::Interceptor
  include ActiveSupport::Configurable

  config_accessor :client, :namespace

  class << self
    attr_accessor :registered
  end

  def self.request_key
    [LHC::Prometheus.namespace, 'lhc_requests'].join('_').to_sym
  end

  def self.times_key
    [LHC::Prometheus.namespace, 'lhc_times'].join('_').to_sym
  end

  def initialize(request)
    super(request)
    return if LHC::Prometheus.registered || LHC::Prometheus.client.blank?
    LHC::Prometheus.client.registry.counter(LHC::Prometheus.request_key, 'Counter of all LHC requests.')
    LHC::Prometheus.client.registry.histogram(LHC::Prometheus.times_key, 'Times for all LHC requests.')
    LHC::Prometheus.registered = true
  end

  def after_response
    return if !LHC::Prometheus.registered || LHC::Prometheus.client.blank?
    LHC::Prometheus.client.registry
      .get(LHC::Prometheus.request_key)
      .increment(
        code: response.code,
        success: response.success?,
        timeout: response.timeout?
      )
    LHC::Prometheus.client.registry
      .get(LHC::Prometheus.times_key)
      .observe({}, response.time_ms)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
lhc-10.1.2 lib/lhc/interceptors/prometheus.rb
lhc-10.1.1 lib/lhc/interceptors/prometheus.rb
lhc-10.1.0 lib/lhc/interceptors/prometheus.rb
lhc-10.0.2 lib/lhc/interceptors/prometheus.rb
lhc-9.4.4 lib/lhc/interceptors/prometheus.rb
lhc-10.0.1 lib/lhc/interceptors/prometheus.rb
lhc-10.0.0 lib/lhc/interceptors/prometheus.rb
lhc-9.4.3 lib/lhc/interceptors/prometheus.rb
lhc-9.4.2 lib/lhc/interceptors/prometheus.rb
lhc-9.4.1 lib/lhc/interceptors/prometheus.rb
lhc-9.4.0 lib/lhc/interceptors/prometheus.rb
lhc-9.3.1 lib/lhc/interceptors/prometheus.rb
lhc-9.3.0 lib/lhc/interceptors/prometheus.rb
lhc-9.2.0 lib/lhc/interceptors/prometheus.rb
lhc-9.1.2 lib/lhc/interceptors/prometheus.rb
lhc-9.1.2.pre lib/lhc/interceptors/prometheus.rb
lhc-9.1.1 lib/lhc/interceptors/prometheus.rb
lhc-8.1.1 lib/lhc/interceptors/prometheus.rb
lhc-9.1.0 lib/lhc/interceptors/prometheus.rb
lhc-9.0.0 lib/lhc/interceptors/prometheus.rb