metricsd 0.2.2 → 0.2.3
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 +2 -1
- data/lib/metricsd/version.rb +1 -1
- data/lib/metricsd.rb +11 -0
- data/spec/client_spec.rb +18 -0
- data/spec/metricsd_spec.rb +9 -0
- metadata +3 -3
data/CHANGELOG.md
CHANGED
data/lib/metricsd/client.rb
CHANGED
@@ -224,7 +224,8 @@ module Metricsd
|
|
224
224
|
# Packs metric into a string representation according to the MetricsD
|
225
225
|
# protocol.
|
226
226
|
def pack(key, value, opts)
|
227
|
-
|
227
|
+
group = opts[:group] || Metricsd.default_group || ''
|
228
|
+
key = "#{group}$#{key}" unless group.empty?
|
228
229
|
opts[:source].empty? ? "#{key}:#{value}" : "#{opts[:source]}@#{key}:#{value}"
|
229
230
|
end
|
230
231
|
end
|
data/lib/metricsd/version.rb
CHANGED
data/lib/metricsd.rb
CHANGED
@@ -72,6 +72,16 @@ module Metricsd
|
|
72
72
|
@@default_source = source
|
73
73
|
end
|
74
74
|
|
75
|
+
# Gets the default group for all metrics.
|
76
|
+
def default_group
|
77
|
+
@@default_group
|
78
|
+
end
|
79
|
+
|
80
|
+
# Sets the default group for all metrics.
|
81
|
+
def default_group=(group)
|
82
|
+
@@default_group = group
|
83
|
+
end
|
84
|
+
|
75
85
|
# Gets the logger used to output errors or warnings.
|
76
86
|
def logger
|
77
87
|
@@logger ||= if defined?(Rails)
|
@@ -95,6 +105,7 @@ module Metricsd
|
|
95
105
|
@@enabled = true
|
96
106
|
@@source = Socket.gethostname[/^([^.]+)/, 1]
|
97
107
|
@@default_source = 'all'
|
108
|
+
@@default_group = nil
|
98
109
|
@@logger = nil
|
99
110
|
end
|
100
111
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -184,6 +184,24 @@ describe Metricsd::Client do
|
|
184
184
|
@socket.should_receive(:send).with('test2@custom.metric:23', 0)
|
185
185
|
Metricsd::Client.record_value('custom.metric', 23, :source => 'test2')
|
186
186
|
end
|
187
|
+
|
188
|
+
it 'should apply default group if specified' do
|
189
|
+
Metricsd.default_group = 'grp'
|
190
|
+
@socket.should_receive(:send).with('all@grp$custom.metric:23', 0)
|
191
|
+
Metricsd::Client.record_value('custom.metric', 23)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should override default group with the specified one' do
|
195
|
+
Metricsd.default_group = 'grp'
|
196
|
+
@socket.should_receive(:send).with('all@group$custom.metric:23', 0)
|
197
|
+
Metricsd::Client.record_value('custom.metric', 23, :group => 'group')
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should clear group, if there is a default one, and empty string specified' do
|
201
|
+
Metricsd.default_group = 'grp'
|
202
|
+
@socket.should_receive(:send).with('all@custom.metric:23', 0)
|
203
|
+
Metricsd::Client.record_value('custom.metric', 23, :group => '')
|
204
|
+
end
|
187
205
|
end
|
188
206
|
|
189
207
|
describe '.record_values' do
|
data/spec/metricsd_spec.rb
CHANGED
@@ -25,6 +25,10 @@ describe Metricsd do
|
|
25
25
|
Metricsd.default_source.should == 'all'
|
26
26
|
end
|
27
27
|
|
28
|
+
it 'should have default_group = nil' do
|
29
|
+
Metricsd.default_group.should be_nil
|
30
|
+
end
|
31
|
+
|
28
32
|
it 'should create logger' do
|
29
33
|
Metricsd.logger.should be_a(Logger)
|
30
34
|
end
|
@@ -76,6 +80,11 @@ describe Metricsd do
|
|
76
80
|
Metricsd.default_source.should == 'nothing'
|
77
81
|
end
|
78
82
|
|
83
|
+
it 'should allow to change default_group' do
|
84
|
+
Metricsd.default_group = 'mygroup'
|
85
|
+
Metricsd.default_group.should == 'mygroup'
|
86
|
+
end
|
87
|
+
|
79
88
|
it 'should allow to change logger' do
|
80
89
|
mock = Metricsd.logger = mock('Logger')
|
81
90
|
Metricsd.logger.should be(mock)
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dmytro Shteflyuk
|