woody.rb 0.2.5 → 0.2.6

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: 0787820d460a65b3ea7345c0c5846b2027ccf2e3
4
- data.tar.gz: b2804edff69de247ceb5b1653c50197bbca5ed02
3
+ metadata.gz: 89d86d35eab4b76f6ebcb074ebc2eab6308054ef
4
+ data.tar.gz: 3229cb03d45827cc885dc68df1077c1d3bbd228d
5
5
  SHA512:
6
- metadata.gz: 310cc9b62173019e0264667dcbafc8fd07cda03f366e3a3267783592d13b270efbe56a4e663c31a6b59a3f35e4ea333706a2c65fabeba87ce881fd4359e4ea38
7
- data.tar.gz: 775faf95a0c8a5724bc234836a941a62e763323c057f521f7426084587ddf768dc6aedb062d4b7dfdf17dc71f9a218a5833843bc33465e909c4fa6c721bb59b8
6
+ metadata.gz: 04bc2503261a01aaafe0734d97c5763de46279ab53e490c8224f5f83bff4acb32bc7c4764d170cf81bce2c4728880b9789b965b3bcaafcebaab75d270d337fe0
7
+ data.tar.gz: 3cde246d480c4efb4227556bb2c5844937e96d928865e44d490dbd7cd12e9e8ef4b2d422ba5ba1a0be0304aa5f70570ae20de0c1a297945c938c576a689f98a7
data/Makefile ADDED
@@ -0,0 +1,9 @@
1
+ TAG=$(shell cat lib/woody/version.rb | grep VERSION | sed 's/ VERSION = "\(.*\)"/\1/')
2
+ release:
3
+ @echo "Releasing woody $(TAG)"
4
+ git tag $(TAG) && \
5
+ git push origin $(TAG) && \
6
+ gem build woody.gemspec && \
7
+ gem push woody.rb-$(TAG).gem && \
8
+ rm woody.rb-$(TAG).gem
9
+
@@ -0,0 +1,12 @@
1
+ module Woody
2
+ module Statsd
3
+ module Sinatra
4
+ module Helpers
5
+ RACK_ENV_KEY = "nanit.statsd"
6
+ def statsd(stat)
7
+ request.env.merge!({ RACK_ENV_KEY => stat})
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,53 @@
1
+ require 'woody/statsd/client'
2
+ module Woody
3
+ module Statsd
4
+ module Sinatra
5
+ class Middleware
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ start_time = Time.now
13
+ status, headers, body = @app.call(env)
14
+ time_took = (1000 * (Time.now - start_time)).round
15
+ if stat = env[Helpers::RACK_ENV_KEY]
16
+ Reporter.report(stat, time_took, status)
17
+ end
18
+ [status, headers, body]
19
+ end
20
+
21
+ private
22
+
23
+ class Reporter
24
+
25
+ class << self
26
+ def report(stat, time_took, status)
27
+ new(stat, time_took, status).report
28
+ end
29
+ end
30
+
31
+ def initialize(stat, time_took, status)
32
+ @client = Woody::Statsd::Client.get
33
+ @base_metric = base_metric(stat)
34
+ @time = time_took
35
+ @status = status
36
+ end
37
+
38
+ def report
39
+ @client.increment "#{@base_metric}.requests"
40
+ @client.increment "#{@base_metric}.responses.#{@status}"
41
+ @client.timing "#{@base_metric}", @time
42
+ end
43
+
44
+ private
45
+
46
+ def base_metric(stat)
47
+ "web.#{stat}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/woody/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Woody
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woody.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chen Fisher
@@ -49,6 +49,7 @@ files:
49
49
  - ".travis.yml"
50
50
  - Gemfile
51
51
  - LICENSE.txt
52
+ - Makefile
52
53
  - README.md
53
54
  - Rakefile
54
55
  - bin/console
@@ -57,6 +58,8 @@ files:
57
58
  - lib/woody/influx.rb
58
59
  - lib/woody/logger.rb
59
60
  - lib/woody/statsd/client.rb
61
+ - lib/woody/statsd/sinatra/helpers.rb
62
+ - lib/woody/statsd/sinatra/middleware.rb
60
63
  - lib/woody/version.rb
61
64
  - woody.gemspec
62
65
  homepage: http://nanit.com