class Prometheus::Client::Rack::Collector
Collector is a Rack middleware that provides a sample implementation of a HTTP tracer. The default label builder can be modified to export a different set of labels per recorded metric.
Constants
- DEFAULT_LABEL_BUILDER
Attributes
app[R]
registry[R]
Public Class Methods
new(app, options = {}, &label_builder)
click to toggle source
# File lib/prometheus/client/rack/collector.rb, line 13 def initialize(app, options = {}, &label_builder) @app = app @registry = options[:registry] || Client.registry @label_builder = label_builder || DEFAULT_LABEL_BUILDER init_request_metrics init_exception_metrics end
Protected Instance Methods
init_exception_metrics()
click to toggle source
# File lib/prometheus/client/rack/collector.rb, line 51 def init_exception_metrics @exceptions = @registry.counter( :http_exceptions_total, 'A counter of the total number of exceptions raised.', ) end
init_request_metrics()
click to toggle source
# File lib/prometheus/client/rack/collector.rb, line 36 def init_request_metrics @requests = @registry.counter( :http_requests_total, 'A counter of the total number of HTTP requests made.', ) @durations = @registry.summary( :http_request_duration_seconds, 'A summary of the response latency.', ) @durations_hist = @registry.histogram( :http_req_duration_seconds, 'A histogram of the response latency.', ) end
trace(env) { || ... }
click to toggle source
# File lib/prometheus/client/rack/collector.rb, line 58 def trace(env) start = Time.now yield.tap do |response| duration = (Time.now - start).to_f record(labels(env, response), duration) end