librato-metrics 0.1.0 → 0.2.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/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.6
3
+ - 1.8.7
4
+ - ree
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - jruby
8
+ - rbx
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## Changelog
2
+
3
+ ### Version 0.2.0
4
+ * Fix bug with stale excon connections not reconnecting
5
+ * Add custom User-Agent
6
+ * Items added to Queue objects have their measure_time set automatically
7
+ * Metric 'type' key can be string or symbol, thanks neilmock
8
+
9
+ ### Version 0.1.0
10
+ * Initial release
data/LICENSE CHANGED
@@ -1,11 +1,24 @@
1
- Librato Software Confidential and Proprietary
1
+ Copyright (c) 2011. Librato, Inc.
2
+ All rights reserved.
2
3
 
3
- Copyright (C) 2011, Librato Inc. ALL RIGHTS RESERVED.
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the <organization> nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
4
14
 
5
- Except as specifically permitted herein, no portion of the
6
- information, including but not limited to object code and source
7
- code, may be reproduced, modified, distributed, republished or
8
- otherwise utilized in any form or by any means for any purpose
9
- without the prior written permission of Librato Inc.
10
-
11
- Visit http://librato.com for more information.
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -101,6 +101,14 @@ Get the 20 most recent 15 minute data point rollups for `temperature`:
101
101
 
102
102
  There are many more options supported for querying, take a look at the [REST API docs](http://dev.librato.com/v1/get/gauges/:name) for more details.
103
103
 
104
+ ## Known Issues & Coming Improvements
105
+
106
+ This is an early release and as such is lacking some capabilities slated for future releases.
107
+
108
+ * Query actions currently do not auto-paginate with large result sets
109
+ * Very large metric POSTs are not automatically chunked for performance
110
+ * Some error conditions currently lack gem-specific exceptions
111
+
104
112
  ## Contribution
105
113
 
106
114
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -2,8 +2,11 @@ module Librato
2
2
  module Metrics
3
3
  class Queue
4
4
 
5
- def initialize
5
+ attr_accessor :skip_measurement_times
6
+
7
+ def initialize(options={})
6
8
  @queued ||= {}
9
+ @skip_measurement_times = options.delete(:skip_measurement_times)
7
10
  end
8
11
 
9
12
  # Add a metric entry to the metric set:
@@ -13,15 +16,19 @@ module Librato
13
16
  def add(args)
14
17
  args.each do |key, value|
15
18
  if value.respond_to?(:each)
16
- type = (value.delete(:type) || 'gauge')
17
- type = ("#{type}s").to_sym
18
- value[:name] = key.to_s
19
- @queued[type] ||= []
20
- @queued[type] << value
19
+ metric = value
20
+ metric[:name] = key.to_s
21
+ type = metric.delete(:type) || metric.delete('type') || 'gauge'
21
22
  else
22
- @queued[:gauges] ||= []
23
- @queued[:gauges] << {:name => key.to_s, :value => value}
23
+ metric = {:name => key.to_s, :value => value}
24
+ type = :gauge
25
+ end
26
+ type = ("#{type}s").to_sym
27
+ unless skip_measurement_times
28
+ metric[:measure_time] ||= epoch_time
24
29
  end
30
+ @queued[type] ||= []
31
+ @queued[type] << metric
25
32
  end
26
33
  queued
27
34
  end
@@ -105,6 +112,10 @@ module Librato
105
112
  Librato::Metrics::Persistence.const_get(type).new
106
113
  end
107
114
 
115
+ def epoch_time
116
+ Time.now.to_i
117
+ end
118
+
108
119
  end
109
120
  end
110
- end
121
+ end
@@ -44,7 +44,9 @@ module Librato
44
44
  end
45
45
 
46
46
  def connection
47
- @connection ||= Excon.new(self.api_endpoint, :headers => {'Authorization' => auth_header})
47
+ # TODO: upate when excon connection recovery is improved.
48
+ # @connection ||= Excon.new(self.api_endpoint, :headers => common_headers)
49
+ Excon.new(self.api_endpoint, :headers => common_headers)
48
50
  end
49
51
 
50
52
  # Purge current credentials and connection
@@ -76,11 +78,16 @@ module Librato
76
78
  # Submit all queued metrics
77
79
  #
78
80
  def submit(args)
79
- @queue ||= Queue.new
81
+ @queue ||= Queue.new(:skip_measurement_times => true)
80
82
  @queue.add args
81
83
  @queue.submit
82
84
  end
83
85
 
86
+ def user_agent
87
+ ruby_ver = "#{RUBY_ENGINE}; #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}; #{RUBY_PLATFORM}"
88
+ "librato-metrics/#{Metrics::VERSION} (#{ruby_ver}) direct-excon/#{Excon::VERSION}"
89
+ end
90
+
84
91
  private
85
92
 
86
93
  def auth_header
@@ -89,6 +96,10 @@ module Librato
89
96
  "Basic #{encoded}"
90
97
  end
91
98
 
99
+ def common_headers
100
+ {'Authorization' => auth_header, 'User-Agent' => user_agent}
101
+ end
102
+
92
103
  def flush_persistence
93
104
  @persistence = nil
94
105
  end
@@ -1,5 +1,5 @@
1
1
  module Librato
2
2
  module Metrics
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.authors = ["Matt Sanders"]
18
18
  s.email = 'matt@librato.com'
19
- s.homepage = 'http://metrics.librato.com'
19
+ s.homepage = 'https://github.com/librato/librato-metrics'
20
20
 
21
21
  s.require_paths = %w[lib]
22
22
 
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency 'excon', '~>0.7.12'
28
28
 
29
29
  ## development dependencies
30
+ s.add_development_dependency 'rake'
30
31
  s.add_development_dependency 'rspec', '~>2.6.0'
31
32
  s.add_development_dependency 'yard'
32
33
  s.add_development_dependency 'rdiscount' # for yard
@@ -5,25 +5,35 @@ module Librato
5
5
 
6
6
  describe Queue do
7
7
 
8
- describe "#add" do
8
+ before(:all) do
9
+ @time = Time.now.to_i
10
+ Librato::Metrics::Queue.stub(:epoch_time).and_return(@time)
11
+ end
9
12
 
13
+ describe "#add" do
10
14
  context "with single hash argument" do
11
15
  it "should record a key-value gauge" do
12
16
  subject.add :foo => 3000
13
- subject.queued.should eql({:gauges => [{:name => 'foo', :value => 3000}]})
17
+ subject.queued.should eql({:gauges => [{:name => 'foo', :value => 3000, :measure_time => @time}]})
14
18
  end
15
19
  end
16
20
 
17
21
  context "with specified metric type" do
18
22
  it "should record counters" do
19
23
  subject.add :total_visits => {:type => :counter, :value => 4000}
20
- expected = {:counters => [{:name => 'total_visits', :value => 4000}]}
24
+ expected = {:counters => [{:name => 'total_visits', :value => 4000, :measure_time => @time}]}
21
25
  subject.queued.should eql expected
22
26
  end
23
27
 
24
28
  it "should record gauges" do
25
29
  subject.add :temperature => {:type => :gauge, :value => 34}
26
- expected = {:gauges => [{:name => 'temperature', :value => 34}]}
30
+ expected = {:gauges => [{:name => 'temperature', :value => 34, :measure_time => @time}]}
31
+ subject.queued.should eql expected
32
+ end
33
+
34
+ it "should accept type key as string or a symbol" do
35
+ subject.add :total_visits => {"type" => "counter", :value => 4000}
36
+ expected = {:counters => [{:name => 'total_visits', :value => 4000}]}
27
37
  subject.queued.should eql expected
28
38
  end
29
39
  end
@@ -44,43 +54,39 @@ module Librato
44
54
  context "with multiple metrics" do
45
55
  it "should record" do
46
56
  subject.add :foo => 123, :bar => 345, :baz => 567
47
- expected = {:gauges=>[{:name=>"foo", :value=>123}, {:name=>"bar", :value=>345}, {:name=>"baz", :value=>567}]}
57
+ expected = {:gauges=>[{:name=>"foo", :value=>123, :measure_time => @time},
58
+ {:name=>"bar", :value=>345, :measure_time => @time},
59
+ {:name=>"baz", :value=>567, :measure_time => @time}]}
48
60
  subject.queued.should eql expected
49
61
  end
50
62
  end
51
-
52
63
  end
53
64
 
54
65
  describe "#counters" do
55
-
56
66
  it "should return currently queued counters" do
57
67
  subject.add :transactions => {:type => :counter, :value => 12345},
58
- :register_cents => {:type => :gauge, :value => 211101}
59
- subject.counters.should eql [{:name => 'transactions', :value => 12345}]
68
+ :register_cents => {:type => :gauge, :value => 211101}
69
+ subject.counters.should eql [{:name => 'transactions', :value => 12345, :measure_time => @time}]
60
70
  end
61
71
 
62
72
  it "should return [] when no queued counters" do
63
73
  subject.counters.should eql []
64
74
  end
65
-
66
75
  end
67
76
 
68
77
  describe "#gauges" do
69
-
70
78
  it "should return currently queued gauges" do
71
79
  subject.add :transactions => {:type => :counter, :value => 12345},
72
80
  :register_cents => {:type => :gauge, :value => 211101}
73
- subject.gauges.should eql [{:name => 'register_cents', :value => 211101}]
81
+ subject.gauges.should eql [{:name => 'register_cents', :value => 211101, :measure_time => @time}]
74
82
  end
75
83
 
76
84
  it "should return [] when no queued gauges" do
77
85
  subject.gauges.should eql []
78
86
  end
79
-
80
87
  end
81
88
 
82
89
  describe "#submit" do
83
-
84
90
  before(:all) do
85
91
  Librato::Metrics.authenticate 'me@librato.com', 'foo'
86
92
  Librato::Metrics.persistence = :test
@@ -103,13 +109,10 @@ module Librato
103
109
  subject.queued.should_not be_empty
104
110
  end
105
111
  end
106
-
107
112
  end
108
113
 
109
114
  describe "#time" do
110
-
111
115
  context "with metric name only" do
112
-
113
116
  it "should queue metric with timed value" do
114
117
  subject.time :sleeping do
115
118
  sleep 0.1
@@ -119,11 +122,9 @@ module Librato
119
122
  queued[:value].should be > 100
120
123
  queued[:value].should be_within(30).of(100)
121
124
  end
122
-
123
125
  end
124
126
 
125
127
  context "with metric and options" do
126
-
127
128
  it "should queue metric with value and options" do
128
129
  subject.time :sleep_two, :source => 'app1', :period => 2 do
129
130
  sleep 0.05
@@ -135,12 +136,10 @@ module Librato
135
136
  queued[:value].should be > 50
136
137
  queued[:value].should be_within(30).of(50)
137
138
  end
138
-
139
139
  end
140
-
141
140
  end
142
141
 
143
142
  end # MetricSet
144
143
 
145
144
  end
146
- end
145
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librato-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000Z
12
+ date: 2011-12-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
16
- requirement: &70180001393620 !ruby/object:Gem::Requirement
16
+ requirement: &70208460547940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 0.7.12
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70180001393620
24
+ version_requirements: *70208460547940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70208460547480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70208460547480
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &70180001393140 !ruby/object:Gem::Requirement
38
+ requirement: &70208460546880 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 2.6.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70180001393140
46
+ version_requirements: *70208460546880
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: yard
38
- requirement: &70180001392760 !ruby/object:Gem::Requirement
49
+ requirement: &70208460546440 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70180001392760
57
+ version_requirements: *70208460546440
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rdiscount
49
- requirement: &70180001392300 !ruby/object:Gem::Requirement
60
+ requirement: &70208460545960 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70180001392300
68
+ version_requirements: *70208460545960
58
69
  description: An easy to use ruby wrapper for Librato's Metrics API
59
70
  email: matt@librato.com
60
71
  executables: []
@@ -63,6 +74,8 @@ extra_rdoc_files:
63
74
  - LICENSE
64
75
  files:
65
76
  - .gitignore
77
+ - .travis.yml
78
+ - CHANGELOG.md
66
79
  - Gemfile
67
80
  - LICENSE
68
81
  - README.md
@@ -80,7 +93,7 @@ files:
80
93
  - spec/unit/metrics/queue_spec.rb
81
94
  - spec/unit/metrics/simple_spec.rb
82
95
  - spec/unit/metrics_spec.rb
83
- homepage: http://metrics.librato.com
96
+ homepage: https://github.com/librato/librato-metrics
84
97
  licenses: []
85
98
  post_install_message:
86
99
  rdoc_options:
@@ -101,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
114
  version: '0'
102
115
  requirements: []
103
116
  rubyforge_project:
104
- rubygems_version: 1.8.10
117
+ rubygems_version: 1.8.12
105
118
  signing_key:
106
119
  specification_version: 2
107
120
  summary: Ruby wrapper for Librato's Metrics API