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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cee4500b798220d2e7720c6b7fbf24dbb4dfee6a
4
- data.tar.gz: 654246270c58ae875d0d6f23f1099c38da87acc8
3
+ metadata.gz: 50fc0c83fce168261f1ef1ecb57e45a1b479584b
4
+ data.tar.gz: 99ab9d17c1453a90a7653acefe1da2eec6b958cc
5
5
  SHA512:
6
- metadata.gz: eb76d39f56af655011c4037c155e326fca7c91ce6d1c8bd43b4843e5a22f731ccafe9ecc19b12fd2051dbc82b3fa8c4e29083a577db43c1051e3983b946c9442
7
- data.tar.gz: 5004d43b141bf78fe02aedcc82fa038f00ad7a257fb0701a3a2db69cc0310859da6b23bca14a9dec123ce3c279ff152da939fba5f8bd70011ffb9c4ca5d0453b
6
+ metadata.gz: 2c8b2bdfc77e0b6448707173c7b6f5f4d434441cae636a62aab45f1ff367beedb60e4c5f06bb9beb550f0e79402c0ca2205e96a19fef5d74f8247bba7a4adcd3
7
+ data.tar.gz: 56be1f2d4cfce176300a8d0dd0d7f45cb63ad52c2efa8517358d43e9f002997f1a042d0006151c87e309d74ef9a005e83531500c27b452c5bb48f52064ba5478
@@ -4,10 +4,9 @@ module Metricize
4
4
 
5
5
  def initialize(options = {})
6
6
  @prefix = options[:prefix]
7
- @sampling_ratio = options[:sampling_ratio] || 0.10
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 < @sampling_ratio
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
@@ -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
- @max_batch_size = options[:max_batch_size] || 5000
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, @max_batch_size - 1)
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-@max_batch_size)
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
 
@@ -15,6 +15,7 @@ module Metricize
15
15
  @queue_host = options[:queue_host] || '127.0.0.1'
16
16
  @queue_port = options[:queue_port] || 6379
17
17
  @queue_name = options[:queue_name] || 'metricize_queue'
18
+ establish_redis_connection
18
19
  end
19
20
 
20
21
  def establish_logger(options)
@@ -1,3 +1,3 @@
1
1
  module Metricize
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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(:@max_batch_size, 3)
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.0
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-29 00:00:00.000000000 Z
11
+ date: 2013-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler