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.
13 14 15 16 17 18 19 |
# File 'lib/metrics/backend/capture.rb', line 13 def initialize(...) super @values = [] @tags = Set.new @sample_rates = [] end |
Instance Attribute Details
#sample_rates ⇒ Object (readonly)
Returns the value of attribute sample_rates.
23 24 25 |
# File 'lib/metrics/backend/capture.rb', line 23 def sample_rates @sample_rates end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
22 23 24 |
# File 'lib/metrics/backend/capture.rb', line 22 def @tags end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
21 22 23 |
# File 'lib/metrics/backend/capture.rb', line 21 def values @values end |
Instance Method Details
#as_json ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/metrics/backend/capture.rb', line 31 def as_json { name: @name, type: @type, description: @description, unit: @unit, values: @values, tags: @tags.to_a.sort, sample_rates: @sample_rates.sort.uniq } end |
#emit(value, tags: nil, sample_rate: 1.0) ⇒ Object
25 26 27 28 29 |
# File 'lib/metrics/backend/capture.rb', line 25 def emit(value, tags: nil, sample_rate: 1.0) @values << value @tags.merge() if @sample_rates << sample_rate end |
#to_json ⇒ Object
43 44 45 |
# File 'lib/metrics/backend/capture.rb', line 43 def to_json(...) as_json.to_json(...) end |