dogstatsd-ruby 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -16
- data/lib/statsd.rb +88 -16
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f070d540d99ad6add1d56aedfdf89c890daf09
|
4
|
+
data.tar.gz: 21e970d92ceed9401b6dc2ee7764b4c27ef048ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1bb32bc03a081aafd9b2ac73c9b945206939c929b77ae48b571d229e8483866c45454c876c727cbff34b4bc5380d84002439254e7a1b1753c1aa63a4af45a5b
|
7
|
+
data.tar.gz: 6382f5a8374da2c09b5b27eab65062b2ca68ea3322fa03377e7183c916a8afd4816ced7ce9a7d5f6743dd5234f2d23413eaf88b9bcbf3cb6724d2bbaf9ab4b53
|
data/README.md
CHANGED
@@ -75,22 +75,8 @@ To suggest a feature, report a bug, or general discussion, head over
|
|
75
75
|
[here](http://github.com/DataDog/dogstatsd-ruby/issues/).
|
76
76
|
|
77
77
|
|
78
|
-
Change Log
|
79
|
-
|
80
|
-
|
81
|
-
- 1.4.1
|
82
|
-
- Fixed bug in message separator when batching metrics
|
83
|
-
- 1.4.0
|
84
|
-
- Added support for metrics batching
|
85
|
-
- 1.3.0
|
86
|
-
- Added support for submitting events.
|
87
|
-
- 1.2.0
|
88
|
-
- Added global tags.
|
89
|
-
- Added ability to set `namespace` and `tags` from `Statsd#initialize`.
|
90
|
-
- 1.1.0
|
91
|
-
- Added `sets` metrics.
|
92
|
-
- 1.0.0
|
93
|
-
- Initial release.
|
78
|
+
[Change Log](CHANGELOG.md)
|
79
|
+
----------------------------
|
94
80
|
|
95
81
|
|
96
82
|
Credits
|
data/lib/statsd.rb
CHANGED
@@ -32,6 +32,18 @@ class Statsd
|
|
32
32
|
['alert_type', 't']
|
33
33
|
]
|
34
34
|
|
35
|
+
# Service check options
|
36
|
+
SC_OPT_KEYS = [
|
37
|
+
['timestamp', 'd:'],
|
38
|
+
['hostname', 'h:'],
|
39
|
+
['tags', '#'],
|
40
|
+
['message', 'm:']
|
41
|
+
]
|
42
|
+
OK = 0
|
43
|
+
WARNING = 1
|
44
|
+
CRITICAL = 2
|
45
|
+
UNKNOWN = 3
|
46
|
+
|
35
47
|
# A namespace to prepend to all statsd calls. Defaults to no namespace.
|
36
48
|
attr_reader :namespace
|
37
49
|
|
@@ -57,7 +69,7 @@ class Statsd
|
|
57
69
|
|
58
70
|
# Return the current version of the library.
|
59
71
|
def self.VERSION
|
60
|
-
"1.
|
72
|
+
"1.5.0"
|
61
73
|
end
|
62
74
|
|
63
75
|
# @param [String] host your statsd host
|
@@ -72,7 +84,7 @@ class Statsd
|
|
72
84
|
self.tags = opts[:tags]
|
73
85
|
@buffer = Array.new
|
74
86
|
self.max_buffer_size = max_buffer_size
|
75
|
-
alias :
|
87
|
+
alias :send_stat :send_to_socket
|
76
88
|
end
|
77
89
|
|
78
90
|
def namespace=(namespace) #:nodoc:
|
@@ -171,6 +183,9 @@ class Statsd
|
|
171
183
|
|
172
184
|
# Reports execution time of the provided block using {#timing}.
|
173
185
|
#
|
186
|
+
# If the block fails, the stat is still reported, then the error
|
187
|
+
# is reraised
|
188
|
+
#
|
174
189
|
# @param [String] stat stat name
|
175
190
|
# @param [Hash] opts the options to create the metric with
|
176
191
|
# @option opts [Numeric] :sample_rate sample rate, 1 for always
|
@@ -182,8 +197,11 @@ class Statsd
|
|
182
197
|
def time(stat, opts={})
|
183
198
|
start = Time.now
|
184
199
|
result = yield
|
185
|
-
|
200
|
+
time_since(stat, start, opts)
|
186
201
|
result
|
202
|
+
rescue
|
203
|
+
time_since(stat, start, opts)
|
204
|
+
raise
|
187
205
|
end
|
188
206
|
# Sends a value to be tracked as a set to the statsd server.
|
189
207
|
#
|
@@ -198,6 +216,49 @@ class Statsd
|
|
198
216
|
send_stats stat, value, :s, opts
|
199
217
|
end
|
200
218
|
|
219
|
+
|
220
|
+
# This method allows you to send custom service check statuses.
|
221
|
+
#
|
222
|
+
# @param [String] name Service check name
|
223
|
+
# @param [String] status Service check status.
|
224
|
+
# @param [Hash] opts the additional data about the service check
|
225
|
+
# @option opts [Integer, nil] :timestamp (nil) Assign a timestamp to the event. Default is now when none
|
226
|
+
# @option opts [String, nil] :hostname (nil) Assign a hostname to the event.
|
227
|
+
# @option opts [Array<String>, nil] :tags (nil) An array of tags
|
228
|
+
# @option opts [String, nil] :message (nil) A message to associate with this service check status
|
229
|
+
# @example Report a critical service check status
|
230
|
+
# $statsd.service_check('my.service.check', Statsd::CRITICAL, :tags=>['urgent'])
|
231
|
+
def service_check(name, status, opts={})
|
232
|
+
service_check_string = format_service_check(name, status, opts)
|
233
|
+
send_to_socket service_check_string
|
234
|
+
end
|
235
|
+
def format_service_check(name, status, opts={})
|
236
|
+
sc_string = "_sc|#{name}|#{status}"
|
237
|
+
|
238
|
+
SC_OPT_KEYS.each do |name_key|
|
239
|
+
if opts[name_key[0].to_sym]
|
240
|
+
if name_key[0] == 'tags'
|
241
|
+
tags = opts[:tags]
|
242
|
+
tags.each do |tag|
|
243
|
+
rm_pipes tag
|
244
|
+
end
|
245
|
+
tags = "#{tags.join(",")}" unless tags.empty?
|
246
|
+
sc_string << "|##{tags}"
|
247
|
+
elsif name_key[0] == 'message'
|
248
|
+
message = opts[:message]
|
249
|
+
rm_pipes message
|
250
|
+
escape_service_check_message message
|
251
|
+
sc_string << "|m:#{message}"
|
252
|
+
else
|
253
|
+
value = opts[name_key[0].to_sym]
|
254
|
+
rm_pipes value
|
255
|
+
sc_string << "|#{name_key[1]}#{value}"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
return sc_string
|
260
|
+
end
|
261
|
+
|
201
262
|
# This end point allows you to post events to the stream. You can tag them, set priority and even aggregate them with other events.
|
202
263
|
#
|
203
264
|
# Aggregation in the stream is made on hostname/event_type/source_type/aggregation_key.
|
@@ -207,13 +268,13 @@ class Statsd
|
|
207
268
|
# @param [String] title Event title
|
208
269
|
# @param [String] text Event text. Supports \n
|
209
270
|
# @param [Hash] opts the additional data about the event
|
210
|
-
# @option opts [
|
271
|
+
# @option opts [Integer, nil] :date_happened (nil) Assign a timestamp to the event. Default is now when none
|
211
272
|
# @option opts [String, nil] :hostname (nil) Assign a hostname to the event.
|
212
273
|
# @option opts [String, nil] :aggregation_key (nil) Assign an aggregation key to the event, to group it with some others
|
213
274
|
# @option opts [String, nil] :priority ('normal') Can be "normal" or "low"
|
214
275
|
# @option opts [String, nil] :source_type_name (nil) Assign a source type to the event
|
215
276
|
# @option opts [String, nil] :alert_type ('info') Can be "error", "warning", "info" or "success".
|
216
|
-
# @option opts [Array<String
|
277
|
+
# @option opts [Array<String>] :tags tags to be added to every metric
|
217
278
|
# @example Report an awful event:
|
218
279
|
# $statsd.event('Something terrible happened', 'The end is near if we do nothing', :alert_type=>'warning', :tags=>['end_of_times','urgent'])
|
219
280
|
def event(title, text, opts={})
|
@@ -232,10 +293,10 @@ class Statsd
|
|
232
293
|
# s.increment('page.views')
|
233
294
|
# end
|
234
295
|
def batch()
|
235
|
-
alias :
|
296
|
+
alias :send_stat :send_to_buffer
|
236
297
|
yield self
|
237
298
|
flush_buffer
|
238
|
-
alias :
|
299
|
+
alias :send_stat :send_to_socket
|
239
300
|
end
|
240
301
|
|
241
302
|
def format_event(title, text, opts={})
|
@@ -244,7 +305,7 @@ class Statsd
|
|
244
305
|
event_string_data = "_e{#{title.length},#{text.length}}:#{title}|#{text}"
|
245
306
|
|
246
307
|
# We construct the string to be sent by adding '|key:value' parts to it when needed
|
247
|
-
# All pipes ('|') in the
|
308
|
+
# All pipes ('|') in the metadata are removed. Title and Text can keep theirs
|
248
309
|
OPTS_KEYS.each do |name_key|
|
249
310
|
if name_key[0] != 'tags' && opts[name_key[0].to_sym]
|
250
311
|
value = opts[name_key[0].to_sym]
|
@@ -252,25 +313,36 @@ class Statsd
|
|
252
313
|
event_string_data << "|#{name_key[1]}:#{value}"
|
253
314
|
end
|
254
315
|
end
|
255
|
-
|
316
|
+
full_tags = tags + (opts[:tags] || [])
|
256
317
|
# Tags are joined and added as last part to the string to be sent
|
257
|
-
|
258
|
-
|
318
|
+
unless full_tags.empty?
|
319
|
+
full_tags.each do |tag|
|
259
320
|
rm_pipes tag
|
260
321
|
end
|
261
|
-
|
262
|
-
event_string_data << "|##{tags}"
|
322
|
+
event_string_data << "|##{full_tags.join(',')}"
|
263
323
|
end
|
264
324
|
|
265
325
|
raise "Event #{title} payload is too big (more that 8KB), event discarded" if event_string_data.length > 8 * 1024
|
266
326
|
return event_string_data
|
267
327
|
end
|
328
|
+
|
268
329
|
private
|
330
|
+
|
269
331
|
def escape_event_content(msg)
|
270
|
-
msg
|
332
|
+
msg.gsub! "\n", "\\n"
|
271
333
|
end
|
334
|
+
|
272
335
|
def rm_pipes(msg)
|
273
|
-
msg
|
336
|
+
msg.gsub! "|", ""
|
337
|
+
end
|
338
|
+
|
339
|
+
def escape_service_check_message(msg)
|
340
|
+
msg.gsub! 'm:', 'm\:'
|
341
|
+
msg.gsub! "\n", "\\n"
|
342
|
+
end
|
343
|
+
|
344
|
+
def time_since(stat, start, opts)
|
345
|
+
timing(stat, ((Time.now - start) * 1000).round, opts)
|
274
346
|
end
|
275
347
|
|
276
348
|
def send_stats(stat, delta, type, opts={})
|
@@ -281,7 +353,7 @@ class Statsd
|
|
281
353
|
rate = "|@#{sample_rate}" unless sample_rate == 1
|
282
354
|
ts = (tags || []) + (opts[:tags] || [])
|
283
355
|
tags = "|##{ts.join(",")}" unless ts.empty?
|
284
|
-
|
356
|
+
send_stat "#{@prefix}#{stat}:#{delta}|#{type}#{rate}#{tags}"
|
285
357
|
end
|
286
358
|
end
|
287
359
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogstatsd-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rein Henrichs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -102,4 +102,3 @@ signing_key:
|
|
102
102
|
specification_version: 4
|
103
103
|
summary: A Ruby DogStatsd client
|
104
104
|
test_files: []
|
105
|
-
has_rdoc:
|