fozzie 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +3 -0
- data/doc/lib/core_ext/hash.html +79 -0
- data/doc/lib/fozzie.html +148 -0
- data/doc/lib/fozzie/configuration.html +174 -0
- data/doc/lib/fozzie/interface.html +288 -0
- data/doc/lib/fozzie/rack/middleware.html +97 -0
- data/doc/lib/fozzie/rails/middleware.html +97 -0
- data/doc/lib/fozzie/socket.html +123 -0
- data/doc/lib/fozzie/version.html +36 -0
- data/fozzie.gemspec +6 -0
- data/lib/fozzie.rb +52 -10
- data/lib/fozzie/configuration.rb +16 -32
- data/lib/fozzie/interface.rb +121 -0
- data/lib/fozzie/rack/middleware.rb +3 -0
- data/lib/fozzie/rails/middleware.rb +4 -0
- data/lib/fozzie/socket.rb +44 -0
- data/lib/fozzie/version.rb +1 -1
- data/spec/lib/fozzie/configuration_spec.rb +9 -42
- data/spec/lib/fozzie/interface_spec.rb +136 -0
- data/spec/lib/fozzie/rack/middleware_spec.rb +3 -5
- data/spec/lib/fozzie/rails/middleware_spec.rb +35 -29
- data/spec/lib/fozzie_spec.rb +6 -138
- metadata +69 -28
- data/lib/fozzie/classes.rb +0 -146
- data/lib/fozzie/config.rb +0 -19
- data/spec/lib/fozzie/config_spec.rb +0 -24
data/spec/lib/fozzie_spec.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fozzie/classes'
|
3
2
|
|
4
3
|
describe Fozzie do
|
5
4
|
|
6
|
-
it
|
7
|
-
|
5
|
+
it "allows dynamic assignment" do
|
6
|
+
{ :host => 'somewhere.local', :port => 99 }.each do |field, val|
|
7
|
+
Fozzie.configure {|c| c.send("#{field}=", val) }
|
8
|
+
Fozzie.c.send(field).should == val
|
9
|
+
end
|
10
|
+
end
|
8
11
|
|
9
12
|
it "has configuration" do
|
10
13
|
Fozzie.config.should be_kind_of(Fozzie::Configuration)
|
@@ -17,139 +20,4 @@ describe Fozzie do
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
|
-
it "acts like its inherited parent" do
|
21
|
-
Fozzie.c.namespaces.each do |k|
|
22
|
-
kl = Kernel.const_get(k)
|
23
|
-
kl.should respond_to(:increment)
|
24
|
-
kl.should respond_to(:decrement)
|
25
|
-
kl.should respond_to(:timing)
|
26
|
-
kl.should respond_to(:count)
|
27
|
-
kl.should respond_to(:time)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "acts an a singleton" do
|
32
|
-
Fozzie.c.namespaces.each do |k|
|
33
|
-
kl1, kl2 = Kernel.const_get(k), Kernel.const_get(k)
|
34
|
-
kl1.should == kl2
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "times a given block" do
|
39
|
-
Stats.expects(:timing).with() {|b, val, timing| b == 'data.bin' && (1000..1200).include?(val) }.twice
|
40
|
-
Stats.time_for('data.bin') { sleep 1 }
|
41
|
-
Stats.time_to_do('data.bin') { sleep 1 }
|
42
|
-
end
|
43
|
-
|
44
|
-
it "registers a commit" do
|
45
|
-
Stats.expects(:timing).with('event.commit', anything).twice
|
46
|
-
Stats.commit
|
47
|
-
Stats.committed
|
48
|
-
end
|
49
|
-
|
50
|
-
it "registers a build" do
|
51
|
-
Stats.expects(:timing).with('event.build', anything).twice
|
52
|
-
Stats.build
|
53
|
-
Stats.built
|
54
|
-
end
|
55
|
-
|
56
|
-
it "registers a deploy" do
|
57
|
-
Stats.expects(:timing).with('event.deploy', anything).twice
|
58
|
-
Stats.deploy
|
59
|
-
Stats.deployed
|
60
|
-
end
|
61
|
-
|
62
|
-
it "ensures block is called on socket error" do
|
63
|
-
UDPSocket.any_instance.stubs(:send).raises(SocketError)
|
64
|
-
proc { Stats.time_for('data.bin') { sleep 1 } }.should_not raise_error
|
65
|
-
proc { Stats.time_to_do('data.bin') { sleep 1 } }.should_not raise_error
|
66
|
-
end
|
67
|
-
|
68
|
-
it "raises exception if natural exception from block" do
|
69
|
-
proc { Stats.time_for('data.bin') { raise ArgumentError, "testing" } }.should raise_error(ArgumentError)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "only calls the block once on SocketError" do
|
73
|
-
UDPSocket.any_instance.stubs(:send).raises(SocketError)
|
74
|
-
i = 0
|
75
|
-
p = proc {|n| (n + 1) }
|
76
|
-
val = Stats.time_for('data.bin') { i+= p.call(i) }
|
77
|
-
val.should == 1
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "#increment_on" do
|
81
|
-
|
82
|
-
it "registers success" do
|
83
|
-
Stats.expects(:increment).with("event.increment.success", 1)
|
84
|
-
Stats.increment_on('event.increment', true).should == true
|
85
|
-
end
|
86
|
-
|
87
|
-
it "registers failure" do
|
88
|
-
Stats.expects(:increment).with("event.increment.fail", 1)
|
89
|
-
Stats.increment_on('event.increment', false).should == false
|
90
|
-
end
|
91
|
-
|
92
|
-
it "simply questions the passed val with if" do
|
93
|
-
a = mock()
|
94
|
-
a.expects(:save).returns({})
|
95
|
-
Stats.expects(:increment).with("event.increment.success", 1)
|
96
|
-
Stats.increment_on('event.increment', a.save).should == {}
|
97
|
-
end
|
98
|
-
|
99
|
-
it "registers fail on nil return" do
|
100
|
-
a = mock()
|
101
|
-
a.expects(:save).returns(nil)
|
102
|
-
Stats.expects(:increment).with("event.increment.fail", 1)
|
103
|
-
Stats.increment_on('event.increment', a.save).should == nil
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "performing actions" do
|
107
|
-
|
108
|
-
it "registers success" do
|
109
|
-
a = mock()
|
110
|
-
a.expects(:save).returns(true)
|
111
|
-
Stats.expects(:increment).with("event.increment.success", 1)
|
112
|
-
Stats.increment_on('event.increment', a.save).should == true
|
113
|
-
end
|
114
|
-
|
115
|
-
it "registers failure" do
|
116
|
-
a = mock()
|
117
|
-
a.expects(:save).returns(false)
|
118
|
-
Stats.expects(:increment).with("event.increment.fail", 1)
|
119
|
-
Stats.increment_on('event.increment', a.save).should == false
|
120
|
-
end
|
121
|
-
|
122
|
-
it "registers positive even when nested" do
|
123
|
-
a = mock()
|
124
|
-
a.expects(:save).returns(true)
|
125
|
-
Stats.expects(:timing).with('event.run', any_parameters)
|
126
|
-
Stats.expects(:increment).with("event.increment.success", 1)
|
127
|
-
|
128
|
-
res = Stats.time_to_do "event.run" do
|
129
|
-
Stats.increment_on('event.increment', a.save)
|
130
|
-
end
|
131
|
-
res.should == true
|
132
|
-
end
|
133
|
-
|
134
|
-
it "registers negative even when nested" do
|
135
|
-
a = mock()
|
136
|
-
a.expects(:save).returns(false)
|
137
|
-
Stats.expects(:timing).with('event.run', any_parameters)
|
138
|
-
Stats.expects(:increment).with("event.increment.fail", 1)
|
139
|
-
|
140
|
-
res = Stats.time_to_do "event.run" do
|
141
|
-
Stats.increment_on('event.increment', a.save)
|
142
|
-
end
|
143
|
-
res.should == false
|
144
|
-
end
|
145
|
-
|
146
|
-
it "allows passing of arrays for stat key" do
|
147
|
-
Stats.expects(:timing).with('event.commit', any_parameters)
|
148
|
-
Stats.time_to_do %w{event commit} do; end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fozzie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sys-uname
|
16
|
+
requirement: &70337811318040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70337811318040
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: rake
|
16
|
-
requirement: &
|
27
|
+
requirement: &70337811333440 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *70337811333440
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &70337811332500 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70337811332500
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: mocha
|
38
|
-
requirement: &
|
49
|
+
requirement: &70337811331420 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70337811331420
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: syntax
|
49
|
-
requirement: &
|
60
|
+
requirement: &70337811330660 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70337811330660
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rack-test
|
60
|
-
requirement: &
|
71
|
+
requirement: &70337811329600 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70337811329600
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: simplecov
|
71
|
-
requirement: &
|
82
|
+
requirement: &70337811328880 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70337811328880
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: sinatra
|
82
|
-
requirement: &
|
93
|
+
requirement: &70337811328060 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *70337811328060
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: actionpack
|
93
|
-
requirement: &
|
104
|
+
requirement: &70337811327220 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: '0'
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *70337811327220
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: guard
|
104
|
-
requirement: &
|
115
|
+
requirement: &70337811326540 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,10 +120,32 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *70337811326540
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: guard-rspec
|
115
|
-
requirement: &
|
126
|
+
requirement: &70337811342180 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *70337811342180
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: guard-rocco
|
137
|
+
requirement: &70337811341600 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
type: :development
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: *70337811341600
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
name: fl-rocco
|
148
|
+
requirement: &70337811340980 !ruby/object:Gem::Requirement
|
116
149
|
none: false
|
117
150
|
requirements:
|
118
151
|
- - ! '>='
|
@@ -120,7 +153,7 @@ dependencies:
|
|
120
153
|
version: '0'
|
121
154
|
type: :development
|
122
155
|
prerelease: false
|
123
|
-
version_requirements: *
|
156
|
+
version_requirements: *70337811340980
|
124
157
|
description: Gem allows statistics gathering from Ruby and Ruby on Rails applications
|
125
158
|
to Statsd
|
126
159
|
email:
|
@@ -135,20 +168,28 @@ files:
|
|
135
168
|
- Guardfile
|
136
169
|
- README.md
|
137
170
|
- Rakefile
|
171
|
+
- doc/lib/core_ext/hash.html
|
172
|
+
- doc/lib/fozzie.html
|
173
|
+
- doc/lib/fozzie/configuration.html
|
174
|
+
- doc/lib/fozzie/interface.html
|
175
|
+
- doc/lib/fozzie/rack/middleware.html
|
176
|
+
- doc/lib/fozzie/rails/middleware.html
|
177
|
+
- doc/lib/fozzie/socket.html
|
178
|
+
- doc/lib/fozzie/version.html
|
138
179
|
- fozzie.gemspec
|
139
180
|
- fozzie.yml.example
|
140
181
|
- lib/core_ext/hash.rb
|
141
182
|
- lib/fozzie.rb
|
142
|
-
- lib/fozzie/classes.rb
|
143
|
-
- lib/fozzie/config.rb
|
144
183
|
- lib/fozzie/configuration.rb
|
184
|
+
- lib/fozzie/interface.rb
|
145
185
|
- lib/fozzie/rack/middleware.rb
|
146
186
|
- lib/fozzie/rails/middleware.rb
|
187
|
+
- lib/fozzie/socket.rb
|
147
188
|
- lib/fozzie/version.rb
|
148
189
|
- spec/config/fozzie.yml
|
149
190
|
- spec/lib/core_ext/hash_spec.rb
|
150
|
-
- spec/lib/fozzie/config_spec.rb
|
151
191
|
- spec/lib/fozzie/configuration_spec.rb
|
192
|
+
- spec/lib/fozzie/interface_spec.rb
|
152
193
|
- spec/lib/fozzie/rack/middleware_spec.rb
|
153
194
|
- spec/lib/fozzie/rails/middleware_spec.rb
|
154
195
|
- spec/lib/fozzie/version_spec.rb
|
@@ -168,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
209
|
version: '0'
|
169
210
|
segments:
|
170
211
|
- 0
|
171
|
-
hash:
|
212
|
+
hash: 95658434726318047
|
172
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
214
|
none: false
|
174
215
|
requirements:
|
@@ -177,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
218
|
version: '0'
|
178
219
|
segments:
|
179
220
|
- 0
|
180
|
-
hash:
|
221
|
+
hash: 95658434726318047
|
181
222
|
requirements: []
|
182
223
|
rubyforge_project: fozzie
|
183
224
|
rubygems_version: 1.8.10
|
@@ -187,8 +228,8 @@ summary: Statsd gem bolt-on
|
|
187
228
|
test_files:
|
188
229
|
- spec/config/fozzie.yml
|
189
230
|
- spec/lib/core_ext/hash_spec.rb
|
190
|
-
- spec/lib/fozzie/config_spec.rb
|
191
231
|
- spec/lib/fozzie/configuration_spec.rb
|
232
|
+
- spec/lib/fozzie/interface_spec.rb
|
192
233
|
- spec/lib/fozzie/rack/middleware_spec.rb
|
193
234
|
- spec/lib/fozzie/rails/middleware_spec.rb
|
194
235
|
- spec/lib/fozzie/version_spec.rb
|
data/lib/fozzie/classes.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
module Fozzie
|
2
|
-
module Classes
|
3
|
-
|
4
|
-
class AbstractFozzie
|
5
|
-
|
6
|
-
RESERVED_CHARS_REGEX = /[\:\|\@]/
|
7
|
-
|
8
|
-
attr_reader :prefix, :configuration
|
9
|
-
|
10
|
-
# Sends an increment (count = 1) for the given stat to the statsd server.
|
11
|
-
#
|
12
|
-
# @param stat (see #count)
|
13
|
-
# @param sample_rate (see #count)
|
14
|
-
# @see #count
|
15
|
-
def increment(stat, sample_rate=1)
|
16
|
-
count(stat, 1, sample_rate)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Sends a decrement (count = -1) for the given stat to the statsd server.
|
20
|
-
#
|
21
|
-
# @param stat (see #count)
|
22
|
-
# @param sample_rate (see #count)
|
23
|
-
# @see #count
|
24
|
-
def decrement(stat, sample_rate=1)
|
25
|
-
count(stat, -1, sample_rate)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Sends an arbitrary count for the given stat to the statsd server.
|
29
|
-
#
|
30
|
-
# @param [String] stat stat name
|
31
|
-
# @param [Integer] count count
|
32
|
-
# @param [Integer] sample_rate sample rate, 1 for always
|
33
|
-
def count(stat, count, sample_rate=1)
|
34
|
-
send(stat, count, 'c', sample_rate)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Sends a timing (in ms) for the given stat to the statsd server. The
|
38
|
-
# sample_rate determines what percentage of the time this report is sent. The
|
39
|
-
# statsd server then uses the sample_rate to correctly track the average
|
40
|
-
# timing for the stat.
|
41
|
-
#
|
42
|
-
# @param stat stat name
|
43
|
-
# @param [Integer] ms timing in milliseconds
|
44
|
-
# @param [Integer] sample_rate sample rate, 1 for always
|
45
|
-
def timing(stat, ms, sample_rate=1)
|
46
|
-
send(stat, ms, 'ms', sample_rate)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Reports execution time of the provided block using {#timing}.
|
50
|
-
#
|
51
|
-
# @param stat (see #timing)
|
52
|
-
# @param sample_rate (see #timing)
|
53
|
-
# @yield The operation to be timed
|
54
|
-
# @see #timing
|
55
|
-
# @example Report the time (in ms) taken to activate an account
|
56
|
-
# $statsd.time('account.activate') { @account.activate! }
|
57
|
-
def time(stat, sample_rate=1)
|
58
|
-
stat = stat.flatten.join('.') if stat.kind_of?(Array)
|
59
|
-
start = Time.now
|
60
|
-
result = yield
|
61
|
-
timing(stat, ((Time.now - start) * 1000).round, sample_rate)
|
62
|
-
result
|
63
|
-
end
|
64
|
-
|
65
|
-
def time_to_do(stat, sample_rate=1, &block)
|
66
|
-
time_for(stat, sample_rate, &block)
|
67
|
-
end
|
68
|
-
|
69
|
-
def time_for(stat, sample_rate=1, &block)
|
70
|
-
time(stat, sample_rate, &block)
|
71
|
-
end
|
72
|
-
|
73
|
-
def commit
|
74
|
-
event :commit
|
75
|
-
end
|
76
|
-
def committed; commit; end
|
77
|
-
|
78
|
-
def built
|
79
|
-
event :build
|
80
|
-
end
|
81
|
-
def build; built; end
|
82
|
-
|
83
|
-
def deployed(app = nil)
|
84
|
-
event :deploy, app
|
85
|
-
end
|
86
|
-
def deploy(app = nil); deployed(app); end
|
87
|
-
|
88
|
-
def increment_on(stat, perf, sample_rate=1)
|
89
|
-
key = "#{stat}.%s" % (perf ? "success" : "fail")
|
90
|
-
increment(key, sample_rate)
|
91
|
-
perf
|
92
|
-
end
|
93
|
-
|
94
|
-
def logger
|
95
|
-
self.class.logger
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.logger
|
99
|
-
@logger
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
|
104
|
-
def event(type, app = nil)
|
105
|
-
stat = "event.#{type.to_s}"
|
106
|
-
stat << ".#{app}" unless app.nil?
|
107
|
-
timing stat, Time.now.usec
|
108
|
-
end
|
109
|
-
|
110
|
-
def send_to_socket(message)
|
111
|
-
return false if Fozzie.c.ip_from_host.empty?
|
112
|
-
begin
|
113
|
-
self.class.logger.debug {"Statsd: #{message}"} if self.class.logger
|
114
|
-
socket.send(message, 0, Fozzie.c.ip_from_host, Fozzie.c.port)
|
115
|
-
rescue SocketError, RuntimeError, Errno::EADDRNOTAVAIL, Timeout::Error => exc
|
116
|
-
self.class.logger.debug {"Statsd Failure: #{exc.message}"} if self.class.logger
|
117
|
-
nil
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def sampled(sample_rate)
|
122
|
-
yield unless sample_rate < 1 and rand > sample_rate
|
123
|
-
end
|
124
|
-
|
125
|
-
def send(stat, delta, type, sample_rate)
|
126
|
-
prefix = "#{Fozzie.c.data_prefix}." unless Fozzie.c.data_prefix.nil?
|
127
|
-
stat = stat.to_s.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_')
|
128
|
-
sampled(sample_rate) { send_to_socket("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}") }
|
129
|
-
end
|
130
|
-
|
131
|
-
def socket
|
132
|
-
@socket ||= UDPSocket.new
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
def self.included(klass)
|
138
|
-
Fozzie.c.namespaces.each do |klas|
|
139
|
-
# set a constant
|
140
|
-
Kernel.const_set(klas, AbstractFozzie.new) unless const_defined?(klas)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|