class Monitoring::OpenCensusCounter

OpenCensus implementation of counters.

Public Class Methods

new(recorder, measure, translator) click to toggle source
Calls superclass method
# File lib/fluent/plugin/monitoring.rb, line 37
def initialize(recorder, measure, translator)
  super()
  raise ArgumentError, 'measure must not be nil' if measure.nil?

  @recorder = recorder
  @measure = measure
  @translator = translator
end

Public Instance Methods

increment(by: 1, labels: {}) click to toggle source
# File lib/fluent/plugin/monitoring.rb, line 46
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