puma-stats-logger 0.1.0
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 +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/lib/puma-stats-logger.rb +6 -0
- data/lib/puma_stats_logger/middleware.rb +37 -0
- data/lib/puma_stats_logger/version.rb +3 -0
- data/puma-stats-logger.gemspec +28 -0
- data/spec/files/puma.state +21 -0
- data/spec/middleware_spec.rb +42 -0
- data/spec/spec_helper.rb +4 -0
- data/tmp/.gitkeep +0 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 951d3d4c27b7e5c9cb3b6a2ef6d63e223d75ebe0
|
4
|
+
data.tar.gz: 8e7e9acbd2b7d7ae4c39313a1bc9092d15a16e8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b672425a657f0019241bda6f90cf8e5ca2d5e94b6ee71091f76c7eb1fa3dd0775a2e5a1038d1ca0e334ae966c4b25eb6830819fd43f4059735464014ca9c4c9c
|
7
|
+
data.tar.gz: 9f27c582b874caf89e6ef93789e28eeca74a3f00ed83c9d0df79514bd71a5e8be9c1c29be55172522b8ed66ab3d77477dddf0c787060ce1b5fb2f1e83d970b6e
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
puma-stats-logger (0.1.0)
|
5
|
+
json
|
6
|
+
puma
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
json (1.8.1)
|
13
|
+
puma (2.8.2)
|
14
|
+
rack (>= 1.1, < 2.0)
|
15
|
+
rack (1.5.2)
|
16
|
+
rack-test (0.6.2)
|
17
|
+
rack (>= 1.0)
|
18
|
+
rake (10.3.2)
|
19
|
+
rspec (2.14.1)
|
20
|
+
rspec-core (~> 2.14.0)
|
21
|
+
rspec-expectations (~> 2.14.0)
|
22
|
+
rspec-mocks (~> 2.14.0)
|
23
|
+
rspec-core (2.14.8)
|
24
|
+
rspec-expectations (2.14.5)
|
25
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
26
|
+
rspec-mocks (2.14.6)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
puma-stats-logger!
|
33
|
+
rack-test
|
34
|
+
rake
|
35
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Hired, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module PumaStatsLogger
|
2
|
+
class Middleware
|
3
|
+
def initialize(app, options = {})
|
4
|
+
@app = app
|
5
|
+
@logger = options[:logger] || Logger.new($stdout)
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
status, headers, body = @app.call(env)
|
10
|
+
log_puma_stats if puma_options
|
11
|
+
[status, headers, body]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def puma_options
|
17
|
+
@puma_options ||= begin
|
18
|
+
return nil unless File.exists?(puma_state_file)
|
19
|
+
YAML.load_file(puma_state_file)['config'].options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def puma_state_file
|
24
|
+
'tmp/puma.state'
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_puma_stats
|
28
|
+
stats = Socket.unix(puma_options[:control_url].gsub('unix://', '')) do |socket|
|
29
|
+
socket.print("GET /stats?token=#{puma_options[:control_auth_token]} HTTP/1.0\r\n\r\n")
|
30
|
+
socket.read
|
31
|
+
end
|
32
|
+
|
33
|
+
stats = JSON.parse(stats.split("\r\n").last)
|
34
|
+
@logger.info stats.map{|k,v| "measure#puma.#{k}=#{v}"}.join(' ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'puma_stats_logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "puma-stats-logger"
|
8
|
+
spec.version = PumaStatsLogger::VERSION
|
9
|
+
spec.authors = ["Hired, Inc", "Nate Clark"]
|
10
|
+
spec.email = ["opensource@hired.com"]
|
11
|
+
spec.summary = %q{A Rack middleware that collects stats from Puma webserver and outputs them for logging }
|
12
|
+
spec.description = %q{A Rack middleware that collects stats from Puma webserver and outputs them for logging }
|
13
|
+
spec.homepage = "https://github.com/hired/puma-stats-logger"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rack-test"
|
24
|
+
|
25
|
+
spec.add_dependency "json"
|
26
|
+
spec.add_dependency "puma"
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
pid: 57709
|
3
|
+
config: !ruby/object:Puma::Configuration
|
4
|
+
options:
|
5
|
+
:min_threads: 0
|
6
|
+
:max_threads: 10
|
7
|
+
:quiet: false
|
8
|
+
:debug: false
|
9
|
+
:binds:
|
10
|
+
- tcp://0.0.0.0:3000
|
11
|
+
:workers: 0
|
12
|
+
:daemon: false
|
13
|
+
:worker_directory: "/Users/nate/workspace/hired"
|
14
|
+
:config_file: config/puma.rb
|
15
|
+
:mode: :http
|
16
|
+
:worker_timeout: 60
|
17
|
+
:environment: development
|
18
|
+
:control_url: unix:///var/folders/_h/30bzldts3gj3n2tknnzcqsl40000gn/T/puma-status-1401402163005-57709
|
19
|
+
:state: tmp/puma.state
|
20
|
+
:control_url_temp: "/var/folders/_h/30bzldts3gj3n2tknnzcqsl40000gn/T/puma-status-1401402163005-57709"
|
21
|
+
:control_auth_token: a56928e2d78ffb8879a937d35b78510
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PumaStatsLogger::Middleware do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
class SampleApplication
|
7
|
+
def call(env)
|
8
|
+
[200, {}, ""]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:app) { PumaStatsLogger::Middleware.new(SampleApplication.new, logger: logger) }
|
13
|
+
let(:logger) { Logger.new(log_output)}
|
14
|
+
let(:log_output) { StringIO.new }
|
15
|
+
|
16
|
+
context 'when a Puma state file exists' do
|
17
|
+
before do
|
18
|
+
FileUtils.cp './spec/files/puma.state', 'tmp/puma.state'
|
19
|
+
|
20
|
+
# stub what the Puma stats server would return
|
21
|
+
Socket.should_receive(:unix).with('/var/folders/_h/30bzldts3gj3n2tknnzcqsl40000gn/T/puma-status-1401402163005-57709').and_return(
|
22
|
+
"HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nConnection: close\r\nContent-Length: 30\r\n\r\n{ \"backlog\": 0, \"running\": 1 }"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
FileUtils.rm './tmp/puma.state'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "outputs the puma stats" do
|
31
|
+
get "/"
|
32
|
+
expect(log_output.string).to include('measure#puma.backlog=0 measure#puma.running=1')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when a Puma state file does not exist' do
|
37
|
+
it "does nothing" do
|
38
|
+
get "/"
|
39
|
+
expect(log_output.string).to be_empty
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tmp/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puma-stats-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hired, Inc
|
8
|
+
- Nate Clark
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rack-test
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: json
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: puma
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: 'A Rack middleware that collects stats from Puma webserver and outputs
|
85
|
+
them for logging '
|
86
|
+
email:
|
87
|
+
- opensource@hired.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
- lib/puma-stats-logger.rb
|
99
|
+
- lib/puma_stats_logger/middleware.rb
|
100
|
+
- lib/puma_stats_logger/version.rb
|
101
|
+
- puma-stats-logger.gemspec
|
102
|
+
- spec/files/puma.state
|
103
|
+
- spec/middleware_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- tmp/.gitkeep
|
106
|
+
homepage: https://github.com/hired/puma-stats-logger
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: A Rack middleware that collects stats from Puma webserver and outputs them
|
130
|
+
for logging
|
131
|
+
test_files:
|
132
|
+
- spec/files/puma.state
|
133
|
+
- spec/middleware_spec.rb
|
134
|
+
- spec/spec_helper.rb
|