Class: Statue::Metric
- Inherits:
-
Object
- Object
- Statue::Metric
- Defined in:
- lib/statue/metric.rb
Constant Summary collapse
- TYPES =
{ c: 'increment', ms: 'measure', g: 'gauge', kv: 'key/value', s: 'set' }
Instance Attribute Summary collapse
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#type ⇒ Object
Returns the value of attribute type.
-
#type_description ⇒ Object
readonly
Returns the value of attribute type_description.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .counter(name, value = 1, options = {}) ⇒ Object
- .gauge(name, value, options = {}) ⇒ Object
- .measure(name, options = {}, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Metric
constructor
A new instance of Metric.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Metric
Returns a new instance of Metric.
30 31 32 33 34 35 36 37 |
# File 'lib/statue/metric.rb', line 30 def initialize( = {}) @type = .fetch(:type) @name = .fetch(:name) @value = .fetch(:value) @type_description = TYPES[type] or raise ArgumentError, "invalid type: #{type}" @sample_rate = [:sample_rate] || 1.0 @full_name = Statue.namespace ? "#{Statue.namespace}.#{@name}" : @name end |
Instance Attribute Details
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
14 15 16 |
# File 'lib/statue/metric.rb', line 14 def full_name @full_name end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/statue/metric.rb', line 13 def name @name end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
13 14 15 |
# File 'lib/statue/metric.rb', line 13 def sample_rate @sample_rate end |
#type ⇒ Object
Returns the value of attribute type.
13 14 15 |
# File 'lib/statue/metric.rb', line 13 def type @type end |
#type_description ⇒ Object (readonly)
Returns the value of attribute type_description.
14 15 16 |
# File 'lib/statue/metric.rb', line 14 def type_description @type_description end |
#value ⇒ Object
Returns the value of attribute value.
13 14 15 |
# File 'lib/statue/metric.rb', line 13 def value @value end |
Class Method Details
.counter(name, value = 1, options = {}) ⇒ Object
16 17 18 |
# File 'lib/statue/metric.rb', line 16 def self.counter(name, value = 1, = {}) new(.merge(type: :c, value: value, name: name)) end |
.gauge(name, value, options = {}) ⇒ Object
20 21 22 |
# File 'lib/statue/metric.rb', line 20 def self.gauge(name, value, = {}) new(.merge(type: :g, value: value, name: name)) end |
.measure(name, options = {}, &block) ⇒ Object
24 25 26 27 28 |
# File 'lib/statue/metric.rb', line 24 def self.measure(name, = {}, &block) duration = .delete(:duration) value = duration || Statue::Clock.duration_in_ms(&block) new(.merge(type: :ms, value: value, name: name)) end |
Instance Method Details
#inspect ⇒ Object
45 46 47 |
# File 'lib/statue/metric.rb', line 45 def inspect "#<StatsD::Instrument::Metric #{full_name} #{type_description}(#{value})@#{sample_rate}>" end |
#to_s ⇒ Object
39 40 41 42 43 |
# File 'lib/statue/metric.rb', line 39 def to_s str = "#{full_name}:#{value}|#{type}" str << "|@#{sample_rate}" if sample_rate != 1.0 str end |