heroku-unicorn-metrics 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/heroku/middleware.rb +4 -3
- data/lib/heroku/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -10,11 +10,11 @@ First, add `heroku-unicorn-metrics` to your Gemfile:
|
|
10
10
|
gem 'heroku-unicorn-metrics'
|
11
11
|
```
|
12
12
|
|
13
|
-
Then subscribe to the `unicorn.metrics.
|
13
|
+
Then 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:
|
14
14
|
|
15
15
|
```
|
16
16
|
# config/initializers/notifications.rb
|
17
|
-
ActiveSupport::Notifications.subscribe(/unicorn.metrics.
|
17
|
+
ActiveSupport::Notifications.subscribe(/unicorn.metrics.queue/) do |*args|
|
18
18
|
event = ActiveSupport::Notifications::Event.new(*args)
|
19
19
|
payload = event.payload
|
20
20
|
|
data/lib/heroku/middleware.rb
CHANGED
@@ -3,19 +3,20 @@ require 'socket'
|
|
3
3
|
module Heroku
|
4
4
|
module UnicornMetrics
|
5
5
|
class Queue
|
6
|
-
|
7
|
-
|
6
|
+
|
8
7
|
def initialize(app)
|
9
8
|
@app = app
|
10
9
|
end
|
11
10
|
|
12
11
|
def call(env)
|
12
|
+
return @app.call(env) unless ENV['PORT']
|
13
|
+
|
13
14
|
start_time = Time.now.to_f*1000.0
|
14
15
|
stats = raindrops_stats
|
15
16
|
|
16
17
|
status, headers, body = @app.call(env)
|
17
18
|
|
18
|
-
stats[:addr] =
|
19
|
+
stats[:addr] = IPSocket.getaddress(Socket.gethostname).to_s + ':'+ENV['PORT']
|
19
20
|
stats[:queue_time] = headers['X-Request-Start'] ? (start_time - headers['X-Request-Start'].to_f).round : 0
|
20
21
|
|
21
22
|
ActiveSupport::Notifications.instrument("unicorn.metrics.queue", stats)
|
data/lib/heroku/version.rb
CHANGED