Class: Monitoring::OpenCensusMonitoringRegistry

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

Overview

OpenCensus implementation of the monitoring registry.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_id, monitored_resource) ⇒ OpenCensusMonitoringRegistry

Returns a new instance of OpenCensusMonitoringRegistry.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fluent/plugin/monitoring.rb', line 96

def initialize(project_id, monitored_resource)
  super
  require 'opencensus'
  require 'opencensus-stackdriver'
  @log = $log # rubocop:disable Style/GlobalVars
  @recorder = OpenCensus::Stats.ensure_recorder
  @exporter = OpenCensus::Stats::Exporters::Stackdriver.new(
    project_id: project_id,
    metric_prefix: 'agent.googleapis.com/agent',
    resource_type: monitored_resource.type,
    resource_labels: monitored_resource.labels)
  OpenCensus.configure do |c|
    c.stats.exporter = @exporter
  end
  @log.debug "OpenCensus config=#{OpenCensus.config}"
end

Class Method Details

.name ⇒ Object



92
93
94
# File 'lib/fluent/plugin/monitoring.rb', line 92

def self.name
  'opencensus'
end

Instance Method Details

#counter(name, labels, docstring) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/fluent/plugin/monitoring.rb', line 113

def counter(name, labels, docstring)
  translator = MetricTranslator.new(name, labels)
  measure = OpenCensus::Stats::MeasureRegistry.get(translator.name)
  if measure.nil?
    measure = OpenCensus::Stats.create_measure_int(
      name: translator.name,
      unit: OpenCensus::Stats::Measure::UNIT_NONE,
      description: docstring
    )
  end
  OpenCensus::Stats.create_and_register_view(
    name: translator.name,
    measure: measure,
    aggregation: OpenCensus::Stats.create_sum_aggregation,
    description: docstring,
    columns: translator.view_labels.map(&:to_s)
  )
  OpenCensusCounter.new(@recorder, measure, translator)
end

#export ⇒ Object



133
134
135
# File 'lib/fluent/plugin/monitoring.rb', line 133

def export
  @exporter.export @recorder.views_data
end