statsd-ruby 0.2.1 → 0.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.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/statsd.rb +4 -0
- data/spec/helper.rb +1 -0
- data/spec/statsd_spec.rb +43 -0
- data/statsd-ruby.gemspec +3 -3
- metadata +6 -6
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/statsd.rb
CHANGED
@@ -16,6 +16,9 @@ class Statsd
|
|
16
16
|
# A namespace to prepend to all statsd calls.
|
17
17
|
attr_accessor :namespace
|
18
18
|
|
19
|
+
#characters that will be replaced with _ in stat names
|
20
|
+
RESERVED_CHARS_REGEX = /[\:\|\@]/
|
21
|
+
|
19
22
|
class << self
|
20
23
|
# Set to any standard logger instance (including stdlib's Logger) to enable
|
21
24
|
# stat logging using logger.debug
|
@@ -82,6 +85,7 @@ class Statsd
|
|
82
85
|
|
83
86
|
def send(stat, delta, type, sample_rate)
|
84
87
|
prefix = "#{@namespace}." unless @namespace.nil?
|
88
|
+
stat = stat.to_s.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_')
|
85
89
|
sampled(sample_rate) { send_to_socket("#{prefix}#{stat}:#{delta}|#{type}#{'|@' << sample_rate.to_s if sample_rate < 1}") }
|
86
90
|
end
|
87
91
|
|
data/spec/helper.rb
CHANGED
data/spec/statsd_spec.rb
CHANGED
@@ -136,6 +136,49 @@ describe Statsd do
|
|
136
136
|
@statsd.socket.recv.must_equal ['service.foobar:500|ms']
|
137
137
|
end
|
138
138
|
end
|
139
|
+
|
140
|
+
describe "with logging" do
|
141
|
+
require 'stringio'
|
142
|
+
before { Statsd.logger = Logger.new(@log = StringIO.new)}
|
143
|
+
|
144
|
+
it "should write to the log in debug" do
|
145
|
+
Statsd.logger.level = Logger::DEBUG
|
146
|
+
|
147
|
+
@statsd.increment('foobar')
|
148
|
+
|
149
|
+
@log.string.must_match "Statsd: foobar:1|c"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should not write to the log unless debug" do
|
153
|
+
Statsd.logger.level = Logger::INFO
|
154
|
+
|
155
|
+
@statsd.increment('foobar')
|
156
|
+
|
157
|
+
@log.string.must_be_empty
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "stat names" do
|
163
|
+
|
164
|
+
it "should accept anything as stat" do
|
165
|
+
@statsd.increment(Object, 1)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should replace ruby constant delimeter with graphite package name" do
|
169
|
+
class Statsd::SomeClass; end
|
170
|
+
@statsd.increment(Statsd::SomeClass, 1)
|
171
|
+
|
172
|
+
@statsd.socket.recv.must_equal ['Statsd.SomeClass:1|c']
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should replace statsd reserved chars in the stat name" do
|
176
|
+
@statsd.increment('ray@hostname.blah|blah.blah:blah', 1)
|
177
|
+
@statsd.socket.recv.must_equal ['ray_hostname.blah_blah.blah_blah:1|c']
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
139
182
|
end
|
140
183
|
|
141
184
|
describe Statsd do
|
data/statsd-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{statsd-ruby}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rein Henrichs"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-24}
|
13
13
|
s.description = %q{A Statsd client in Ruby}
|
14
14
|
s.email = %q{rein@phpfog.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.homepage = %q{http://github.com/reinh/statsd}
|
31
31
|
s.licenses = ["MIT"]
|
32
32
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.
|
33
|
+
s.rubygems_version = %q{1.3.9.1}
|
34
34
|
s.summary = %q{A Statsd client in Ruby}
|
35
35
|
|
36
36
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rein Henrichs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
requirements: []
|
128
128
|
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
130
|
+
rubygems_version: 1.3.9.1
|
131
131
|
signing_key:
|
132
132
|
specification_version: 3
|
133
133
|
summary: A Statsd client in Ruby
|