Module: Emrb
- Defined in:
- lib/emrb.rb,
lib/emrb/server.rb,
lib/emrb/version.rb,
lib/emrb/instruments/state.rb,
lib/emrb/instruments/exporters.rb,
lib/emrb/instruments/instruments.rb
Overview
Emrb provides a facility for instrumenting applications with prometheus metrics. All instruments can be used the same way as in prometheus-client, and are registered within the same registry. Both Prometheus::Middleware::Collector and Prometheus::Middleware::Exporter can be accessed using Emrb::Collector and Emrb::Exporter.
Defined Under Namespace
Modules: Instruments
Constant Summary collapse
- VERSION =
"0.1.5"
- Exporter =
Rack middleware that provides a sample implementation of a Prometheus HTTP exposition endpoint.
By default it will export the state of the global registry and expose it under ‘/metrics`. Use the `:registry` and `:path` options to change the defaults. Original source: github.com/prometheus/client_ruby/blob/main/lib/prometheus/middleware/exporter.rb
Prometheus::Middleware::Exporter
- Collector =
Rack middleware that provides a sample implementation of a HTTP tracer.
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 ‘:metrics_prefix` to something else if you like.
The request counter metric is broken down by code, method and path. The request duration metric is broken down by method and path. Original source: github.com/prometheus/client_ruby/blob/main/lib/prometheus/middleware/collector.rb
Prometheus::Middleware::Collector
Class Method Summary collapse
-
.expose_metrics(port, address = "0.0.0.0") ⇒ Object
expose_metrics starts a simple sinatra server on a given port and address that exposes a single /metrics endpoint for scrapers to access.
-
.stop_exposing_metrics ⇒ Object
Stops the metrics server previously started by #expose_metrics.
Class Method Details
.expose_metrics(port, address = "0.0.0.0") ⇒ Object
expose_metrics starts a simple sinatra server on a given port and address that exposes a single /metrics endpoint for scrapers to access. It is a courtesy utility for applications not exposing an HTTP server by default.
To use this method, the application calling it must bundle both sinatra and puma gems.
port - Port to expose the server address - Address to expose the server. Defaults to ‘0.0.0.0`.
Returns nothing.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/emrb/server.rb', line 34 def self.expose_metrics(port, address = "0.0.0.0") return if @metrics_app metrics_app = Class.new(Sinatra::Base) do set :bind, address set :port, port use Emrb::Exporter use Rack::Deflater end @metrics_app = metrics_app.new puma_server = Puma::Server.new(metrics_app) puma_server.add_tcp_listener(address, port) @puma_server = puma_server @metrics_thr = Thread.new { puma_server.run } end |
.stop_exposing_metrics ⇒ Object
Stops the metrics server previously started by #expose_metrics.
Returns nothing.
54 55 56 57 58 59 |
# File 'lib/emrb/server.rb', line 54 def self.stop_exposing_metrics return unless @metrics_app @puma_server.stop(true) @metrics_thr.join end |