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.



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_ratesObject (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

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

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



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

#to_jsonObject



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

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