Class | Raindrops::Middleware |
In: |
lib/raindrops/middleware.rb
(CVS)
|
Parent: | Object |
Raindrops::Middleware is Rack middleware that allows snapshotting current activity from an HTTP request. For all operating systems, it returns at least the following fields:
Additional fields are available for \Linux users.
It should be loaded at the top of Rack middleware stack before other middlewares for maximum accuracy.
If you‘re using preload_app=false (the default) in your Rainbows!/Unicorn config file, you‘ll need to create the global Stats object before forking.
require 'raindrops' $stats ||= Raindrops::Middleware::Stats.new
In your Rack config.ru:
use Raindrops::Middleware, :stats => $stats
If you‘re using preload_app=true in your Rainbows!/Unicorn config file, just add the middleware to your stack:
In your Rack config.ru:
use Raindrops::Middleware
To get bound listener statistics under \Linux, you need to specify the listener names for your server. You can even include listen sockets for other servers on the same machine. This can be handy for monitoring your nginx proxy as well.
In your Rack config.ru, just pass the :listeners argument as an array of strings (along with any other arguments). You can specify any combination of TCP or Unix domain socket names:
use Raindrops::Middleware, :listeners => %w(0.0.0.0:80 /tmp/.sock)
If you‘re running Unicorn 0.98.0 or later, you don‘t have to pass in the :listeners array, Raindrops will automatically detect the listeners used by Unicorn master process. This does not detect listeners in different processes, of course.
The response body includes the following stats for each listener (see also Raindrops::ListenStats):
There is a server running this middleware (and Watcher) at
http://raindrops-demo.bogomips.org/_raindrops
Also check out the Watcher demo at raindrops-demo.bogomips.org/
The demo server is only limited to 30 users, so be sure not to abuse it by using the /tail/ endpoint too much.
app may be any Rack application, this middleware wraps it. opts is a hash that understands the following members: