Class: Metrics::Backend::Capture::Metric
- Defined in:
- lib/metrics/backend/capture.rb
Instance Attribute Summary collapse
-
#sample_rates ⇒ Object
readonly
Returns the value of attribute sample_rates.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Attributes inherited from Metric
#description, #name, #type, #unit
Instance Method Summary collapse
- #as_json ⇒ Object
- #emit(value, tags: nil, sample_rate: 1.0) ⇒ Object
-
#initialize ⇒ Metric
constructor
A new instance of Metric.
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Metric
Returns a new instance of Metric.
12 13 14 15 16 17 18 |
# File 'lib/metrics/backend/capture.rb', line 12 def initialize(...) super @values = [] = Set.new @sample_rates = [] end |
Instance Attribute Details
#sample_rates ⇒ Object (readonly)
Returns the value of attribute sample_rates.
22 23 24 |
# File 'lib/metrics/backend/capture.rb', line 22 def sample_rates @sample_rates end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
21 22 23 |
# File 'lib/metrics/backend/capture.rb', line 21 def end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
20 21 22 |
# File 'lib/metrics/backend/capture.rb', line 20 def values @values end |
Instance Method Details
#as_json ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/metrics/backend/capture.rb', line 30 def as_json { name: @name, type: @type, description: @description, unit: @unit, values: @values, tags: .to_a.sort, sample_rates: @sample_rates.sort.uniq } end |
#emit(value, tags: nil, sample_rate: 1.0) ⇒ Object
24 25 26 27 28 |
# File 'lib/metrics/backend/capture.rb', line 24 def emit(value, tags: nil, sample_rate: 1.0) @values << value .merge() if @sample_rates << sample_rate end |
#to_json ⇒ Object
42 43 44 |
# File 'lib/metrics/backend/capture.rb', line 42 def to_json(...) as_json.to_json(...) end |