Class: PrometheusMiddleware
- Inherits:
-
Object
- Object
- PrometheusMiddleware
- Defined in:
- lib/macaw_framework/middlewares/prometheus_middleware.rb
Overview
Middleware responsible to configure prometheus defining metrics and an endpoint to access them.
Instance Attribute Summary collapse
-
#request_count ⇒ Object
Returns the value of attribute request_count.
-
#request_duration_milliseconds ⇒ Object
Returns the value of attribute request_duration_milliseconds.
-
#response_count ⇒ Object
Returns the value of attribute response_count.
Instance Method Summary collapse
Instance Attribute Details
#request_count ⇒ Object
Returns the value of attribute request_count.
10 11 12 |
# File 'lib/macaw_framework/middlewares/prometheus_middleware.rb', line 10 def request_count @request_count end |
#request_duration_milliseconds ⇒ Object
Returns the value of attribute request_duration_milliseconds.
10 11 12 |
# File 'lib/macaw_framework/middlewares/prometheus_middleware.rb', line 10 def request_duration_milliseconds @request_duration_milliseconds end |
#response_count ⇒ Object
Returns the value of attribute response_count.
10 11 12 |
# File 'lib/macaw_framework/middlewares/prometheus_middleware.rb', line 10 def response_count @response_count end |
Instance Method Details
#configure_prometheus(prometheus_registry, configurations, macaw) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/macaw_framework/middlewares/prometheus_middleware.rb', line 12 def configure_prometheus(prometheus_registry, configurations, macaw) return nil unless prometheus_registry @request_duration_milliseconds = Prometheus::Client::Histogram.new( :request_duration_milliseconds, docstring: 'The duration of each request in milliseconds', labels: [:endpoint], buckets: (100..1000).step(100).to_a + (2000..10_000).step(1000).to_a ) @request_count = Prometheus::Client::Counter.new( :request_count, docstring: 'The total number of requests received', labels: [:endpoint] ) @response_count = Prometheus::Client::Counter.new( :response_count, docstring: 'The total number of responses sent', labels: %i[endpoint status] ) prometheus_registry.register(@request_duration_milliseconds) prometheus_registry.register(@request_count) prometheus_registry.register(@response_count) prometheus_endpoint(prometheus_registry, configurations, macaw) end |