fozzie 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +5 -5
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -5
  6. data/Gemfile +3 -3
  7. data/README.md +288 -276
  8. data/Rakefile +6 -6
  9. data/fozzie.gemspec +29 -29
  10. data/fozzie.yml.example +14 -14
  11. data/lib/core_ext/hash/symbolize_keys.rb +21 -21
  12. data/lib/core_ext/module/alias_method_chain.rb +19 -19
  13. data/lib/core_ext/module/monitor.rb +12 -12
  14. data/lib/core_ext/string/snakecase.rb +9 -9
  15. data/lib/fozzie.rb +67 -67
  16. data/lib/fozzie/adapter/statsd.rb +95 -95
  17. data/lib/fozzie/bulk_dsl.rb +27 -27
  18. data/lib/fozzie/configuration.rb +1 -0
  19. data/lib/fozzie/dsl.rb +18 -18
  20. data/lib/fozzie/exception.rb +4 -4
  21. data/lib/fozzie/interface.rb +139 -139
  22. data/lib/fozzie/rack/middleware.rb +43 -43
  23. data/lib/fozzie/sniff.rb +49 -49
  24. data/lib/fozzie/version.rb +3 -3
  25. data/resources/mill.js.example +26 -26
  26. data/spec/config/fozzie.yml +5 -5
  27. data/spec/lib/core_ext/module/monitor_spec.rb +8 -8
  28. data/spec/lib/fozzie/adapter/statsd_spec.rb +82 -82
  29. data/spec/lib/fozzie/bulk_dsl_spec.rb +46 -46
  30. data/spec/lib/fozzie/configuration_spec.rb +125 -125
  31. data/spec/lib/fozzie/dsl_spec.rb +15 -15
  32. data/spec/lib/fozzie/rack/middleware_spec.rb +69 -69
  33. data/spec/lib/fozzie/rack/sinatra_spec.rb +30 -30
  34. data/spec/lib/fozzie/sniff_spec.rb +131 -131
  35. data/spec/lib/fozzie/version_spec.rb +9 -9
  36. data/spec/lib/fozzie_spec.rb +39 -39
  37. data/spec/shared_examples/fozzie_adapter.rb +7 -7
  38. data/spec/shared_examples/interface.rb +159 -159
  39. data/spec/spec_helper.rb +28 -28
  40. metadata +24 -36
  41. data/.rvmrc +0 -1
@@ -1,28 +1,28 @@
1
- module Fozzie
2
- class BulkDsl
3
- include Fozzie::Interface
4
-
5
- def initialize(&block)
6
- @metrics = []
7
- block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
8
- send_bulk
9
- end
10
-
11
- private
12
-
13
- # Cache the requested metrics for bulk sending
14
- #
15
- def send(stat, value, type, sample_rate = 1)
16
- val = { :bin => stat, :value => value, :type => type, :sample_rate => sample_rate }
17
-
18
- @metrics.push(val)
19
- end
20
-
21
- def send_bulk
22
- return if @metrics.empty?
23
-
24
- adapter.register(@metrics)
25
- end
26
-
27
- end
1
+ module Fozzie
2
+ class BulkDsl
3
+ include Fozzie::Interface
4
+
5
+ def initialize(&block)
6
+ @metrics = []
7
+ block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
8
+ send_bulk
9
+ end
10
+
11
+ private
12
+
13
+ # Cache the requested metrics for bulk sending
14
+ #
15
+ def send(stat, value, type, sample_rate = 1)
16
+ val = { :bin => stat, :value => value, :type => type, :sample_rate => sample_rate }
17
+
18
+ @metrics.push(val)
19
+ end
20
+
21
+ def send_bulk
22
+ return if @metrics.empty?
23
+
24
+ adapter.register(@metrics)
25
+ end
26
+
27
+ end
28
28
  end
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'sys/uname'
3
3
  require 'timeout'
4
+ require 'forwardable'
4
5
 
5
6
  module Fozzie
6
7
 
@@ -1,19 +1,19 @@
1
- require 'singleton'
2
- require "fozzie/interface"
3
-
4
- module Fozzie
5
- class Dsl
6
- include Fozzie::Interface, Singleton
7
-
8
- private
9
-
10
- # Send the statistic to the chosen provider
11
- #
12
- def send(stat, value, type, sample_rate = 1)
13
- val = { :bin => stat, :value => value, :type => type, :sample_rate => sample_rate }
14
-
15
- adapter.register(val)
16
- end
17
-
18
- end
1
+ require 'singleton'
2
+ require "fozzie/interface"
3
+
4
+ module Fozzie
5
+ class Dsl
6
+ include Fozzie::Interface, Singleton
7
+
8
+ private
9
+
10
+ # Send the statistic to the chosen provider
11
+ #
12
+ def send(stat, value, type, sample_rate = 1)
13
+ val = { :bin => stat, :value => value, :type => type, :sample_rate => sample_rate }
14
+
15
+ adapter.register(val)
16
+ end
17
+
18
+ end
19
19
  end
@@ -1,5 +1,5 @@
1
- module Fozzie
2
-
3
- class AdapterMissing < StandardError; end
4
-
1
+ module Fozzie
2
+
3
+ class AdapterMissing < StandardError; end
4
+
5
5
  end
@@ -1,140 +1,140 @@
1
- require 'fozzie/adapter/statsd'
2
-
3
- module Fozzie
4
- module Interface
5
-
6
- # Increments the given stat by one, with an optional sample rate
7
- #
8
- # `Stats.increment 'wat'`
9
- def increment(stat, sample_rate=1)
10
- count(stat, 1, sample_rate)
11
- end
12
-
13
- # Decrements the given stat by one, with an optional sample rate
14
- #
15
- # `Stats.decrement 'wat'`
16
- def decrement(stat, sample_rate=1)
17
- count(stat, -1, sample_rate)
18
- end
19
-
20
- # Registers a count for the given stat, with an optional sample rate
21
- #
22
- # `Stats.count 'wat', 500`
23
- def count(stat, count, sample_rate=1)
24
- send(stat, count, :count, sample_rate)
25
- end
26
-
27
- # Registers a timing (in ms) for the given stat, with an optional sample rate
28
- #
29
- # `Stats.timing 'wat', 500`
30
- def timing(stat, ms, sample_rate=1)
31
- send(stat, ms, :timing, sample_rate)
32
- end
33
-
34
- # Registers the time taken to complete a given block (in ms), with an optional sample rate
35
- #
36
- # `Stats.time 'wat' { # Do something... }`
37
- def time(stat, sample_rate=1)
38
- start = Time.now
39
- result = yield
40
- timing(stat, ((Time.now - start) * 1000).round, sample_rate)
41
- result
42
- end
43
-
44
- # Registers the time taken to complete a given block (in ms), with an optional sample rate
45
- #
46
- # `Stats.time_to_do 'wat' { # Do something, again... }`
47
- def time_to_do(stat, sample_rate=1, &block)
48
- time(stat, sample_rate, &block)
49
- end
50
-
51
- # Registers the time taken to complete a given block (in ms), with an optional sample rate
52
- #
53
- # `Stats.time_for 'wat' { # Do something, grrr... }`
54
- def time_for(stat, sample_rate=1, &block)
55
- time(stat, sample_rate, &block)
56
- end
57
-
58
- # Registers a commit
59
- #
60
- # `Stats.commit`
61
- def commit
62
- event :commit
63
- end
64
-
65
- # Registers a commit
66
- #
67
- # `Stats.commit`
68
- def committed
69
- commit
70
- end
71
-
72
- # Registers that the app has been built
73
- #
74
- # `Stats.built`
75
- def built
76
- event :build
77
- end
78
-
79
- # Registers a build for the app
80
- #
81
- # `Stats.build`
82
- def build
83
- built
84
- end
85
-
86
- # Registers a deployed status for the given app
87
- #
88
- # `Stats.deployed 'watapp'`
89
- def deployed(app = nil)
90
- event :deploy, app
91
- end
92
-
93
- # Registers a deployment for the given app
94
- #
95
- # `Stats.deploy 'watapp'`
96
- def deploy(app = nil)
97
- deployed(app)
98
- end
99
-
100
- # Register an event of any type
101
- #
102
- # `Stats.event 'wat', 'app'`
103
- def event(type, app = nil)
104
- gauge ["event", type.to_s, app], Time.now.usec
105
- end
106
-
107
- # Registers an increment on the result of the given boolean
108
- #
109
- # `Stats.increment_on 'wat', wat.random?`
110
- def increment_on(stat, perf, sample_rate=1)
111
- key = [stat, (perf ? "success" : "fail")]
112
- increment(key, sample_rate)
113
- perf
114
- end
115
-
116
- # Register an arbitrary value
117
- #
118
- # `Stats.gauge 'wat', 'app'`
119
- def gauge(stat, value, sample_rate = 1)
120
- send(stat, value, :gauge, sample_rate)
121
- end
122
-
123
- # Register multiple statistics in a single call
124
- #
125
- # `Stats.bulk do
126
- # increment 'wat'
127
- # decrement 'wot'
128
- # end`
129
- def bulk(&block)
130
- Fozzie::BulkDsl.new(&block)
131
- end
132
-
133
- private
134
-
135
- def adapter
136
- Fozzie.c.adapter
137
- end
138
-
139
- end
1
+ require 'fozzie/adapter/statsd'
2
+
3
+ module Fozzie
4
+ module Interface
5
+
6
+ # Increments the given stat by one, with an optional sample rate
7
+ #
8
+ # `Stats.increment 'wat'`
9
+ def increment(stat, sample_rate=1)
10
+ count(stat, 1, sample_rate)
11
+ end
12
+
13
+ # Decrements the given stat by one, with an optional sample rate
14
+ #
15
+ # `Stats.decrement 'wat'`
16
+ def decrement(stat, sample_rate=1)
17
+ count(stat, -1, sample_rate)
18
+ end
19
+
20
+ # Registers a count for the given stat, with an optional sample rate
21
+ #
22
+ # `Stats.count 'wat', 500`
23
+ def count(stat, count, sample_rate=1)
24
+ send(stat, count, :count, sample_rate)
25
+ end
26
+
27
+ # Registers a timing (in ms) for the given stat, with an optional sample rate
28
+ #
29
+ # `Stats.timing 'wat', 500`
30
+ def timing(stat, ms, sample_rate=1)
31
+ send(stat, ms, :timing, sample_rate)
32
+ end
33
+
34
+ # Registers the time taken to complete a given block (in ms), with an optional sample rate
35
+ #
36
+ # `Stats.time 'wat' { # Do something... }`
37
+ def time(stat, sample_rate=1)
38
+ start = Time.now
39
+ result = yield
40
+ timing(stat, ((Time.now - start) * 1000).round, sample_rate)
41
+ result
42
+ end
43
+
44
+ # Registers the time taken to complete a given block (in ms), with an optional sample rate
45
+ #
46
+ # `Stats.time_to_do 'wat' { # Do something, again... }`
47
+ def time_to_do(stat, sample_rate=1, &block)
48
+ time(stat, sample_rate, &block)
49
+ end
50
+
51
+ # Registers the time taken to complete a given block (in ms), with an optional sample rate
52
+ #
53
+ # `Stats.time_for 'wat' { # Do something, grrr... }`
54
+ def time_for(stat, sample_rate=1, &block)
55
+ time(stat, sample_rate, &block)
56
+ end
57
+
58
+ # Registers a commit
59
+ #
60
+ # `Stats.commit`
61
+ def commit
62
+ event :commit
63
+ end
64
+
65
+ # Registers a commit
66
+ #
67
+ # `Stats.commit`
68
+ def committed
69
+ commit
70
+ end
71
+
72
+ # Registers that the app has been built
73
+ #
74
+ # `Stats.built`
75
+ def built
76
+ event :build
77
+ end
78
+
79
+ # Registers a build for the app
80
+ #
81
+ # `Stats.build`
82
+ def build
83
+ built
84
+ end
85
+
86
+ # Registers a deployed status for the given app
87
+ #
88
+ # `Stats.deployed 'watapp'`
89
+ def deployed(app = nil)
90
+ event :deploy, app
91
+ end
92
+
93
+ # Registers a deployment for the given app
94
+ #
95
+ # `Stats.deploy 'watapp'`
96
+ def deploy(app = nil)
97
+ deployed(app)
98
+ end
99
+
100
+ # Register an event of any type
101
+ #
102
+ # `Stats.event 'wat', 'app'`
103
+ def event(type, app = nil)
104
+ gauge ["event", type.to_s, app], Time.now.usec
105
+ end
106
+
107
+ # Registers an increment on the result of the given boolean
108
+ #
109
+ # `Stats.increment_on 'wat', wat.random?`
110
+ def increment_on(stat, perf, sample_rate=1)
111
+ key = [stat, (perf ? "success" : "fail")]
112
+ increment(key, sample_rate)
113
+ perf
114
+ end
115
+
116
+ # Register an arbitrary value
117
+ #
118
+ # `Stats.gauge 'wat', 'app'`
119
+ def gauge(stat, value, sample_rate = 1)
120
+ send(stat, value, :gauge, sample_rate)
121
+ end
122
+
123
+ # Register multiple statistics in a single call
124
+ #
125
+ # `Stats.bulk do
126
+ # increment 'wat'
127
+ # decrement 'wot'
128
+ # end`
129
+ def bulk(&block)
130
+ Fozzie::BulkDsl.new(&block)
131
+ end
132
+
133
+ private
134
+
135
+ def adapter
136
+ Fozzie.c.adapter
137
+ end
138
+
139
+ end
140
140
  end
@@ -1,44 +1,44 @@
1
- require 'fozzie'
2
-
3
- module Fozzie
4
- module Rack
5
-
6
- # Time and record each request through a given Rack app
7
- # This middleware times server processing for a resource, not view render.
8
- class Middleware
9
-
10
- attr_reader :app
11
-
12
- def initialize(app)
13
- @app = app
14
- end
15
-
16
- def call(env)
17
- k = generate_key(env)
18
- if k.nil?
19
- self.call_without_timer(env)
20
- else
21
- self.call_with_timer(k, env)
22
- end
23
- end
24
-
25
- def call_without_timer(env)
26
- @app.call(env)
27
- end
28
-
29
- def call_with_timer(key, env)
30
- S.time_to_do key do
31
- @app.call(env)
32
- end
33
- end
34
-
35
- def generate_key(env)
36
- s = env['PATH_INFO']
37
- return nil if s.nil?
38
- s = (s == '/' ? 'index' : s.gsub(/.(\/)./) {|m| m.gsub('/', '.') }.gsub(/\//, '').strip)
39
- (s.nil? || s.empty? ? nil : "#{s}.render")
40
- end
41
-
42
- end
43
- end
1
+ require 'fozzie'
2
+
3
+ module Fozzie
4
+ module Rack
5
+
6
+ # Time and record each request through a given Rack app
7
+ # This middleware times server processing for a resource, not view render.
8
+ class Middleware
9
+
10
+ attr_reader :app
11
+
12
+ def initialize(app)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ k = generate_key(env)
18
+ if k.nil?
19
+ self.call_without_timer(env)
20
+ else
21
+ self.call_with_timer(k, env)
22
+ end
23
+ end
24
+
25
+ def call_without_timer(env)
26
+ @app.call(env)
27
+ end
28
+
29
+ def call_with_timer(key, env)
30
+ S.time_to_do key do
31
+ @app.call(env)
32
+ end
33
+ end
34
+
35
+ def generate_key(env)
36
+ s = env['PATH_INFO']
37
+ return nil if s.nil?
38
+ s = (s == '/' ? 'index' : s.gsub(/.(\/)./) {|m| m.gsub('/', '.') }.gsub(/\//, '').strip)
39
+ (s.nil? || s.empty? ? nil : "#{s}.render")
40
+ end
41
+
42
+ end
43
+ end
44
44
  end