dogstatsd-ruby 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/datadog/statsd.rb +42 -37
- metadata +3 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 046a0af9f230451c91fdeb9ae128c550b1c20623fa017d326e63a2f053f7cc9a
|
4
|
+
data.tar.gz: e2ba838497de521e89d386645a0228f819fdd03c28acc05a4789aa7f8d979de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2048376477bd1af31a63b75d17638df999c9f6341f967b2c826177add2a13831a54a72729e2a5c62aa09fa4aca6dccbaba308c79d9adcd470808d3bb80cde59
|
7
|
+
data.tar.gz: 2e0ac5fc90f8a2359f35a754034bb6474c1169ac8c8f3301257555553e1aca4f708cecd4d9245ff835cbe4396561a89d3bd3700ef6cea6c92c343a1e41ca2055
|
data/lib/datadog/statsd.rb
CHANGED
@@ -49,8 +49,10 @@ module Datadog
|
|
49
49
|
COUNTER_TYPE = 'c'.freeze
|
50
50
|
GAUGE_TYPE = 'g'.freeze
|
51
51
|
HISTOGRAM_TYPE = 'h'.freeze
|
52
|
+
DISTRIBUTION_TYPE = 'd'.freeze
|
52
53
|
TIMING_TYPE = 'ms'.freeze
|
53
54
|
SET_TYPE = 's'.freeze
|
55
|
+
VERSION = "3.3.0".freeze
|
54
56
|
|
55
57
|
# A namespace to prepend to all statsd calls. Defaults to no namespace.
|
56
58
|
attr_reader :namespace
|
@@ -79,8 +81,9 @@ module Datadog
|
|
79
81
|
end
|
80
82
|
|
81
83
|
# Return the current version of the library.
|
84
|
+
# deprecated, but cannot be removed since uses might use it to check the version against older releases
|
82
85
|
def self.VERSION
|
83
|
-
|
86
|
+
VERSION
|
84
87
|
end
|
85
88
|
|
86
89
|
# @param [String] host your statsd host
|
@@ -188,6 +191,22 @@ module Datadog
|
|
188
191
|
send_stats stat, value, HISTOGRAM_TYPE, opts
|
189
192
|
end
|
190
193
|
|
194
|
+
# Sends a value to be tracked as a distribution to the statsd server.
|
195
|
+
# Note: Distributions are a beta feature of Datadog and not generally
|
196
|
+
# available. Distributions must be specifically enabled for your
|
197
|
+
# organization.
|
198
|
+
#
|
199
|
+
# @param [String] stat stat name.
|
200
|
+
# @param [Numeric] value distribution value.
|
201
|
+
# @param [Hash] opts the options to create the metric with
|
202
|
+
# @option opts [Numeric] :sample_rate sample rate, 1 for always
|
203
|
+
# @option opts [Array<String>] :tags An array of tags
|
204
|
+
# @example Report the current user count:
|
205
|
+
# $statsd.distribution('user.count', User.count)
|
206
|
+
def distribution(stat, value, opts={})
|
207
|
+
send_stats stat, value, DISTRIBUTION_TYPE, opts
|
208
|
+
end
|
209
|
+
|
191
210
|
# Sends a timing (in ms) for the given stat to the statsd server. The
|
192
211
|
# sample_rate determines what percentage of the time this report is sent. The
|
193
212
|
# statsd server then uses the sample_rate to correctly track the average
|
@@ -218,10 +237,11 @@ module Datadog
|
|
218
237
|
# $statsd.time('account.activate') { @account.activate! }
|
219
238
|
def time(stat, opts={})
|
220
239
|
opts = {:sample_rate => opts} if opts.is_a? Numeric
|
221
|
-
start = Time.now
|
240
|
+
start = (PROCESS_TIME_SUPPORTED ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : Time.now.to_f)
|
222
241
|
return yield
|
223
242
|
ensure
|
224
|
-
|
243
|
+
finished = (PROCESS_TIME_SUPPORTED ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : Time.now.to_f)
|
244
|
+
timing(stat, ((finished - start) * 1000).round, opts)
|
225
245
|
end
|
226
246
|
# Sends a value to be tracked as a set to the statsd server.
|
227
247
|
#
|
@@ -237,7 +257,6 @@ module Datadog
|
|
237
257
|
send_stats stat, value, SET_TYPE, opts
|
238
258
|
end
|
239
259
|
|
240
|
-
|
241
260
|
# This method allows you to send custom service check statuses.
|
242
261
|
#
|
243
262
|
# @param [String] name Service check name
|
@@ -261,9 +280,9 @@ module Datadog
|
|
261
280
|
next unless opts[key]
|
262
281
|
|
263
282
|
if key == :tags
|
264
|
-
|
265
|
-
|
266
|
-
|
283
|
+
if tags_string = tags_as_string(opts)
|
284
|
+
sc_string << "|##{tags_string}"
|
285
|
+
end
|
267
286
|
elsif key == :message
|
268
287
|
message = remove_pipes(opts[:message])
|
269
288
|
escaped_message = escape_service_check_message(message)
|
@@ -332,9 +351,8 @@ module Datadog
|
|
332
351
|
end
|
333
352
|
|
334
353
|
# Tags are joined and added as last part to the string to be sent
|
335
|
-
|
336
|
-
|
337
|
-
event_string_data << "|##{full_tags.join(COMMA)}"
|
354
|
+
if tags_string = tags_as_string(opts)
|
355
|
+
event_string_data << "|##{tags_string}"
|
338
356
|
end
|
339
357
|
|
340
358
|
raise "Event #{title} payload is too big (more that 8KB), event discarded" if event_string_data.length > 8192 # 8 * 1024 = 8192
|
@@ -351,49 +369,40 @@ module Datadog
|
|
351
369
|
NEW_LINE = "\n".freeze
|
352
370
|
ESC_NEW_LINE = "\\n".freeze
|
353
371
|
COMMA = ",".freeze
|
354
|
-
BLANK = "".freeze
|
355
372
|
PIPE = "|".freeze
|
356
373
|
DOT = ".".freeze
|
357
374
|
DOUBLE_COLON = "::".freeze
|
358
375
|
UNDERSCORE = "_".freeze
|
376
|
+
PROCESS_TIME_SUPPORTED = (RUBY_VERSION >= "2.1.0")
|
359
377
|
|
360
|
-
private_constant :NEW_LINE, :ESC_NEW_LINE, :COMMA, :
|
378
|
+
private_constant :NEW_LINE, :ESC_NEW_LINE, :COMMA, :PIPE, :DOT,
|
361
379
|
:DOUBLE_COLON, :UNDERSCORE
|
362
380
|
|
381
|
+
def tags_as_string(opts)
|
382
|
+
tag_arr = opts[:tags] || []
|
383
|
+
tag_arr = tag_arr.map { |tag| escape_tag_content(tag) }
|
384
|
+
tag_arr = tags + tag_arr # @tags are normalized when set, so not need to normalize them again
|
385
|
+
tag_arr.join(COMMA) unless tag_arr.empty?
|
386
|
+
end
|
387
|
+
|
363
388
|
def escape_event_content(msg)
|
364
389
|
msg.gsub NEW_LINE, ESC_NEW_LINE
|
365
390
|
end
|
366
391
|
|
367
392
|
def escape_tag_content(tag)
|
368
|
-
remove_pipes(tag.to_s)
|
369
|
-
|
370
|
-
|
371
|
-
def escape_tag_content!(tag)
|
372
|
-
tag = tag.to_s
|
373
|
-
tag.gsub!(PIPE, BLANK)
|
374
|
-
tag.gsub!(COMMA, BLANK)
|
393
|
+
tag = remove_pipes(tag.to_s)
|
394
|
+
tag.delete! COMMA
|
375
395
|
tag
|
376
396
|
end
|
377
397
|
|
378
398
|
def remove_pipes(msg)
|
379
|
-
msg.
|
399
|
+
msg.delete PIPE
|
380
400
|
end
|
381
401
|
|
382
402
|
def escape_service_check_message(msg)
|
383
403
|
escape_event_content(msg).gsub('m:'.freeze, 'm\:'.freeze)
|
384
404
|
end
|
385
405
|
|
386
|
-
def time_since(stat, start, opts)
|
387
|
-
timing(stat, ((Time.now - start) * 1000).round, opts)
|
388
|
-
end
|
389
|
-
|
390
|
-
def join_array_to_str(str, array, joiner)
|
391
|
-
array.each_with_index do |item, i|
|
392
|
-
str << joiner unless i == 0
|
393
|
-
str << item
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
406
|
def send_stats(stat, delta, type, opts={})
|
398
407
|
sample_rate = opts[:sample_rate] || 1
|
399
408
|
if sample_rate == 1 or rand < sample_rate
|
@@ -417,14 +426,10 @@ module Datadog
|
|
417
426
|
full_stat << sample_rate.to_s
|
418
427
|
end
|
419
428
|
|
420
|
-
|
421
|
-
tag_arr = opts[:tags].to_a
|
422
|
-
tag_arr.map! { |tag| t = tag.to_s.dup; escape_tag_content!(t); t }
|
423
|
-
ts = tags.to_a + tag_arr
|
424
|
-
unless ts.empty?
|
429
|
+
if tags_string = tags_as_string(opts)
|
425
430
|
full_stat << PIPE
|
426
431
|
full_stat << '#'.freeze
|
427
|
-
|
432
|
+
full_stat << tags_string
|
428
433
|
end
|
429
434
|
|
430
435
|
send_stat(full_stat)
|
metadata
CHANGED
@@ -1,71 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogstatsd-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.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:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: minitest
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: yard
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.6.0
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.6.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: jeweler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.8'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.8'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: simplecov
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
11
|
+
date: 2018-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
69
13
|
description: A Ruby DogStastd client
|
70
14
|
email: code@datadoghq.com
|
71
15
|
executables: []
|