puma-stats-logger 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 951d3d4c27b7e5c9cb3b6a2ef6d63e223d75ebe0
4
- data.tar.gz: 8e7e9acbd2b7d7ae4c39313a1bc9092d15a16e8f
3
+ metadata.gz: 791f449b3f7c87b41b434c8caa87be42192f741e
4
+ data.tar.gz: a13f557ed65e1947233ebd90722e8ce471492bae
5
5
  SHA512:
6
- metadata.gz: b672425a657f0019241bda6f90cf8e5ca2d5e94b6ee71091f76c7eb1fa3dd0775a2e5a1038d1ca0e334ae966c4b25eb6830819fd43f4059735464014ca9c4c9c
7
- data.tar.gz: 9f27c582b874caf89e6ef93789e28eeca74a3f00ed83c9d0df79514bd71a5e8be9c1c29be55172522b8ed66ab3d77477dddf0c787060ce1b5fb2f1e83d970b6e
6
+ metadata.gz: 4276834c44a84082a2123b65b085c24c021de20ff162e005bb3bc5b3cd2f40793c4a9dfcf48c98b17ed3632b4fe9f45b81e5f6f12b60502b9f5adf59c444f5b4
7
+ data.tar.gz: eea74cfd3692741243d6046d763c1575b5ec5cf351add44937f5f97e1374ce2f152dc552607639ef3c53a519b75683a18d37397a445591f29ac9db3c803e93ac
data/README.md CHANGED
@@ -1,4 +1,67 @@
1
- puma-stats-logger
2
- =================
1
+ ## Puma Stats Logger
2
+
3
+ #### For Rack apps (including Rails)
4
+
5
+ This Rack middleware gathers statistics from [Puma](http://puma.io/) web server and logs them to the logging destination of your choice. It uses Puma's built in control server to query Puma's stats after every request in your production application. Currently, Puma provides two metrics that are output to your logs:
6
+
7
+ * __running__ - the number of threads currently running
8
+ * __backlog__ - the number of requests waiting to be processed by a thread
9
+
10
+ The actual log entry looks like this:
11
+
12
+ measure#puma.backlog=0 measure#puma.running=6
13
+
14
+
15
+ ## Getting Started
16
+
17
+ Add the gem to your gemfile:
18
+
19
+ gem 'puma-stats-logger'
20
+
21
+ ##### Enable Puma's control/stats server & state file
22
+
23
+ If you use a Puma configuration file, add the following two lines:
24
+
25
+ # in config/puma.rb
26
+
27
+ activate_control_app
28
+ state_path 'tmp/puma.state'
29
+
30
+ OR ... if you don't use a Puma config file and you start Puma via command line, add these options:
31
+
32
+ puma --control auto --state "tmp/puma.state"
33
+
34
+ ##### Activate the Middleware in your app
35
+
36
+ In your application and/or environment config:
37
+
38
+ config.middleware.use PumaStatsLogger::Middleware
39
+
40
+ or in a Rails initializer:
41
+
42
+ Rails.application.middleware.use PumaStatsLogger::Middleware
43
+
44
+
45
+ ##### Changing the logging destination
46
+
47
+ By default, the Puma stats are logged to standard output `$stdout`. This works great out of the box for Heroku users. You can customize this by passing an option hash:
48
+
49
+ config.middleware.use PumaStatsLogger::Middleware, logger: Logger.new('destination/puma-stats.log')
50
+
51
+
52
+ ## Visualizing Results
53
+
54
+ We use the Librato add-on on Heroku to make nice charts of this data. You may have noticed that the log output is already formatted for Librato, so if you're already using Librato, Puma metrics should show up automatically under Metrics.
55
+
56
+ ![Puma stats in Librato](https://dmrxx81gnj0ct.cloudfront.net/public/Screen+Shot+2014-05-29+at+5.19.18+PM.png "Puma stats in Librato")
57
+
58
+ ## Open Source by Hired
59
+
60
+ [Hired](https://hired.com/?utm_source=opensource&utm_medium=puma-stats-logger&utm_campaign=readme) is a marketplace for top engineering talent to find full-time technology jobs. Talented Ruby developers (like yourself) are in extremely high demand! On Hired, apply once and receive 5 to 15 competing job offers in one week from 800+ technology companies. Average Ruby engineer salaries on Hired are around $120,000 per year!
61
+
62
+ <a href="https://hired.com/?utm_source=opensource&utm_medium=puma-stats-logger&utm_campaign=readme-banner" target="_blank">
63
+ <img src="https://dmrxx81gnj0ct.cloudfront.net/public/hired-banner-light-1-728x90.png" alt="Hired" width="728" height="90" align="center"/>
64
+ </a>
65
+
66
+ We are Ruby developers ourselves, and we use all of our open source projects in production. We always encourge forks, pull requests, and issues. Get in touch with the Hired Engineering team at _opensource@hired.com_.
3
67
 
4
- A Rack middleware that collects stats from Puma webserver and outputs them for logging
@@ -31,7 +31,12 @@ module PumaStatsLogger
31
31
  end
32
32
 
33
33
  stats = JSON.parse(stats.split("\r\n").last)
34
- @logger.info stats.map{|k,v| "measure#puma.#{k}=#{v}"}.join(' ')
34
+ line = String.new.tap do |s|
35
+ s << "source=#{ENV['DYNO']}" if ENV['DYNO']
36
+ s << stats.map{|k,v| "measure#puma.#{k}=#{v}"}.join(' ')
37
+ end
38
+
39
+ @logger.info line
35
40
  end
36
41
  end
37
42
  end
@@ -1,3 +1,3 @@
1
1
  module PumaStatsLogger
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -18,7 +18,7 @@ describe PumaStatsLogger::Middleware do
18
18
  FileUtils.cp './spec/files/puma.state', 'tmp/puma.state'
19
19
 
20
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(
21
+ expect(Socket).to receive(:unix).with('/var/folders/_h/30bzldts3gj3n2tknnzcqsl40000gn/T/puma-status-1401402163005-57709').and_return(
22
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
23
  )
24
24
  end
@@ -31,6 +31,12 @@ describe PumaStatsLogger::Middleware do
31
31
  get "/"
32
32
  expect(log_output.string).to include('measure#puma.backlog=0 measure#puma.running=1')
33
33
  end
34
+
35
+ it "includes Heroku dyno information" do
36
+ ENV['DYNO'] = 'web.1'
37
+ get "/"
38
+ expect(log_output.string).to include('source=web.1')
39
+ end
34
40
  end
35
41
 
36
42
  context 'when a Puma state file does not exist' do
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'rspec/autorun'
1
+ require 'rspec'
2
2
  require 'rack/test'
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), '../lib/puma-stats-logger'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma-stats-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hired, Inc
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-29 00:00:00.000000000 Z
12
+ date: 2015-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake