metricize 0.5.0 → 0.5.1
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/metricize/client.rb +2 -3
- data/lib/metricize/forwarder.rb +3 -4
- data/lib/metricize/shared.rb +1 -0
- data/lib/metricize/version.rb +1 -1
- data/spec/lib/metricize_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50fc0c83fce168261f1ef1ecb57e45a1b479584b
|
4
|
+
data.tar.gz: 99ab9d17c1453a90a7653acefe1da2eec6b958cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c8b2bdfc77e0b6448707173c7b6f5f4d434441cae636a62aab45f1ff367beedb60e4c5f06bb9beb550f0e79402c0ca2205e96a19fef5d74f8247bba7a4adcd3
|
7
|
+
data.tar.gz: 56be1f2d4cfce176300a8d0dd0d7f45cb63ad52c2efa8517358d43e9f002997f1a042d0006151c87e309d74ef9a005e83531500c27b452c5bb48f52064ba5478
|
data/lib/metricize/client.rb
CHANGED
@@ -4,10 +4,9 @@ module Metricize
|
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
6
|
@prefix = options[:prefix]
|
7
|
-
@
|
7
|
+
@log_sampling_ratio = options[:log_sampling_ratio] || 0.10
|
8
8
|
establish_logger(options)
|
9
9
|
initialize_redis(options)
|
10
|
-
establish_redis_connection
|
11
10
|
end
|
12
11
|
|
13
12
|
def increment(name, options = {})
|
@@ -43,7 +42,7 @@ module Metricize
|
|
43
42
|
with_error_handling do
|
44
43
|
@redis.lpush(@queue_name, data)
|
45
44
|
end
|
46
|
-
return unless rand < @
|
45
|
+
return unless rand < @log_sampling_ratio
|
47
46
|
msg = "#{name.gsub('.', '_')}=#{value}" # splunk chokes on dots in field names
|
48
47
|
msg << ", metric_source=#{options[:source].gsub('.', '_')}" if options[:source]
|
49
48
|
log_message msg, :info
|
data/lib/metricize/forwarder.rb
CHANGED
@@ -7,10 +7,9 @@ module Metricize
|
|
7
7
|
@username = options.fetch(:username)
|
8
8
|
@remote_url = options[:remote_url] || 'metrics-api.librato.com/v1/metrics'
|
9
9
|
@remote_timeout = options[:remote_timeout] || 10
|
10
|
-
@
|
10
|
+
@batch_size = options[:batch_size] || 5000
|
11
11
|
establish_logger(options)
|
12
12
|
initialize_redis(options)
|
13
|
-
establish_redis_connection
|
14
13
|
end
|
15
14
|
|
16
15
|
def go!
|
@@ -29,9 +28,9 @@ module Metricize
|
|
29
28
|
|
30
29
|
def lshift_queue
|
31
30
|
return [] unless queue_length > 0
|
32
|
-
current_batch = @redis.lrange(@queue_name, 0, @
|
31
|
+
current_batch = @redis.lrange(@queue_name, 0, @batch_size - 1)
|
33
32
|
# ltrim indexes are 0 based and somewhat confusing -- see http://redis.io/commands/ltrim
|
34
|
-
@redis.ltrim(@queue_name, 0, -1-@
|
33
|
+
@redis.ltrim(@queue_name, 0, -1-@batch_size)
|
35
34
|
current_batch.map {|metric| JSON.parse(metric, :symbolize_names => true) }
|
36
35
|
end
|
37
36
|
|
data/lib/metricize/shared.rb
CHANGED
data/lib/metricize/version.rb
CHANGED
data/spec/lib/metricize_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Metricize do
|
|
8
8
|
:username => 'name@example.com',
|
9
9
|
:logger => logger) }
|
10
10
|
|
11
|
-
let(:client) { Metricize::Client.new( :prefix => 'prefix', :logger => logger ) }
|
11
|
+
let(:client) { Metricize::Client.new( :prefix => 'prefix', :logger => logger, :log_sampling_ratio => 1.0 ) }
|
12
12
|
|
13
13
|
before do
|
14
14
|
Timecop.freeze(Time.at(1234))
|
@@ -57,7 +57,7 @@ describe Metricize do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "limits the number of metrics forwarded to the remote in a single request" do
|
60
|
-
forwarder.instance_variable_set(:@
|
60
|
+
forwarder.instance_variable_set(:@batch_size, 3)
|
61
61
|
7.times { | n| client.increment('stat.name' + n.to_s) }
|
62
62
|
forwarder.go!
|
63
63
|
expect(forwarder.send(:queue_length)).to eq 4
|
@@ -133,8 +133,8 @@ describe Metricize do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
it "logs in splunk format a sampling of metrics" do
|
136
|
+
client = Metricize::Client.new( :prefix => 'prefix', :logger => logger, :log_sampling_ratio => 0.10 )
|
136
137
|
srand(1234)
|
137
|
-
logger.should_receive(:info) # ignore initial connection message
|
138
138
|
logger.should_receive(:info).with(/prefix_value1=10.0/m).exactly(9).times
|
139
139
|
100.times { client.measure('value1', 10) }
|
140
140
|
logger.should_receive(:info).with(/prefix_value2=20.0/m).exactly(6).times
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metricize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt McNeil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|