Class: Vmpooler::Metrics::Promstats::CollectorMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/vmpooler/metrics/promstats/collector_middleware.rb

Overview

CollectorMiddleware is an implementation of Rack Middleware customised for vmpooler use.

By default metrics are registered on the global registry. Set the ‘:registry` option to use a custom registry.

By default metrics all have the prefix “http_server”. Set to something else if you like.

The request counter metric is broken down by code, method and path by default. Set the ‘:counter_label_builder` option to use a custom label builder.

The request duration metric is broken down by method and path by default. Set the ‘:duration_label_builder` option to use a custom label builder.

Label Builder functions will receive a Rack env and a status code, and must return a hash with the labels for that request. They must also accept an empty env, and return a hash with the correct keys. This is necessary to initialize the metrics with the correct set of labels.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ CollectorMiddleware

Returns a new instance of CollectorMiddleware.



44
45
46
47
48
49
50
51
# File 'lib/vmpooler/metrics/promstats/collector_middleware.rb', line 44

def initialize(app, options = {})
  @app = app
  @registry = options[:registry] || Prometheus::Client.registry
  @metrics_prefix = options[:metrics_prefix] || 'http_server'

  init_request_metrics
  init_exception_metrics
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



42
43
44
# File 'lib/vmpooler/metrics/promstats/collector_middleware.rb', line 42

def app
  @app
end

#registryObject (readonly)

Returns the value of attribute registry.



42
43
44
# File 'lib/vmpooler/metrics/promstats/collector_middleware.rb', line 42

def registry
  @registry
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



53
54
55
# File 'lib/vmpooler/metrics/promstats/collector_middleware.rb', line 53

def call(env) # :nodoc:
  trace(env) { @app.call(env) }
end