Class: Monitoring::OpenCensusCounter

Inherits:
BaseCounter show all
Defined in:
lib/fluent/plugin/monitoring.rb

Overview

OpenCensus implementation of counters.

Instance Method Summary collapse

Constructor Details

#initialize(recorder, measure, translator) ⇒ OpenCensusCounter

Returns a new instance of OpenCensusCounter.

Raises:

  • (ArgumentError)


35
36
37
38
39
40
# File 'lib/fluent/plugin/monitoring.rb', line 35

def initialize(recorder, measure, translator)
  raise ArgumentError, 'measure must not be nil' if measure.nil?
  @recorder = recorder
  @measure = measure
  @translator = translator
end

Instance Method Details

#increment(by: 1, labels: {}) ⇒ Object



42
43
44
45
46
47
# File 'lib/fluent/plugin/monitoring.rb', line 42

def increment(by: 1, labels: {})
  labels = @translator.translate_labels(labels)
  tag_map = OpenCensus::Tags::TagMap.new(
    labels.map { |k, v| [k.to_s, v.to_s] }.to_h)
  @recorder.record(@measure.create_measurement(value: by, tags: tag_map))
end