Skip to content

Commit

Permalink
Accept exporter options (e.g. port), forward them to upstream
Browse files Browse the repository at this point in the history
For now there is only `port` option, see prometheus/client_ruby#199
  • Loading branch information
Envek committed Nov 8, 2022
1 parent 91e006b commit 7746697
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ And then execute:
use Yabeda::Prometheus::Exporter
```

Metrics will be available on `/metrics` path (configured by `:path` option).
Metrics will be available on `/metrics` path (configured by `:path` option), additionally metrics can be served only on specific port with `:port` option.

Also you can mount it in Rails application routes as standalone Rack application.
Alternatively you can mount it in Rails application routes as standalone Rack application:

```ruby
Rails.application.routes.draw do
mount Yabeda::Prometheus::Exporter, at: "/metrics"
end
```

Additional options (like `:port`) are also accepted and forwarded to [Prometheys Exporter](https://github.com/prometheus/client_ruby/blob/main/lib/prometheus/middleware/exporter.rb) middleware.

2. Run web-server from long-running processes (delayed jobs, …):

Expand Down
7 changes: 4 additions & 3 deletions lib/yabeda/prometheus/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Exporter < ::Prometheus::Middleware::Exporter
class << self
# Allows to use middleware as standalone rack application
def call(env)
@app ||= new(NOT_FOUND_HANDLER, path: "/")
options = env.fetch("action_dispatch.request.path_parameters", {})
@app ||= new(NOT_FOUND_HANDLER, path: "/", **options)
@app.call(env)
end

Expand All @@ -30,12 +31,12 @@ def start_metrics_server!(**rack_app_options)
end
end

def rack_app(exporter = self, path: "/metrics", logger: Logger.new(IO::NULL), use_deflater: true)
def rack_app(exporter = self, logger: Logger.new(IO::NULL), use_deflater: true, **exporter_options)
::Rack::Builder.new do
use ::Rack::Deflater if use_deflater
use ::Rack::CommonLogger, logger
use ::Rack::ShowExceptions
use exporter, path: path
use exporter, **exporter_options
run NOT_FOUND_HANDLER
end
end
Expand Down

0 comments on commit 7746697

Please sign in to comment.