Class: LHC::Prometheus
- Inherits:
-
Interceptor
- Object
- Interceptor
- LHC::Prometheus
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/lhc/interceptors/prometheus.rb
Class Attribute Summary collapse
-
.registered ⇒ Object
Returns the value of attribute registered.
Attributes inherited from Interceptor
Class Method Summary collapse
Instance Method Summary collapse
- #after_response ⇒ Object
-
#initialize(request) ⇒ Prometheus
constructor
A new instance of Prometheus.
Methods inherited from Interceptor
#after_request, #before_raw_request, #before_request, #before_response, dup, #response
Constructor Details
#initialize(request) ⇒ Prometheus
Returns a new instance of Prometheus.
20 21 22 23 24 25 26 |
# File 'lib/lhc/interceptors/prometheus.rb', line 20 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 |
Class Attribute Details
.registered ⇒ Object
Returns the value of attribute registered.
9 10 11 |
# File 'lib/lhc/interceptors/prometheus.rb', line 9 def registered @registered end |
Class Method Details
.request_key ⇒ Object
12 13 14 |
# File 'lib/lhc/interceptors/prometheus.rb', line 12 def self.request_key [LHC::Prometheus.namespace, 'lhc_requests'].join('_').to_sym end |
.times_key ⇒ Object
16 17 18 |
# File 'lib/lhc/interceptors/prometheus.rb', line 16 def self.times_key [LHC::Prometheus.namespace, 'lhc_times'].join('_').to_sym end |
Instance Method Details
#after_response ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lhc/interceptors/prometheus.rb', line 28 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 |