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 +4 -4
- data/Makefile +9 -0
- data/lib/woody/statsd/sinatra/helpers.rb +12 -0
- data/lib/woody/statsd/sinatra/middleware.rb +53 -0
- data/lib/woody/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89d86d35eab4b76f6ebcb074ebc2eab6308054ef
|
4
|
+
data.tar.gz: 3229cb03d45827cc885dc68df1077c1d3bbd228d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,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
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.
|
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
|