Class: Monitoring::OpenCensusMonitoringRegistry
- Inherits:
-
BaseMonitoringRegistry
- Object
- BaseMonitoringRegistry
- Monitoring::OpenCensusMonitoringRegistry
- Defined in:
- lib/fluent/plugin/monitoring.rb
Overview
OpenCensus implementation of the monitoring registry.
Class Method Summary collapse
Instance Method Summary collapse
- #counter(name, labels, docstring) ⇒ Object
- #export ⇒ Object
-
#initialize(project_id, monitored_resource, gcm_service_address) ⇒ OpenCensusMonitoringRegistry
constructor
A new instance of OpenCensusMonitoringRegistry.
Constructor Details
#initialize(project_id, monitored_resource, gcm_service_address) ⇒ OpenCensusMonitoringRegistry
Returns a new instance of OpenCensusMonitoringRegistry.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fluent/plugin/monitoring.rb', line 95 def initialize(project_id, monitored_resource, gcm_service_address) 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, gcm_service_address: gcm_service_address ) OpenCensus.configure do |c| c.stats.exporter = @exporter end @log.debug "OpenCensus config=#{OpenCensus.config}" end |
Class Method Details
.name ⇒ Object
91 92 93 |
# File 'lib/fluent/plugin/monitoring.rb', line 91 def self.name 'opencensus' end |
Instance Method Details
#counter(name, labels, docstring) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fluent/plugin/monitoring.rb', line 114 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
134 135 136 |
# File 'lib/fluent/plugin/monitoring.rb', line 134 def export @exporter.export @recorder.views_data end |