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) ⇒ OpenCensusCounter

Returns a new instance of OpenCensusCounter.

Raises:

  • (ArgumentError)


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

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

Instance Method Details

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



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

def increment(by: 1, 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