Class: RackMonitor::RequestStatus
- Inherits:
-
Object
- Object
- RackMonitor::RequestStatus
- Defined in:
- lib/rack_monitor.rb
Overview
Simple middleware to add a quick status URL for tools like Nagios.
Constant Summary collapse
- REQUEST_METHOD =
'REQUEST_METHOD'.freeze
- GET =
'GET'.freeze
- PATH_INFO =
'PATH_INFO'.freeze
- STATUS_PATH =
'/status'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, callback_or_response, status_path = nil) ⇒ RequestStatus
constructor
Initializes the middleware.
Constructor Details
#initialize(app, callback_or_response, status_path = nil) ⇒ RequestStatus
Initializes the middleware.
# Responds with "OK" on /status
use RequestStatus, "OK"
You can change what URL to look for:
use RequestStatus, "OK", "/ping"
You can also check internal systems and return something more informative.
use RequestStatus, lambda {
status = MyApp.status # A Hash of some live counters or something
[200, {"Content-Type" => "application/json"}, status.to_json]
}
app - The next Rack app in the pipeline. callback_or_response - Either a Proc or a Rack response. status_path - Optional String path that returns the status.
Default: "/status"
Returns nothing.
33 34 35 36 37 |
# File 'lib/rack_monitor.rb', line 33 def initialize(app, callback_or_response, status_path = nil) @app = app @status_path = (status_path || STATUS_PATH).freeze @callback = callback_or_response end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rack_monitor.rb', line 39 def call(env) if env[REQUEST_METHOD] == GET if env[PATH_INFO] == @status_path if @callback.respond_to?(:call) return @callback.call else return @callback end end end @app.call env end |