metricsd 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - jruby
6
+
7
+ notifications:
8
+ recipients:
9
+ - kpumuk@kpumuk.info
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.2.4 (August 11, 2011)
2
+
3
+ Features:
4
+
5
+ - Time metrics should be recorded with ".time" suffix (was "\_time"), status metrics - with ".status" suffix (was "_count")
6
+ - Added Client#record methods (alias of record_value)
7
+ - Changed group separator to "." (was "$")
8
+ - Removed separator option (it was a temporary solution)
9
+
1
10
  ## 0.2.3 (July 27, 2011)
2
11
 
3
12
  Features:
@@ -44,8 +44,8 @@ module Metricsd
44
44
  #
45
45
  # # Group metrics using :group option.
46
46
  # Metricsd::Client.record_success("reads", :source => @hbase_table, :group => 'hbase')
47
- # # Group metrics using special syntax "group$metric".
48
- # Metricsd::Client.record_success("hbase$reads", :source => @hbase_table)
47
+ # # Group metrics using special syntax "group.metric".
48
+ # Metricsd::Client.record_success("hbase.reads", :source => @hbase_table)
49
49
  #
50
50
  class Client
51
51
  class << self
@@ -60,15 +60,13 @@ module Metricsd
60
60
  # @param [Boolean] is_success indicating whether request was successful.
61
61
  # @param [Float] time floating point number of seconds.
62
62
  # @param [Hash] opts options.
63
- # @option opts [String] :sep ("_") separator used to add suffixes +count+ and +time+.
64
63
  # @option opts [String] :group metrics group.
65
64
  # @option opts [String] :source metric source.
66
65
  #
67
66
  def record_hit(metric, is_success, time, opts = {})
68
- sep = opts[:sep] || opts[:separator] || '_'
69
67
  record_internal({
70
- "#{metric}#{sep}count" => is_success ? 1 : -1,
71
- "#{metric}#{sep}time" => (time * 1000).round
68
+ "#{metric}.status" => is_success ? 1 : -1,
69
+ "#{metric}.time" => (time * 1000).round
72
70
  }, opts
73
71
  )
74
72
  end
@@ -80,13 +78,11 @@ module Metricsd
80
78
  #
81
79
  # @param [String] metric is the metric name (like app.docs.upload)
82
80
  # @param [Hash] opts options.
83
- # @option opts [String] :sep ("_") separator used to add suffixes +count+ and +time+.
84
81
  # @option opts [String] :group metrics group.
85
82
  # @option opts [String] :source metric source.
86
83
  #
87
84
  def record_success(metric, opts = {})
88
- sep = opts[:sep] || opts[:separator] || '_'
89
- record_internal({"#{metric}#{sep}count" => 1}, opts)
85
+ record_internal({"#{metric}.status" => 1}, opts)
90
86
  end
91
87
 
92
88
  # Record failed boolean event.
@@ -96,13 +92,11 @@ module Metricsd
96
92
  #
97
93
  # @param [String] metric is the metric name (like app.docs.upload)
98
94
  # @param [Hash] opts options.
99
- # @option opts [String] :sep ("_") separator used to add suffixes +count+ and +time+.
100
95
  # @option opts [String] :group metrics group.
101
96
  # @option opts [String] :source metric source.
102
97
  #
103
98
  def record_failure(metric, opts = {})
104
- sep = opts[:sep] || opts[:separator] || '_'
105
- record_internal({"#{metric}#{sep}count" => -1}, opts)
99
+ record_internal({"#{metric}.status" => -1}, opts)
106
100
  end
107
101
 
108
102
  # Record timing info. Time should be a floating point
@@ -114,18 +108,16 @@ module Metricsd
114
108
  # @param [String] metric is the metric name (like app.docs.upload)
115
109
  # @param [Float] time floating point number of seconds.
116
110
  # @param [Hash] opts options.
117
- # @option opts [String] :sep ("_") separator used to add suffixes +count+ and +time+.
118
111
  # @option opts [String] :group metrics group.
119
112
  # @option opts [String] :source metric source.
120
113
  #
121
114
  def record_time(metric, time = nil, opts = {}, &block)
122
115
  opts, time = time, nil if Hash === time
123
- sep = opts[:sep] || opts[:separator] || '_'
124
116
  if time.nil?
125
117
  raise ArgumentError, "You should pass a block if time is not given" unless block_given?
126
118
  time = Benchmark.measure(&block).real
127
119
  end
128
- record_internal({"#{metric}#{sep}time" => (time * 1000).round}, opts)
120
+ record_internal({"#{metric}.time" => (time * 1000).round}, opts)
129
121
  end
130
122
 
131
123
  # Record an integer value.
@@ -136,13 +128,13 @@ module Metricsd
136
128
  # @param [String] metric is the metric name (like app.docs.upload)
137
129
  # @param [Integer] value metric value.
138
130
  # @param [Hash] opts options.
139
- # @option opts [String] :sep ("_") separator used to add suffixes +count+ and +time+.
140
131
  # @option opts [String] :group metrics group.
141
132
  # @option opts [String] :source metric source.
142
133
  #
143
134
  def record_value(metric, value, opts = {})
144
135
  record_internal({metric => value.round}, opts)
145
136
  end
137
+ alias :record :record_value
146
138
 
147
139
  # Record multiple integer values.
148
140
  #
@@ -151,7 +143,6 @@ module Metricsd
151
143
  #
152
144
  # @param [Hash] metrics a +Hash+ that maps metrics names to their values.
153
145
  # @param [Hash] opts options.
154
- # @option opts [String] :sep ("_") separator used to add suffixes +count+ and +time+.
155
146
  # @option opts [String] :group metrics group.
156
147
  # @option opts [String] :source metric source.
157
148
  #
@@ -225,7 +216,7 @@ module Metricsd
225
216
  # protocol.
226
217
  def pack(key, value, opts)
227
218
  group = opts[:group] || Metricsd.default_group || ''
228
- key = "#{group}$#{key}" unless group.empty?
219
+ key = "#{group}.#{key}" unless group.empty?
229
220
  opts[:source].empty? ? "#{key}:#{value}" : "#{opts[:source]}@#{key}:#{value}"
230
221
  end
231
222
  end
@@ -1,3 +1,3 @@
1
1
  module Metricsd
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -34,98 +34,83 @@ describe Metricsd::Client do
34
34
 
35
35
  describe '.record_hit' do
36
36
  it 'should send two metrics in a single packet' do
37
- @socket.should_receive(:send).with('all@custom.metric_count:1;all@custom.metric_time:450', 0)
37
+ @socket.should_receive(:send).with('all@custom.metric.status:1;all@custom.metric.time:450', 0)
38
38
  Metricsd::Client.record_hit('custom.metric', true, 0.45)
39
39
  end
40
40
 
41
41
  it 'should handle is_success=false' do
42
- @socket.should_receive(:send).with('all@custom.metric_count:-1;all@custom.metric_time:450', 0)
42
+ @socket.should_receive(:send).with('all@custom.metric.status:-1;all@custom.metric.time:450', 0)
43
43
  Metricsd::Client.record_hit('custom.metric', false, 0.45)
44
44
  end
45
45
 
46
- it 'should change separator if :sep option is specified' do
47
- @socket.should_receive(:send).with('all@custom.metric!count:1;all@custom.metric!time:450', 0)
48
- Metricsd::Client.record_hit('custom.metric', true, 0.45, :sep => '!')
49
- end
50
-
51
46
  it 'should apply group to both the metrics' do
52
- @socket.should_receive(:send).with('all@test$custom.metric_count:1;all@test$custom.metric_time:450', 0)
47
+ @socket.should_receive(:send).with('all@test.custom.metric.status:1;all@test.custom.metric.time:450', 0)
53
48
  Metricsd::Client.record_hit('custom.metric', true, 0.45, :group => 'test')
54
49
  end
55
50
 
56
51
  it 'should apply source if empty string passed' do
57
- @socket.should_receive(:send).with('test@custom.metric_count:1;test@custom.metric_time:450', 0)
52
+ @socket.should_receive(:send).with('test@custom.metric.status:1;test@custom.metric.time:450', 0)
58
53
  Metricsd::Client.record_hit('custom.metric', true, 0.45, :source => '')
59
54
  end
60
55
 
61
56
  it 'should apply source if specified' do
62
- @socket.should_receive(:send).with('test2@custom.metric_count:1;test2@custom.metric_time:450', 0)
57
+ @socket.should_receive(:send).with('test2@custom.metric.status:1;test2@custom.metric.time:450', 0)
63
58
  Metricsd::Client.record_hit('custom.metric', true, 0.45, :source => 'test2')
64
59
  end
65
60
  end
66
61
 
67
62
  describe '.record_success' do
68
63
  it 'should record successes' do
69
- @socket.should_receive(:send).with('all@custom.metric_count:1', 0)
64
+ @socket.should_receive(:send).with('all@custom.metric.status:1', 0)
70
65
  Metricsd::Client.record_success('custom.metric')
71
66
  end
72
67
 
73
- it 'should change separator if :sep option is specified' do
74
- @socket.should_receive(:send).with('all@custom.metric!count:1', 0)
75
- Metricsd::Client.record_success('custom.metric', :sep => '!')
76
- end
77
-
78
68
  it 'should apply group if specified' do
79
- @socket.should_receive(:send).with('all@test$custom.metric_count:1', 0)
69
+ @socket.should_receive(:send).with('all@test.custom.metric.status:1', 0)
80
70
  Metricsd::Client.record_success('custom.metric', :group => 'test')
81
71
  end
82
72
 
83
73
  it 'should apply source if empty string passed' do
84
- @socket.should_receive(:send).with('test@custom.metric_count:1', 0)
74
+ @socket.should_receive(:send).with('test@custom.metric.status:1', 0)
85
75
  Metricsd::Client.record_success('custom.metric', :source => '')
86
76
  end
87
77
 
88
78
  it 'should apply source specified' do
89
- @socket.should_receive(:send).with('test2@custom.metric_count:1', 0)
79
+ @socket.should_receive(:send).with('test2@custom.metric.status:1', 0)
90
80
  Metricsd::Client.record_success('custom.metric', :source => 'test2')
91
81
  end
92
82
  end
93
83
 
94
84
  describe '.record_failure' do
95
85
  it 'should record failures' do
96
- @socket.should_receive(:send).with('all@custom.metric_count:-1', 0)
86
+ @socket.should_receive(:send).with('all@custom.metric.status:-1', 0)
97
87
  Metricsd::Client.record_failure('custom.metric')
98
88
  end
99
89
 
100
- it 'should change separator if :sep option is specified' do
101
- @socket.should_receive(:send).with('all@custom.metric!count:-1', 0)
102
- Metricsd::Client.record_failure('custom.metric', :sep => '!')
103
- end
104
-
105
90
  it 'should apply group if specified' do
106
- @socket.should_receive(:send).with('all@test$custom.metric_count:-1', 0)
91
+ @socket.should_receive(:send).with('all@test.custom.metric.status:-1', 0)
107
92
  Metricsd::Client.record_failure('custom.metric', :group => 'test')
108
93
  end
109
94
 
110
95
  it 'should apply source if empty string passed' do
111
- @socket.should_receive(:send).with('test@custom.metric_count:-1', 0)
96
+ @socket.should_receive(:send).with('test@custom.metric.status:-1', 0)
112
97
  Metricsd::Client.record_failure('custom.metric', :source => '')
113
98
  end
114
99
 
115
100
  it 'should apply source specified' do
116
- @socket.should_receive(:send).with('test2@custom.metric_count:-1', 0)
101
+ @socket.should_receive(:send).with('test2@custom.metric.status:-1', 0)
117
102
  Metricsd::Client.record_failure('custom.metric', :source => 'test2')
118
103
  end
119
104
  end
120
105
 
121
106
  describe '.record_time' do
122
107
  it 'should record time if specified' do
123
- @socket.should_receive(:send).with('all@custom.metric_time:450', 0)
108
+ @socket.should_receive(:send).with('all@custom.metric.time:450', 0)
124
109
  Metricsd::Client.record_time('custom.metric', 0.45)
125
110
  end
126
111
 
127
112
  it 'should yield a block if time is not specified' do
128
- @socket.should_receive(:send).with(match(/all@custom.metric_time:1\d{2}/), 0)
113
+ @socket.should_receive(:send).with(match(/all@custom.metric.time:1\d{2}/), 0)
129
114
  yielded = false
130
115
  Metricsd::Client.record_time('custom.metric') do
131
116
  yielded = true
@@ -135,7 +120,7 @@ describe Metricsd::Client do
135
120
  end
136
121
 
137
122
  it 'should use options if time is not specified' do
138
- @socket.should_receive(:send).with(match(/all@custom.metric_time:\d+/), 0)
123
+ @socket.should_receive(:send).with(match(/all@custom.metric.time:\d+/), 0)
139
124
  yielded = false
140
125
  Metricsd::Client.record_time('custom.metric', {}) do
141
126
  yielded = true
@@ -143,23 +128,18 @@ describe Metricsd::Client do
143
128
  yielded.should be_true
144
129
  end
145
130
 
146
- it 'should change separator if :sep option is specified' do
147
- @socket.should_receive(:send).with('all@custom.metric!time:450', 0)
148
- Metricsd::Client.record_time('custom.metric', 0.45, :sep => '!')
149
- end
150
-
151
131
  it 'should apply group if specified' do
152
- @socket.should_receive(:send).with('all@test$custom.metric_time:450', 0)
132
+ @socket.should_receive(:send).with('all@test.custom.metric.time:450', 0)
153
133
  Metricsd::Client.record_time('custom.metric', 0.45, :group => 'test')
154
134
  end
155
135
 
156
136
  it 'should apply source if empty string passed' do
157
- @socket.should_receive(:send).with('test@custom.metric_time:450', 0)
137
+ @socket.should_receive(:send).with('test@custom.metric.time:450', 0)
158
138
  Metricsd::Client.record_time('custom.metric', 0.45, :source => '')
159
139
  end
160
140
 
161
141
  it 'should apply source specified' do
162
- @socket.should_receive(:send).with('test2@custom.metric_time:450', 0)
142
+ @socket.should_receive(:send).with('test2@custom.metric.time:450', 0)
163
143
  Metricsd::Client.record_time('custom.metric', 0.45, :source => 'test2')
164
144
  end
165
145
  end
@@ -171,7 +151,7 @@ describe Metricsd::Client do
171
151
  end
172
152
 
173
153
  it 'should apply group if specified' do
174
- @socket.should_receive(:send).with('all@test$custom.metric:23', 0)
154
+ @socket.should_receive(:send).with('all@test.custom.metric:23', 0)
175
155
  Metricsd::Client.record_value('custom.metric', 23, :group => 'test')
176
156
  end
177
157
 
@@ -187,13 +167,13 @@ describe Metricsd::Client do
187
167
 
188
168
  it 'should apply default group if specified' do
189
169
  Metricsd.default_group = 'grp'
190
- @socket.should_receive(:send).with('all@grp$custom.metric:23', 0)
170
+ @socket.should_receive(:send).with('all@grp.custom.metric:23', 0)
191
171
  Metricsd::Client.record_value('custom.metric', 23)
192
172
  end
193
173
 
194
174
  it 'should override default group with the specified one' do
195
175
  Metricsd.default_group = 'grp'
196
- @socket.should_receive(:send).with('all@group$custom.metric:23', 0)
176
+ @socket.should_receive(:send).with('all@group.custom.metric:23', 0)
197
177
  Metricsd::Client.record_value('custom.metric', 23, :group => 'group')
198
178
  end
199
179
 
@@ -211,7 +191,7 @@ describe Metricsd::Client do
211
191
  end
212
192
 
213
193
  it 'should apply group if specified' do
214
- @socket.should_receive(:send).with('all@test$another.metric:47;all@test$custom.metric:23', 0)
194
+ @socket.should_receive(:send).with('all@test.another.metric:47;all@test.custom.metric:23', 0)
215
195
  Metricsd::Client.record_values({'custom.metric' => 23, 'another.metric' => 47}, :group => 'test')
216
196
  end
217
197
 
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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmytro Shteflyuk
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-27 00:00:00 -04:00
18
+ date: 2011-08-11 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -100,6 +100,7 @@ extra_rdoc_files: []
100
100
  files:
101
101
  - .gitignore
102
102
  - .rvmrc
103
+ - .travis.yml
103
104
  - CHANGELOG.md
104
105
  - Gemfile
105
106
  - Guardfile