Class: Metrics::Backend::Capture::Metric

Inherits:
Metric
  • Object
show all
Defined in:
lib/metrics/backend/capture.rb

Instance Attribute Summary collapse

Attributes inherited from Metric

#description, #name, #type, #unit

Instance Method Summary collapse

Constructor Details

#initializeMetric

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 = []
  @tags = Set.new
  @sample_rates = []
end

Instance Attribute Details

#sample_ratesObject (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

#tagsObject (readonly)

Returns the value of attribute tags.



21
22
23
# File 'lib/metrics/backend/capture.rb', line 21

def tags
  @tags
end

#valuesObject (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_jsonObject



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: @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
  @tags.merge(tags) if tags
  @sample_rates << sample_rate
end

#to_jsonObject



42
43
44
# File 'lib/metrics/backend/capture.rb', line 42

def to_json(...)
  as_json.to_json(...)
end