rack-queue-metrics 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.md +59 -0
- data/lib/queue-metrics/middleware.rb +41 -0
- data/lib/queue-metrics/railtie.rb +10 -0
- data/lib/queue-metrics/version.rb +5 -0
- data/lib/rack-queue-metrics.rb +2 -0
- data/rack-queue-metrics.gemspec +20 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGM2N2FlNzhmYmZlYWI4ZmVlNTYwOTYzZDVhODljZTUzZTJjYWI3NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGNiZGRlMjAwM2QxNDJhZjAzMWM5OGQ0YzEwOTE2MmE3ZDZiMjQ2ZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODQ1ZmI1MjU2MDBhZDI0Y2FkNmFmN2EwMDg0ZGFjOWVkNDM1YWY0NjIyN2Y1
|
10
|
+
NmRkNTI5MTBkOWY5YzI5MGMxMGM3MGU4ZjQ1YTYwODk5MDdmM2NhMGYyZjZh
|
11
|
+
ZDMwNWM4OWI2MjVhMzY3ZmU5MTVjOGJmM2MxYWUxMGM2NmY0Mjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2I3ZGFjOTkyZDZjMmUxMDYyMmJiNjZmNDVlYTY3OWYxNjcwYWJmNTA3MjZm
|
14
|
+
OTQ5YjJiZDdhNTg4MTJhMzQ2ZDZmOGNkZmVmNDRkYzNkN2JkYjQwOGIzMTU4
|
15
|
+
ZGEzNjYwYzYzODEzMDQ2NTY2M2YzYzI4YTVjOWMyMTYwZjEyZjQ=
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Rack Queue Metrics
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
First, add `rack-queue-metrics` to your Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'rack-queue-metrics'
|
11
|
+
```
|
12
|
+
|
13
|
+
### Rails
|
14
|
+
|
15
|
+
You're done! If you want to instrument queue metrics beyond the default output, you can subscribe to the `unicorn.metrics.queue` notifcation in your Rails app. For example, to print queue information to your logs, add the following to `config/initializers/notifcations.rb:
|
16
|
+
|
17
|
+
```
|
18
|
+
# config/initializers/notifications.rb
|
19
|
+
ActiveSupport::Notifications.subscribe(/unicorn.metrics.queue/) do |*args|
|
20
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
21
|
+
payload = event.payload
|
22
|
+
|
23
|
+
addr = payload[:addr]
|
24
|
+
active = payload[:requests][:active]
|
25
|
+
queued = payload[:requests][:queued]
|
26
|
+
queue_time = payload[:queue_time]
|
27
|
+
|
28
|
+
puts "STATS addr=#{addr} active=#{active} queued=#{queued} queue_time=#{queue_time} "
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
For more information, see the [ActiveSupport::Notification](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) docs.
|
33
|
+
|
34
|
+
### Sinatra/Rack Apps
|
35
|
+
|
36
|
+
Include the `Raindrops` and `Rack::QueueMetrics` middleware in your application's config.ru:
|
37
|
+
|
38
|
+
```
|
39
|
+
# config.ru
|
40
|
+
use Raindrops::Middleware
|
41
|
+
use Rack::QueueMetrics::Middleware
|
42
|
+
```
|
43
|
+
|
44
|
+
### Output
|
45
|
+
|
46
|
+
With every request, `rack-queue-metrics` will output a log line with the the following format:
|
47
|
+
|
48
|
+
```
|
49
|
+
at=metric measure=rack.queue-metrics addr=10.10.10.90:5000 queue_time=0 queue_depth=0
|
50
|
+
```
|
51
|
+
|
52
|
+
## Notifications
|
53
|
+
|
54
|
+
The following information is sent in the notification payload:
|
55
|
+
|
56
|
+
* `requests[:active]`: Number of requests currently being processed by Unicorn at the start of the request
|
57
|
+
* `requests[:queued]`: Number of requests waiting to be processed at the start of the request
|
58
|
+
* `queue_time`: Amount of time the current request spent in the queue
|
59
|
+
* `addr`: Address of the dyno processing the request
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module QueueMetrics
|
5
|
+
class Middleware
|
6
|
+
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
return @app.call(env) unless ENV['PORT']
|
13
|
+
|
14
|
+
start_time = Time.now.to_f*1000.0
|
15
|
+
stats = raindrops_stats
|
16
|
+
|
17
|
+
status, headers, body = @app.call(env)
|
18
|
+
|
19
|
+
stats[:addr] = IPSocket.getaddress(Socket.gethostname).to_s + ':'+ENV['PORT']
|
20
|
+
stats[:queue_time] = headers['X-Request-Start'] ? (start_time - headers['X-Request-Start'].to_f).round : 0
|
21
|
+
|
22
|
+
puts "at=metric measure=rack.queue-metrics addr=#{stats[:addr]} queue_time=#{stats[:queue_time]} queue_depth=#{stats[:requests][:queued]}"
|
23
|
+
ActiveSupport::Notifications.instrument("rack.queue-metrics", stats) if defined?(ActiveSupport::Notifications)
|
24
|
+
|
25
|
+
[status, headers, body]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def raindrops_stats
|
31
|
+
if defined? Raindrops::Linux.tcp_listener_stats
|
32
|
+
stats = Raindrops::Linux.tcp_listener_stats([ '0.0.0.0:'+ENV['PORT'] ])['0.0.0.0:'+ENV['PORT']]
|
33
|
+
return { :requests => { :active => stats.active, :queued => stats.queued }}
|
34
|
+
else
|
35
|
+
return { :requests => { :active => 0, :queued => 0 }}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Rack
|
2
|
+
module QueueMetrics
|
3
|
+
class RackQueueRailtie < Rails::Railtie
|
4
|
+
initializer "rack_queue_railtie.configure_rails_initialization" do |app|
|
5
|
+
app.middleware.use Raindrops::Middleware
|
6
|
+
app.middleware.use Rack::QueueMetrics::Middleware
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "queue-metrics/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-queue-metrics"
|
7
|
+
s.version = Rack::QueueMetrics::VERSION
|
8
|
+
s.authors = ["dominic (Dominic Dagradi)"]
|
9
|
+
s.email = ["dominic@heroku.com"]
|
10
|
+
s.homepage = "http://github.com/heroku/rack-queue-metrics"
|
11
|
+
s.summary = %q{Measure queueing metrics for Rack apps}
|
12
|
+
s.description = %q{Measure queueing metrics for Rack apps}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency 'raindrops'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-queue-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dominic (Dominic Dagradi)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: raindrops
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Measure queueing metrics for Rack apps
|
28
|
+
email:
|
29
|
+
- dominic@heroku.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/queue-metrics/middleware.rb
|
36
|
+
- lib/queue-metrics/railtie.rb
|
37
|
+
- lib/queue-metrics/version.rb
|
38
|
+
- lib/rack-queue-metrics.rb
|
39
|
+
- rack-queue-metrics.gemspec
|
40
|
+
homepage: http://github.com/heroku/rack-queue-metrics
|
41
|
+
licenses: []
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.0.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Measure queueing metrics for Rack apps
|
63
|
+
test_files: []
|