ruby-metrics 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.bundle/config +1 -2
  2. data/.gitignore +2 -0
  3. data/.rvmrc +1 -1
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +48 -0
  6. data/Gemfile +8 -2
  7. data/README.md +2 -1
  8. data/Rakefile +20 -7
  9. data/examples/gmontest.rb +17 -0
  10. data/examples/opentsdb_reporter.rb +77 -0
  11. data/lib/ruby-metrics.rb +3 -4
  12. data/lib/ruby-metrics/agent.rb +72 -16
  13. data/lib/ruby-metrics/instruments/counter.rb +19 -12
  14. data/lib/ruby-metrics/instruments/gauge.rb +13 -9
  15. data/lib/ruby-metrics/instruments/histogram.rb +46 -45
  16. data/lib/ruby-metrics/instruments/meter.rb +29 -26
  17. data/lib/ruby-metrics/instruments/timer.rb +38 -37
  18. data/lib/ruby-metrics/integration.rb +3 -4
  19. data/lib/ruby-metrics/logging.rb +0 -2
  20. data/lib/ruby-metrics/reporter.rb +28 -0
  21. data/lib/ruby-metrics/statistics/exponential_sample.rb +4 -5
  22. data/lib/ruby-metrics/statistics/uniform_sample.rb +1 -2
  23. data/lib/ruby-metrics/time_units.rb +13 -11
  24. data/lib/ruby-metrics/version.rb +1 -1
  25. data/ruby-metrics-ganglia.gemspec +21 -0
  26. data/ruby-metrics-librato.gemspec +20 -0
  27. data/ruby-metrics-opentsdb.gemspec +21 -0
  28. data/ruby-metrics.gemspec +18 -15
  29. data/spec/agent_spec.rb +13 -4
  30. data/spec/instruments/meter_spec.rb +40 -3
  31. data/spec/instruments/timer_spec.rb +1 -1
  32. data/spec/spec_helper.rb +1 -1
  33. metadata +106 -105
  34. data/Gemfile.lock +0 -34
  35. data/lib/ruby-metrics/instruments.rb +0 -89
  36. data/lib/ruby-metrics/instruments/base.rb +0 -23
  37. data/lib/ruby-metrics/statistics/sample.rb +0 -21
  38. data/spec/instruments/base_spec.rb +0 -16
  39. data/spec/instruments_spec.rb +0 -76
  40. data/spec/integration/webrick_spec.rb +0 -18
  41. data/spec/statistics/sample_spec.rb +0 -22
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ruby-metrics (0.8.6)
5
- json
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- diff-lcs (1.1.2)
11
- json (1.5.1)
12
- rack (1.2.2)
13
- rack-test (0.5.7)
14
- rack (>= 1.0)
15
- rspec (2.5.0)
16
- rspec-core (~> 2.5.0)
17
- rspec-expectations (~> 2.5.0)
18
- rspec-mocks (~> 2.5.0)
19
- rspec-core (2.5.1)
20
- rspec-expectations (2.5.0)
21
- diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.5.0)
23
- simplecov (0.4.0)
24
- simplecov-html (~> 0.4.0)
25
- simplecov-html (0.4.3)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- rack-test
32
- rspec
33
- ruby-metrics!
34
- simplecov (>= 0.3.8)
@@ -1,89 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'time_units')
2
-
3
- require File.join(File.dirname(__FILE__), 'statistics', 'sample')
4
- require File.join(File.dirname(__FILE__), 'statistics', 'uniform_sample')
5
- require File.join(File.dirname(__FILE__), 'statistics', 'exponential_sample')
6
-
7
- require 'json'
8
-
9
- module Metrics
10
- module Instruments
11
- @instruments = {}
12
- @types = {}
13
-
14
- def self.register_instrument(type, klass)
15
- @types[type] = klass
16
- end
17
-
18
- def self.registered_instruments
19
- @types
20
- end
21
-
22
- def self.register_with_options(type, name, options = {})
23
- @instruments[name] = @types[type].new(options)
24
- end
25
-
26
- def self.register(type, name, &block)
27
- @instruments[name] = @types[type].new(&block)
28
- end
29
-
30
- def self.unregister_all
31
- @instruments = {}
32
- end
33
-
34
- def self.registered
35
- @instruments
36
- end
37
-
38
- def self.to_json
39
- @instruments.to_json
40
- end
41
-
42
- module TypeMethods
43
-
44
- def register(type, name, &block)
45
- Metrics::Instruments.register(type, name, &block)
46
- end
47
-
48
- def register_with_options(type, name, options)
49
- Metrics::Instruments.register_with_options(type, name, options)
50
- end
51
-
52
- def counter(name)
53
- register(:counter, name)
54
- end
55
-
56
- def meter(name)
57
- register(:meter, name)
58
- end
59
-
60
- def gauge(name, &block)
61
- register(:gauge, name, &block)
62
- end
63
-
64
- def timer(name, options = {})
65
- register_with_options(:timer, name, options)
66
- end
67
-
68
- def uniform_histogram(name)
69
- register(:uniform_histogram, name)
70
- end
71
-
72
- # For backwards compatibility
73
- alias_method :histogram, :uniform_histogram
74
-
75
- def exponential_histogram(name)
76
- register(:exponential_histogram, name)
77
- end
78
- end
79
-
80
- end
81
- end
82
-
83
- require File.join(File.dirname(__FILE__), 'instruments', 'base')
84
- require File.join(File.dirname(__FILE__), 'instruments', 'counter')
85
- require File.join(File.dirname(__FILE__), 'instruments', 'meter')
86
- require File.join(File.dirname(__FILE__), 'instruments', 'gauge')
87
- require File.join(File.dirname(__FILE__), 'instruments', 'histogram')
88
- require File.join(File.dirname(__FILE__), 'instruments', 'timer')
89
-
@@ -1,23 +0,0 @@
1
- module Metrics
2
- module Instruments
3
- class Base
4
-
5
- def to_i
6
- raise NotImplementedError
7
- end
8
-
9
- def to_json(*_)
10
- raise NotImplementedError
11
- end
12
-
13
- def to_s
14
- self.to_json
15
- end
16
-
17
- def to_f
18
- raise NotImplementedError
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- module Metrics
2
- module Statistics
3
- class Sample
4
- def clear
5
- raise NotImplementedError
6
- end
7
-
8
- def size
9
- raise NotImplementedError
10
- end
11
-
12
- def update(value)
13
- raise NotImplementedError
14
- end
15
-
16
- def values
17
- raise NotImplementedError
18
- end
19
- end
20
- end
21
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Metrics::Instruments::Base do
4
- before(:each) do
5
- @base = Metrics::Instruments::Base.new
6
- end
7
-
8
- %w( to_i to_f to_json to_s ).each do |method|
9
- it "should raise a NotImplementedError for ##{method}" do
10
- lambda do
11
- @base.send(method)
12
- end.should raise_exception(NotImplementedError)
13
- end
14
- end
15
-
16
- end
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Metrics::Instruments do
4
- before(:each) do
5
- @instruments = Metrics::Instruments
6
- @instruments.unregister_all
7
-
8
- @counter = Metrics::Instruments::Counter.new
9
- @meter = Metrics::Instruments::Meter.new
10
- end
11
-
12
- it "should initially have no instruments in its hash" do
13
- @instruments.registered.should == {}
14
- end
15
-
16
- it "should allow for registering a Counter instrument" do
17
- Metrics::Instruments::Counter.stub!(:new).and_return @counter
18
- @instruments.register(:counter, :test_counter).should == @counter
19
- @instruments.registered.should == {:test_counter => @counter}
20
- end
21
-
22
- it "should allow for registering a Meter instrument" do
23
- Metrics::Instruments::Meter.stub!(:new).and_return @meter
24
- @instruments.register(:meter, :test_meter).should == @meter
25
- @instruments.registered.should == {:test_meter => @meter}
26
- end
27
-
28
- it "should allow for registering a Histogram instrument using uniform sampling" do
29
- histogram = Metrics::Instruments::UniformHistogram.new
30
- Metrics::Instruments::UniformHistogram.stub!(:new).and_return histogram
31
- @instruments.register(:uniform_histogram, :test_histogram).should == histogram
32
- @instruments.registered.should == {:test_histogram => histogram}
33
- end
34
-
35
- it "should allow for registering a Histogram instrument using exponentially decaying sampling" do
36
- histogram = Metrics::Instruments::ExponentialHistogram.new
37
- Metrics::Instruments::ExponentialHistogram.stub!(:new).and_return histogram
38
- @instruments.register(:exponential_histogram, :test_histogram).should == histogram
39
- @instruments.registered.should == {:test_histogram => histogram}
40
- end
41
-
42
-
43
- it "should generate JSON correctly" do
44
- Metrics::Instruments::Meter.stub!(:new).and_return @meter
45
- @instruments.register(:meter, :test_meter).should == @meter
46
- @instruments.registered.should == {:test_meter => @meter}
47
-
48
- @instruments.to_json.should == %({"test_meter":{"one_minute_rate":0.0,"five_minute_rate":0.0,"fifteen_minute_rate":0.0}})
49
- end
50
-
51
- it "should not allow for creating a gauge with no block" do
52
- lambda do
53
- @instruments.register :gauge, :test_gauge
54
- end.should raise_error(ArgumentError)
55
- end
56
-
57
- it "should allow for creating a gauge with a block" do
58
- proc = Proc.new { "result" }
59
- @instruments.register :gauge, :test_gauge, &proc
60
- end
61
-
62
- context '#register_instrument' do
63
- it 'registers a new instrument' do
64
- lambda { Metrics::Instruments.register_instrument(:test, String) }.should_not raise_error
65
- end
66
-
67
- it 'returns the list of registered instruments' do
68
- Metrics::Instruments.register_instrument(:str, String)
69
- Metrics::Instruments.register_instrument(:int, Fixnum)
70
-
71
- inst = Metrics::Instruments.registered_instruments
72
- inst[:str].should == String
73
- inst[:int].should == Fixnum
74
- end
75
- end
76
- end
@@ -1,18 +0,0 @@
1
- require "rack/test"
2
-
3
- describe Metrics::Integration::WEBrick do
4
-
5
- it "should start the WEBrick thread" do
6
- Thread.stub!(:new).and_return do |block|
7
- block.call
8
- end
9
-
10
- mock_server = mock(WEBrick::HTTPServer)
11
- WEBrick::HTTPServer.should_receive(:new).and_return mock_server
12
- mock_server.should_receive(:mount)
13
- mock_server.should_receive(:start)
14
-
15
- Metrics::Integration::WEBrick.start
16
- end
17
-
18
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Metrics::Statistics::Sample do
4
- before(:each) do
5
- @sample = Metrics::Statistics::Sample.new
6
- end
7
-
8
- %w( clear values size ).each do |method|
9
- it "should raise a NotImplementedError for ##{method}" do
10
- lambda do
11
- @sample.send(method)
12
- end.should raise_exception(NotImplementedError)
13
- end
14
- end
15
-
16
- it "should raise a NotImplementedError for 'update'" do
17
- lambda do
18
- @sample.update(0)
19
- end.should raise_exception(NotImplementedError)
20
- end
21
-
22
- end