metricsd 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/lib/metricsd/client.rb +21 -6
- data/lib/metricsd/version.rb +1 -1
- data/spec/client_spec.rb +7 -1
- metadata +6 -6
data/CHANGELOG.md
CHANGED
data/lib/metricsd/client.rb
CHANGED
@@ -70,6 +70,7 @@ module Metricsd
|
|
70
70
|
}, opts
|
71
71
|
)
|
72
72
|
end
|
73
|
+
alias :hit :record_hit
|
73
74
|
|
74
75
|
# Record succeded boolean event.
|
75
76
|
#
|
@@ -84,6 +85,7 @@ module Metricsd
|
|
84
85
|
def record_success(metric, opts = {})
|
85
86
|
record_internal({"#{metric}.status" => 1}, opts)
|
86
87
|
end
|
88
|
+
alias :success :record_success
|
87
89
|
|
88
90
|
# Record failed boolean event.
|
89
91
|
#
|
@@ -98,6 +100,7 @@ module Metricsd
|
|
98
100
|
def record_failure(metric, opts = {})
|
99
101
|
record_internal({"#{metric}.status" => -1}, opts)
|
100
102
|
end
|
103
|
+
alias :failure :record_failure
|
101
104
|
|
102
105
|
# Record timing info. Time should be a floating point
|
103
106
|
# number of seconds.
|
@@ -113,12 +116,17 @@ module Metricsd
|
|
113
116
|
#
|
114
117
|
def record_time(metric, time = nil, opts = {}, &block)
|
115
118
|
opts, time = time, nil if Hash === time
|
119
|
+
result = nil
|
116
120
|
if time.nil?
|
117
121
|
raise ArgumentError, "You should pass a block if time is not given" unless block_given?
|
118
|
-
time = Benchmark.measure
|
122
|
+
time = Benchmark.measure do
|
123
|
+
result = block.call
|
124
|
+
end.real
|
119
125
|
end
|
120
126
|
record_internal({"#{metric}.time" => (time * 1000).round}, opts)
|
127
|
+
result
|
121
128
|
end
|
129
|
+
alias :time :record_time
|
122
130
|
|
123
131
|
# Record an integer value.
|
124
132
|
#
|
@@ -135,6 +143,7 @@ module Metricsd
|
|
135
143
|
record_internal({metric => value.round}, opts)
|
136
144
|
end
|
137
145
|
alias :record :record_value
|
146
|
+
alias :value :record_value
|
138
147
|
|
139
148
|
# Record multiple integer values.
|
140
149
|
#
|
@@ -156,6 +165,7 @@ module Metricsd
|
|
156
165
|
def record_values(metrics, opts = {})
|
157
166
|
record_internal(metrics, opts)
|
158
167
|
end
|
168
|
+
alias :values :record_values
|
159
169
|
|
160
170
|
# Reset and re-establish connection.
|
161
171
|
def reset_connection!
|
@@ -166,9 +176,14 @@ module Metricsd
|
|
166
176
|
|
167
177
|
# Returns a UDP socket used to send metrics to MetricsD.
|
168
178
|
def collector_socket
|
169
|
-
@@
|
170
|
-
|
179
|
+
@@lock.synchronize do
|
180
|
+
@@socket ||= UDPSocket.new.tap do |sock|
|
181
|
+
sock.connect(Metricsd.server_host, Metricsd.server_port)
|
182
|
+
end
|
171
183
|
end
|
184
|
+
rescue SocketError => e
|
185
|
+
Metricsd.logger.error("Exception occurred while trying to connect to MetricsD (#{Metricsd.server_host}:#{Metricsd.server_port}): #{e.inspect}")
|
186
|
+
nil
|
172
187
|
end
|
173
188
|
|
174
189
|
# Send informating to the RRD collector daemon using UDP protocol.
|
@@ -204,11 +219,10 @@ module Metricsd
|
|
204
219
|
# Sends a string to the MetricsD. Should never raise any network-specific
|
205
220
|
# exceptions, but log them instead, and silently return.
|
206
221
|
def safe_send(msg)
|
207
|
-
collector_socket.send(msg, 0)
|
222
|
+
collector_socket.send(msg, 0) if collector_socket
|
208
223
|
true
|
209
224
|
rescue Errno::ECONNREFUSED => e
|
210
|
-
Metricsd.logger.error("Exception occurred while trying to send data to
|
211
|
-
e.backtrace.each { |line| Metricsd.logger.error(line) }
|
225
|
+
Metricsd.logger.error("Exception occurred while trying to send data to MetricsD (#{Metricsd.server_host}:#{Metricsd.server_port}): #{e.inspect}")
|
212
226
|
false
|
213
227
|
end
|
214
228
|
|
@@ -220,5 +234,6 @@ module Metricsd
|
|
220
234
|
opts[:source].empty? ? "#{key}:#{value}" : "#{opts[:source]}@#{key}:#{value}"
|
221
235
|
end
|
222
236
|
end
|
237
|
+
@@lock = Monitor.new
|
223
238
|
end
|
224
239
|
end
|
data/lib/metricsd/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -14,7 +14,6 @@ describe Metricsd::Client do
|
|
14
14
|
it 'should not throw, but log exceptions on failure' do
|
15
15
|
@socket.should_receive(:send).and_raise(Errno::ECONNREFUSED.new('exception from test'))
|
16
16
|
Metricsd.logger.should_receive(:error).once.with(match(/exception from test/))
|
17
|
-
Metricsd.logger.should_receive(:error).at_least(1) # stacktrace
|
18
17
|
Metricsd::Client.record_value('custom.metric', 5)
|
19
18
|
end
|
20
19
|
|
@@ -119,6 +118,13 @@ describe Metricsd::Client do
|
|
119
118
|
yielded.should be_true
|
120
119
|
end
|
121
120
|
|
121
|
+
it 'should return block value' do
|
122
|
+
@socket.should_receive(:send).with(match(/all@custom.metric.time:\d+/), 0)
|
123
|
+
Metricsd::Client.record_time('custom.metric') do
|
124
|
+
'hello'
|
125
|
+
end.should eq('hello')
|
126
|
+
end
|
127
|
+
|
122
128
|
it 'should use options if time is not specified' do
|
123
129
|
@socket.should_receive(:send).with(match(/all@custom.metric.time:\d+/), 0)
|
124
130
|
yielded = false
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metricsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dmytro Shteflyuk
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
requirements: []
|
143
143
|
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.
|
145
|
+
rubygems_version: 1.3.7
|
146
146
|
signing_key:
|
147
147
|
specification_version: 3
|
148
148
|
summary: Client library for MetricsD server
|