Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Have the instruments register themselves

  • Loading branch information...
commit c3e12c5a0b75953e52681b8c45ad1688bd5f706c 1 parent e08d2f1
@dj2 dj2 authored
View
30 lib/ruby-metrics/instruments.rb
@@ -4,28 +4,16 @@
require File.join(File.dirname(__FILE__), 'statistics', 'uniform_sample')
require File.join(File.dirname(__FILE__), 'statistics', 'exponential_sample')
-require File.join(File.dirname(__FILE__), 'instruments', 'base')
-require File.join(File.dirname(__FILE__), 'instruments', 'counter')
-require File.join(File.dirname(__FILE__), 'instruments', 'meter')
-require File.join(File.dirname(__FILE__), 'instruments', 'gauge')
-require File.join(File.dirname(__FILE__), 'instruments', 'histogram')
-require File.join(File.dirname(__FILE__), 'instruments', 'timer')
-
-
require 'json'
module Metrics
module Instruments
@instruments = {}
-
- @types = {
- :counter => Counter,
- :meter => Meter,
- :gauge => Gauge,
- :exponential_histogram => ExponentialHistogram,
- :uniform_histogram => UniformHistogram,
- :timer => Timer
- }
+ @types = {}
+
+ def self.register_instrument(type, klass)
+ @types[type] = klass
+ end
def self.register_with_options(type, name, options = {})
@instruments[name] = @types[type].new(options)
@@ -87,3 +75,11 @@ def exponential_histogram(name)
end
end
+
+require File.join(File.dirname(__FILE__), 'instruments', 'base')
+require File.join(File.dirname(__FILE__), 'instruments', 'counter')
+require File.join(File.dirname(__FILE__), 'instruments', 'meter')
+require File.join(File.dirname(__FILE__), 'instruments', 'gauge')
+require File.join(File.dirname(__FILE__), 'instruments', 'histogram')
+require File.join(File.dirname(__FILE__), 'instruments', 'timer')
+
View
2  lib/ruby-metrics/instruments/counter.rb
@@ -29,5 +29,7 @@ def to_s
end
end
+
+ register_instrument(:counter, Counter)
end
end
View
2  lib/ruby-metrics/instruments/gauge.rb
@@ -16,5 +16,7 @@ def to_s
end
end
+
+ register_instrument(:gauge, Gauge)
end
end
View
7 lib/ruby-metrics/instruments/histogram.rb
@@ -166,13 +166,16 @@ def initialize
super(:exponential)
end
end
-
+
+ register_instrument(:exponential_histogram, ExponentialHistogram)
+
class UniformHistogram < Histogram
def initialize
super(:uniform)
end
end
-
+
+ register_instrument(:uniform_histogram, UniformHistogram)
end
end
View
2  lib/ruby-metrics/instruments/meter.rb
@@ -93,5 +93,7 @@ def to_s
end
end
+
+ register_instrument(:meter, Meter)
end
end
View
2  lib/ruby-metrics/instruments/timer.rb
@@ -123,6 +123,8 @@ def scale_duration_to_ns(value, unit)
end
end
+
+ register_instrument(:timer, Timer)
end
end

0 comments on commit c3e12c5

Please sign in to comment.
Something went wrong with that request. Please try again.