class Yabeda::Prometheus::Mmap::Exporter
Rack application or middleware that provides metrics exposition endpoint
Constants
- NOT_FOUND_HANDLER
Public Class Methods
call(env)
click to toggle source
Allows to use middleware as standalone rack application
# File lib/yabeda/prometheus/mmap/exporter.rb, line 18 def call(env) @app ||= new(NOT_FOUND_HANDLER, path: '/') @app.call(env) end
new(app, options = {})
click to toggle source
Calls superclass method
# File lib/yabeda/prometheus/mmap/exporter.rb, line 45 def initialize(app, options = {}) super(app, options.merge(registry: Yabeda::Prometheus::Mmap.registry)) end
rack_app(exporter = self, path: '/metrics')
click to toggle source
# File lib/yabeda/prometheus/mmap/exporter.rb, line 35 def rack_app(exporter = self, path: '/metrics') ::Rack::Builder.new do use ::Rack::CommonLogger if ENV['PROMETHEUS_EXPORTER_LOG_REQUESTS'] != 'false' use ::Rack::ShowExceptions use exporter, path: path run NOT_FOUND_HANDLER end end
start_metrics_server!()
click to toggle source
# File lib/yabeda/prometheus/mmap/exporter.rb, line 23 def start_metrics_server! Thread.new do default_port = ENV.fetch('PORT', 9394) ::Rack::Handler::WEBrick.run( rack_app, Host: ENV['PROMETHEUS_EXPORTER_BIND'] || '0.0.0.0', Port: ENV.fetch('PROMETHEUS_EXPORTER_PORT', default_port), AccessLog: [] ) end end
Public Instance Methods
call(env)
click to toggle source
Calls superclass method
# File lib/yabeda/prometheus/mmap/exporter.rb, line 49 def call(env) ::Yabeda.collect! if env['PATH_INFO'] == path if ::Yabeda.debug? result = nil ::Yabeda.yabeda_prometheus_mmap.render_duration.measure({}) do result = super end result else super end end