https://github.com/heroku/rack-queue-metrics
Rack server queue reporting
https://github.com/heroku/rack-queue-metrics
Last synced: 8 months ago
JSON representation
Rack server queue reporting
- Host: GitHub
- URL: https://github.com/heroku/rack-queue-metrics
- Owner: heroku
- License: mit
- Created: 2013-03-05T22:54:26.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2021-10-12T13:48:56.000Z (about 4 years ago)
- Last Synced: 2024-10-02T15:18:42.013Z (over 1 year ago)
- Language: Ruby
- Homepage: https://devcenter.heroku.com/articles/rails-unicorn
- Size: 26.4 KB
- Stars: 38
- Watchers: 108
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Rack Queue Metrics
Report on queued connections in any Rack-based server using [Raindrops](http://raindrops.bogomips.org/) and the [Raindrops::Linux](http://raindrops.bogomips.org/Raindrops/Linux.html) features.
## Usage
First, add `rack-queue-metrics` to your Gemfile:
```
gem 'rack-queue-metrics'
```
### Rails
You're done! If you want to instrument queue metrics beyond the default output, you can subscribe to the `rack.queue-metrics` notifcation in your Rails app. For example, to print queue information to your logs, add the following to `config/initializers/notifcations.rb:
```
# config/initializers/notifications.rb
ActiveSupport::Notifications.subscribe(/rack.queue-metrics/) do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
payload = event.payload
addr = payload[:addr]
active = payload[:requests][:active]
queued = payload[:requests][:queued]
queue_time = payload[:queue_time]
puts "STATS addr=#{addr} active=#{active} queued=#{queued} queue_time=#{queue_time} "
end
```
For more information, see the [ActiveSupport::Notification](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) docs.
### Sinatra/Rack Apps
Include the `Raindrops` and `Rack::QueueMetrics` middleware in your application's config.ru:
```
# config.ru
use Raindrops::Middleware
use Rack::QueueMetrics::Middleware
```
### Output
With every request, `rack-queue-metrics` will output a log line with the the following format:
```
at=metric measure=rack.queue-metrics addr=10.10.10.90:5000 queue_time=0 queue_depth=0
```
## Notifications
The following information is sent in the notification payload:
* `requests[:active]`: Number of requests currently being processed by the dyno at the start of the request
* `requests[:queued]`: Number of requests waiting to be processed at the start of the request
* `queue_time`: Amount of time the current request spent in the queue
* `addr`: Address of the dyno processing the request