Class: Yodeler::Metric
- Inherits:
-
Object
- Object
- Yodeler::Metric
- Defined in:
- lib/yodeler/metric.rb
Constant Summary collapse
- TYPES =
[:event, :increment, :gauge, :timing]
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(type, name, value, opts = {}) ⇒ Metric
constructor
A new instance of Metric.
- #name ⇒ Object
-
#sample? ⇒ Boolean
Should this metric be sampled.
- #to_hash ⇒ Object
Constructor Details
#initialize(type, name, value, opts = {}) ⇒ Metric
Returns a new instance of Metric.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/yodeler/metric.rb', line 12 def initialize(type, name, value, opts = {}) @uuid = SecureRandom.uuid @type = type @name = name @value = value @prefix = opts.delete(:prefix) @sample_rate = opts.delete(:sample_rate) @timestamp = opts.delete(:timestamp) @tags = opts.delete(:tags) @hostname = opts.delete(:hostname) @meta = opts.delete(:meta) || {} #additional meta data to send end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/yodeler/metric.rb', line 8 def @options end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/yodeler/metric.rb', line 6 def prefix @prefix end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
6 7 8 |
# File 'lib/yodeler/metric.rb', line 6 def sample_rate @sample_rate end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/yodeler/metric.rb', line 6 def @tags end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/yodeler/metric.rb', line 5 def type @type end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/yodeler/metric.rb', line 7 def uuid @uuid end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/yodeler/metric.rb', line 5 def value @value end |
Instance Method Details
#name ⇒ Object
25 26 27 |
# File 'lib/yodeler/metric.rb', line 25 def name @prefix ? [@prefix, @name].join('.') : @name end |
#sample? ⇒ Boolean
Returns Should this metric be sampled.
30 31 32 |
# File 'lib/yodeler/metric.rb', line 30 def sample? @_sample ||= !(rand > @sample_rate) end |
#to_hash ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yodeler/metric.rb', line 34 def to_hash hash = { uuid: uuid, name: name, type: @type, value: @value, meta: @meta } hash[:meta][:timestamp] = @timestamp if @timestamp hash[:meta][:tags] = @tags if @tags && @tags.any? hash[:meta][:hostname] = @hostname if @hostname hash end |