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
- .name ⇒ Object
-
.translate_metric_name(name) ⇒ Object
Translate the internal metrics to the curated metrics in Stackdriver.
Instance Method Summary collapse
- #counter(name, labels, docstring) ⇒ Object
- #export ⇒ Object
-
#initialize(project_id, monitored_resource) ⇒ OpenCensusMonitoringRegistry
constructor
A new instance of OpenCensusMonitoringRegistry.
Constructor Details
#initialize(project_id, monitored_resource) ⇒ OpenCensusMonitoringRegistry
Returns a new instance of OpenCensusMonitoringRegistry.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fluent/plugin/monitoring.rb', line 90 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
86 87 88 |
# File 'lib/fluent/plugin/monitoring.rb', line 86 def self.name 'opencensus' end |
.translate_metric_name(name) ⇒ Object
Translate the internal metrics to the curated metrics in Stackdriver. The Prometheus metrics are collected by Google Kubernetes Engine's monitoring, so we can't redefine them.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fluent/plugin/monitoring.rb', line 135 def translate_metric_name(name) case name when :stackdriver_successful_requests_count, :stackdriver_failed_requests_count :request_count when :stackdriver_ingested_entries_count, :stackdriver_dropped_entries_count :log_entry_count when :stackdriver_retried_entries_count :log_entry_retry_count else name end end |
Instance Method Details
#counter(name, labels, docstring) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/fluent/plugin/monitoring.rb', line 107 def counter(name, labels, docstring) name = OpenCensusMonitoringRegistry.translate_metric_name(name) measure = OpenCensus::Stats::MeasureRegistry.get(name) if measure.nil? measure = OpenCensus::Stats.create_measure_int( name: name, unit: OpenCensus::Stats::Measure::UNIT_NONE, description: docstring ) end OpenCensus::Stats.create_and_register_view( name: name, measure: measure, aggregation: OpenCensus::Stats.create_sum_aggregation, description: docstring, columns: labels.map(&:to_s) ) OpenCensusCounter.new(@recorder, measure) end |
#export ⇒ Object
127 128 129 |
# File 'lib/fluent/plugin/monitoring.rb', line 127 def export @exporter.export @recorder.views_data end |