Sha256: 391c07a843e9bbea4a57828adbde80e575c62d926e5926f8577295227fcda81d

Contents?: true

Size: 1.15 KB

Versions: 17

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

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

17 entries across 17 versions & 1 rubygems

Version Path
lhc-10.5.4 lib/lhc/interceptors/prometheus.rb
lhc-10.5.3 lib/lhc/interceptors/prometheus.rb
lhc-10.5.2 lib/lhc/interceptors/prometheus.rb
lhc-10.5.1 lib/lhc/interceptors/prometheus.rb
lhc-10.5.0 lib/lhc/interceptors/prometheus.rb
lhc-10.4.3 lib/lhc/interceptors/prometheus.rb
lhc-10.4.2 lib/lhc/interceptors/prometheus.rb
lhc-10.4.1 lib/lhc/interceptors/prometheus.rb
lhc-10.4.0 lib/lhc/interceptors/prometheus.rb
lhc-10.3.0 lib/lhc/interceptors/prometheus.rb
lhc-10.2.1 lib/lhc/interceptors/prometheus.rb
lhc-10.2.0 lib/lhc/interceptors/prometheus.rb
lhc-10.1.8 lib/lhc/interceptors/prometheus.rb
lhc-10.1.7 lib/lhc/interceptors/prometheus.rb
lhc-10.1.6 lib/lhc/interceptors/prometheus.rb
lhc-10.1.5 lib/lhc/interceptors/prometheus.rb
lhc-10.1.3 lib/lhc/interceptors/prometheus.rb