heroku-unicorn-metrics 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -0
- data/heroku-unicorn-metrics.gemspec +21 -0
- data/lib/heroku-unicorn-metrics.rb +2 -0
- data/lib/heroku/middleware.rb +39 -0
- data/lib/heroku/railtie.rb +10 -0
- data/lib/heroku/version.rb +5 -0
- metadata +83 -0
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Heroku Unicorn Metrics
|
2
|
+
|
3
|
+
Report on Unicorn queued connections 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 `heroku-unicorn-metrics` to your Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'heroku-unicorn-metrics'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then subscribe to the `unicorn.metrics.request` notifcation in your Rails app. For example, to print queue information to your logs, add the following to `config/initializers/notifcations.rb:
|
14
|
+
|
15
|
+
```
|
16
|
+
# config/initializers/notifications.rb
|
17
|
+
ActiveSupport::Notifications.subscribe(/unicorn.metrics.request/) do |*args|
|
18
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
19
|
+
payload = event.payload
|
20
|
+
|
21
|
+
addr = payload[:addr]
|
22
|
+
active = payload[:requests][:active]
|
23
|
+
queued = payload[:requests][:queued]
|
24
|
+
queue_time = payload[:queue_time]
|
25
|
+
|
26
|
+
puts "STATS addr=#{addr} active=#{active} queued=#{queued} queue_time=#{queue_time} "
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
For more information, see the [ActiveSupport::Notification](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) docs.
|
31
|
+
|
32
|
+
## Data
|
33
|
+
|
34
|
+
The following information is sent in the notification payload:
|
35
|
+
|
36
|
+
* `requests[:active]`: Number of requests currently being processed by Unicorn at the start of the request
|
37
|
+
* `requests[:queued]`: Number of requests waiting to be processed at the start of the request
|
38
|
+
* `queue_time`: Amount of time the current request spent in the queue
|
39
|
+
* `addr`: Address of the dyno processing the request
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "heroku/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "heroku-unicorn-metrics"
|
7
|
+
s.version = Heroku::UnicornMetrics::VERSION
|
8
|
+
s.authors = ["dominic (Dominic Dagradi)"]
|
9
|
+
s.email = ["dominic@heroku.com"]
|
10
|
+
s.homepage = "http://github.com/heroku/heroku-unicorn-metrics"
|
11
|
+
s.summary = %q{Additional metrics for Heroku apps using Unicorn}
|
12
|
+
s.description = %q{Additional metrics for Heroku apps using Unicorn}
|
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 'unicorn'
|
20
|
+
s.add_dependency 'rails', ">= 3.0"
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Heroku
|
4
|
+
module UnicornMetrics
|
5
|
+
class Queue
|
6
|
+
ADDR = IPSocket.getaddress(Socket.gethostname).to_s+':'+ENV['PORT']
|
7
|
+
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
start_time = Time.now.to_f*1000.0
|
14
|
+
stats = raindrops_stats
|
15
|
+
|
16
|
+
status, headers, body = @app.call(env)
|
17
|
+
|
18
|
+
stats[:addr] = ADDR
|
19
|
+
stats[:queue_time] = headers['X-Request-Start'] ? (start_time - headers['X-Request-Start'].to_f).round : 0
|
20
|
+
|
21
|
+
ActiveSupport::Notifications.instrument("unicorn.metrics.queue", stats)
|
22
|
+
|
23
|
+
[status, headers, body]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def raindrops_stats
|
29
|
+
if defined? Raindrops::Linux.tcp_listener_stats
|
30
|
+
stats = Raindrops::Linux.tcp_listener_stats([ '0.0.0.0:'+ENV['PORT'] ])['0.0.0.0:'+ENV['PORT']]
|
31
|
+
return { :requests => { :active => stats.active, :queued => stats.queued }}
|
32
|
+
else
|
33
|
+
return { :requests => { :active => 0, :queued => 0 }}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Heroku
|
2
|
+
module UnicornMetrics
|
3
|
+
class UnicornMetricsRailtie < Rails::Railtie
|
4
|
+
initializer "my_railtie.configure_rails_initialization" do |app|
|
5
|
+
app.middleware.use Raindrops::Middleware
|
6
|
+
app.middleware.use Heroku::UnicornMetrics::Queue
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku-unicorn-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- dominic (Dominic Dagradi)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: unicorn
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
description: Additional metrics for Heroku apps using Unicorn
|
47
|
+
email:
|
48
|
+
- dominic@heroku.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- README.md
|
54
|
+
- heroku-unicorn-metrics.gemspec
|
55
|
+
- lib/heroku-unicorn-metrics.rb
|
56
|
+
- lib/heroku/middleware.rb
|
57
|
+
- lib/heroku/railtie.rb
|
58
|
+
- lib/heroku/version.rb
|
59
|
+
homepage: http://github.com/heroku/heroku-unicorn-metrics
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.24
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Additional metrics for Heroku apps using Unicorn
|
83
|
+
test_files: []
|