Sha256: 39b5c7cc3fab394d6a79e6e7eea08f84dc2054f7518b05562cd46f3a22cba811

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 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
    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(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-7.3.3 lib/lhc/interceptors/prometheus.rb
lhc-7.3.2 lib/lhc/interceptors/prometheus.rb
lhc-7.3.1 lib/lhc/interceptors/prometheus.rb
lhc-7.3.0 lib/lhc/interceptors/prometheus.rb
lhc-7.2.0 lib/lhc/interceptors/prometheus.rb
lhc-7.1.0 lib/lhc/interceptors/prometheus.rb
lhc-7.0.1 lib/lhc/interceptors/prometheus.rb
lhc-7.0.0 lib/lhc/interceptors/prometheus.rb
lhc-7.0.0.beta1 lib/lhc/interceptors/prometheus.rb
lhc-6.7.2 lib/lhc/interceptors/prometheus.rb
lhc-6.7.1 lib/lhc/interceptors/prometheus.rb
lhc-6.7.0 lib/lhc/interceptors/prometheus.rb
lhc-6.6.0.zipkin.pre.03 lib/lhc/interceptors/prometheus.rb
lhc-6.6.0.zipkin.pre.02 lib/lhc/interceptors/prometheus.rb
lhc-6.6.0.zipkin.pre.01 lib/lhc/interceptors/prometheus.rb
lhc-6.6.0.zipkin.pre lib/lhc/interceptors/prometheus.rb
lhc-6.6.0 lib/lhc/interceptors/prometheus.rb