dogstatsd-ruby 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +23 -0
- data/lib/statsd.rb +41 -4
- metadata +67 -88
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 93021b35d28b353f50ffd4e6c27b5dfe3881f6a1
|
4
|
+
data.tar.gz: 15f63c6b4b48b5947029863633a0f3859ec932df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a5110a43772bd0c4d02d04a9b501c01da66c10f0c17ed3afd3e8bea0585418fce5ecc8f5026f115fc4d6a53e46e488d4e9d286a491fbbf90fe8206e80063516
|
7
|
+
data.tar.gz: db4ded7c2533b144275edb923abccc69456ed07984bda0dc7f480b40af0c6aa27acc19925255ef40ab92fa5e5f9261947fae865bd56102b6f1a5c2c74bc9b32f
|
data/README.md
CHANGED
@@ -36,10 +36,31 @@ statsd.time('page.render') do
|
|
36
36
|
render_page('home.html')
|
37
37
|
end
|
38
38
|
|
39
|
+
# Send several metrics at the same time
|
40
|
+
# All metrics will be buffered and sent in one packet when the block completes
|
41
|
+
statsd.batch do |s|
|
42
|
+
s.increment('page.views')
|
43
|
+
s.gauge('users.online', 123)
|
44
|
+
end
|
45
|
+
|
39
46
|
# Tag a metric.
|
40
47
|
statsd.histogram('query.time', 10, :tags => ["version:1"])
|
41
48
|
```
|
42
49
|
|
50
|
+
You can also post events to your stream. You can tag them, set priority and even aggregate them with other events.
|
51
|
+
|
52
|
+
Aggregation in the stream is made on hostname/event_type/source_type/aggregation_key.
|
53
|
+
|
54
|
+
``` ruby
|
55
|
+
# Post a simple message
|
56
|
+
statsd.event("There might be a storm tomorrow", "A friend warned me earlier.")
|
57
|
+
|
58
|
+
# Cry for help
|
59
|
+
statsd.event("SO MUCH SNOW", "Started yesterday and it won't stop !!", :alert_type => "error", :tags => ["urgent", "endoftheworld"])
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
|
43
64
|
Documentation
|
44
65
|
-------------
|
45
66
|
|
@@ -57,6 +78,8 @@ To suggest a feature, report a bug, or general discussion, head over
|
|
57
78
|
Change Log
|
58
79
|
----------
|
59
80
|
|
81
|
+
- 1.4.0
|
82
|
+
- Added support for metrics batching
|
60
83
|
- 1.3.0
|
61
84
|
- Added support for submitting events.
|
62
85
|
- 1.2.0
|
data/lib/statsd.rb
CHANGED
@@ -44,6 +44,12 @@ class Statsd
|
|
44
44
|
# Global tags to be added to every statsd call. Defaults to no tags.
|
45
45
|
attr_reader :tags
|
46
46
|
|
47
|
+
# Buffer containing the statsd message before they are sent in batch
|
48
|
+
attr_reader :buffer
|
49
|
+
|
50
|
+
# Maximum number of metrics in the buffer before it is flushed
|
51
|
+
attr_accessor :max_buffer_size
|
52
|
+
|
47
53
|
class << self
|
48
54
|
# Set to a standard logger instance to enable debug logging.
|
49
55
|
attr_accessor :logger
|
@@ -51,19 +57,22 @@ class Statsd
|
|
51
57
|
|
52
58
|
# Return the current version of the library.
|
53
59
|
def self.VERSION
|
54
|
-
"1.
|
60
|
+
"1.4.0"
|
55
61
|
end
|
56
62
|
|
57
63
|
# @param [String] host your statsd host
|
58
64
|
# @param [Integer] port your statsd port
|
59
65
|
# @option opts [String] :namespace set a namespace to be prepended to every metric name
|
60
66
|
# @option opts [Array<String>] :tags tags to be added to every metric
|
61
|
-
def initialize(host = DEFAULT_HOST, port = DEFAULT_PORT, opts = {})
|
67
|
+
def initialize(host = DEFAULT_HOST, port = DEFAULT_PORT, opts = {}, max_buffer_size=50)
|
62
68
|
self.host, self.port = host, port
|
63
69
|
@prefix = nil
|
64
70
|
@socket = UDPSocket.new
|
65
71
|
self.namespace = opts[:namespace]
|
66
72
|
self.tags = opts[:tags]
|
73
|
+
@buffer = Array.new
|
74
|
+
self.max_buffer_size = max_buffer_size
|
75
|
+
alias :send :send_to_socket
|
67
76
|
end
|
68
77
|
|
69
78
|
def namespace=(namespace) #:nodoc:
|
@@ -205,7 +214,7 @@ class Statsd
|
|
205
214
|
# @option opts [String, nil] :source_type_name (nil) Assign a source type to the event
|
206
215
|
# @option opts [String, nil] :alert_type ('info') Can be "error", "warning", "info" or "success".
|
207
216
|
# @option opts [Array<String>, nil] :source_type_name (nil) An array of tags
|
208
|
-
# @example Report an
|
217
|
+
# @example Report an awful event:
|
209
218
|
# $statsd.event('Something terrible happened', 'The end is near if we do nothing', :alert_type=>'warning', :tags=>['end_of_times','urgent'])
|
210
219
|
def event(title, text, opts={})
|
211
220
|
event_string = format_event(title, text, opts)
|
@@ -213,6 +222,22 @@ class Statsd
|
|
213
222
|
|
214
223
|
send_to_socket event_string
|
215
224
|
end
|
225
|
+
|
226
|
+
# Send several metrics in the same UDP Packet
|
227
|
+
# They will be buffered and flushed when the block finishes
|
228
|
+
#
|
229
|
+
# @example Send several metrics in one packet:
|
230
|
+
# $statsd.batch do |s|
|
231
|
+
# s.gauge('users.online',156)
|
232
|
+
# s.increment('page.views')
|
233
|
+
# end
|
234
|
+
def batch()
|
235
|
+
alias :send :send_to_buffer
|
236
|
+
yield self
|
237
|
+
flush_buffer
|
238
|
+
alias :send :send_to_socket
|
239
|
+
end
|
240
|
+
|
216
241
|
def format_event(title, text, opts={})
|
217
242
|
escape_event_content title
|
218
243
|
escape_event_content text
|
@@ -256,10 +281,22 @@ class Statsd
|
|
256
281
|
rate = "|@#{sample_rate}" unless sample_rate == 1
|
257
282
|
ts = (tags || []) + (opts[:tags] || [])
|
258
283
|
tags = "|##{ts.join(",")}" unless ts.empty?
|
259
|
-
|
284
|
+
send "#{@prefix}#{stat}:#{delta}|#{type}#{rate}#{tags}"
|
260
285
|
end
|
261
286
|
end
|
262
287
|
|
288
|
+
def send_to_buffer(message)
|
289
|
+
@buffer << message
|
290
|
+
if @buffer.length >= @max_buffer_size
|
291
|
+
flush_buffer
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
def flush_buffer()
|
296
|
+
send_to_socket(@buffer.join('\n'))
|
297
|
+
@buffer = Array.new
|
298
|
+
end
|
299
|
+
|
263
300
|
def send_to_socket(message)
|
264
301
|
self.class.logger.debug { "Statsd: #{message}" } if self.class.logger
|
265
302
|
@socket.send(message, 0, @host, @port)
|
metadata
CHANGED
@@ -1,126 +1,105 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogstatsd-ruby
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 1.3.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Rein Henrichs
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: minitest
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
32
20
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: yard
|
36
21
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
47
33
|
version: 0.6.0
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: jeweler
|
52
35
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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'
|
63
48
|
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: simplecov
|
67
49
|
prerelease: false
|
68
|
-
|
69
|
-
|
70
|
-
|
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:
|
71
59
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
77
62
|
type: :development
|
78
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
79
69
|
description: A Ruby DogStastd client
|
80
70
|
email: code@datadoghq.com
|
81
71
|
executables: []
|
82
|
-
|
83
72
|
extensions: []
|
84
|
-
|
85
|
-
extra_rdoc_files:
|
73
|
+
extra_rdoc_files:
|
86
74
|
- LICENSE.txt
|
87
75
|
- README.md
|
88
|
-
files:
|
76
|
+
files:
|
89
77
|
- LICENSE.txt
|
90
78
|
- README.md
|
91
79
|
- lib/statsd.rb
|
92
80
|
homepage: http://github.com/datadog/dogstatsd-ruby
|
93
|
-
licenses:
|
81
|
+
licenses:
|
94
82
|
- MIT
|
83
|
+
metadata: {}
|
95
84
|
post_install_message:
|
96
85
|
rdoc_options: []
|
97
|
-
|
98
|
-
require_paths:
|
86
|
+
require_paths:
|
99
87
|
- lib
|
100
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
-
|
102
|
-
requirements:
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
103
90
|
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
version: "0"
|
109
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
|
-
requirements:
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
112
95
|
- - ">="
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
|
115
|
-
segments:
|
116
|
-
- 0
|
117
|
-
version: "0"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
118
98
|
requirements: []
|
119
|
-
|
120
99
|
rubyforge_project:
|
121
|
-
rubygems_version:
|
100
|
+
rubygems_version: 2.2.2
|
122
101
|
signing_key:
|
123
|
-
specification_version:
|
102
|
+
specification_version: 4
|
124
103
|
summary: A Ruby DogStatsd client
|
125
104
|
test_files: []
|
126
|
-
|
105
|
+
has_rdoc:
|