Module: OpenCensus::Stats
- Defined in:
- lib/opencensus/stats.rb,
lib/opencensus/stats/view.rb,
lib/opencensus/stats/config.rb,
lib/opencensus/stats/measure.rb,
lib/opencensus/stats/exemplar.rb,
lib/opencensus/stats/recorder.rb,
lib/opencensus/stats/exporters.rb,
lib/opencensus/stats/view_data.rb,
lib/opencensus/stats/aggregation.rb,
lib/opencensus/stats/measurement.rb,
lib/opencensus/stats/aggregation/sum.rb,
lib/opencensus/stats/exporters/multi.rb,
lib/opencensus/stats/aggregation_data.rb,
lib/opencensus/stats/exporters/logger.rb,
lib/opencensus/stats/measure_registry.rb,
lib/opencensus/stats/aggregation/count.rb,
lib/opencensus/stats/aggregation_data/sum.rb,
lib/opencensus/stats/aggregation/last_value.rb,
lib/opencensus/stats/aggregation_data/count.rb,
lib/opencensus/stats/aggregation/distribution.rb,
lib/opencensus/stats/aggregation_data/last_value.rb,
lib/opencensus/stats/aggregation_data/distribution.rb
Overview
The Stats module contains support for OpenCensus stats collection.
OpenCensus allows users to create typed measures, record measurements, aggregate the collected data, and export the aggregated data.
Defined Under Namespace
Modules: Aggregation, AggregationData, Exporters Classes: Exemplar, Measure, MeasureRegistry, Measurement, Recorder, View, ViewData
Class Method Summary collapse
-
.configure ⇒ Object
Configure OpenCensus Stats.
-
.create_and_register_view(name:, measure:, aggregation:, columns: nil, description: nil) ⇒ Object
Create and register a view to current stats recorder context.
-
.create_count_aggregation ⇒ Aggregation
Create aggregation defination instance with type count.
-
.create_distribution_aggregation(buckets) ⇒ Aggregation
Create aggregation defination instance with type distribution.
-
.create_last_value_aggregation ⇒ Aggregation
Create aggregation defination instance with type last value.
-
.create_measure_double(name:, unit:, description: nil) ⇒ Measure
Create and register double type measure into measure registry.
-
.create_measure_int(name:, unit:, description: nil) ⇒ Measure
Create and register int64 type measure into measure registry.
-
.create_measurement(name:, value:, tags:) ⇒ Object
Create measurement value for registered measure.
-
.create_sum_aggregation ⇒ Aggregation
Create aggregation defination instance with type sum.
-
.ensure_recorder ⇒ Recorder
Get recorder from the stats context.
-
.recorder_context ⇒ Recorder?
Get the current thread-local stats recorder context/ Returns
nil
if there is no current SpanContext. -
.recorder_context=(context) ⇒ Object
Sets the current thread-local Recorder, which governs the behavior of the recorder creation methods of OpenCensus::Stats::Recorder.
-
.registered_measures ⇒ Array<Measure>
Get list of registered measures.
-
.unset_recorder_context ⇒ Object
Unsets the current thread-local SpanContext, disabling stats recorder creation methods of OpenCensus::Stats::Recorder.
Class Method Details
.configure ⇒ Object
Configure OpenCensus Stats. These configuration fields include parameters governing aggregation, exporting.
This configuration is also available as the stats
subconfig under the
main configuration OpenCensus.configure
. If the OpenCensus Railtie is
installed in a Rails application, the configuration object is also
exposed as config.opencensus.stats
.
Generally, you should configure this once at process initialization, but it can be modified at any time.
Supported fields are:
-
exporter
The exporter to use. Must be an exporter, an object with an export method that takes an array of ViewData objects. See Exporters. The initial value is a OpenCensus::Stats::Exporters::Logger that logs to STDOUT.
@example:
OpenCensus::Stats.configure do |config| config.exporter = OpenCensus::Stats::Exporters::Logger.new end
64 65 66 67 68 69 70 |
# File 'lib/opencensus/stats/config.rb', line 64 def configure if block_given? yield @config else @config end end |
.create_and_register_view(name:, measure:, aggregation:, columns: nil, description: nil) ⇒ Object
Create and register a view to current stats recorder context.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/opencensus/stats.rb', line 126 def create_and_register_view \ name:, measure:, aggregation:, columns: nil, description: nil view = View.new( name: name, measure: measure, aggregation: aggregation, description: description, columns: columns ) ensure_recorder.register_view view end |
.create_count_aggregation ⇒ Aggregation
Create aggregation defination instance with type count.
150 151 152 |
# File 'lib/opencensus/stats.rb', line 150 def create_count_aggregation Aggregation::Count.new end |
.create_distribution_aggregation(buckets) ⇒ Aggregation
Create aggregation defination instance with type distribution. distribution.
158 159 160 |
# File 'lib/opencensus/stats.rb', line 158 def create_distribution_aggregation buckets Aggregation::Distribution.new buckets end |
.create_last_value_aggregation ⇒ Aggregation
Create aggregation defination instance with type last value.
164 165 166 |
# File 'lib/opencensus/stats.rb', line 164 def create_last_value_aggregation Aggregation::LastValue.new end |
.create_measure_double(name:, unit:, description: nil) ⇒ Measure
Create and register double type measure into measure registry.
92 93 94 95 96 97 98 99 |
# File 'lib/opencensus/stats.rb', line 92 def create_measure_double name:, unit:, description: nil MeasureRegistry.register( name: name, unit: unit, type: Measure::DOUBLE_TYPE, description: description ) end |
.create_measure_int(name:, unit:, description: nil) ⇒ Measure
Create and register int64 type measure into measure registry.
77 78 79 80 81 82 83 84 |
# File 'lib/opencensus/stats.rb', line 77 def create_measure_int name:, unit:, description: nil MeasureRegistry.register( name: name, unit: unit, type: Measure::INT64_TYPE, description: description ) end |
.create_measurement(name:, value:, tags:) ⇒ Object
Create measurement value for registered measure.
113 114 115 116 117 |
# File 'lib/opencensus/stats.rb', line 113 def create_measurement name:, value:, tags: measure = MeasureRegistry.get name return measure.create_measurement(value: value, tags: ) if measure raise ArgumentError, "#{name} measure is not registered" end |
.create_sum_aggregation ⇒ Aggregation
Create aggregation defination instance with type sum.
144 145 146 |
# File 'lib/opencensus/stats.rb', line 144 def create_sum_aggregation Aggregation::Sum.new end |
.ensure_recorder ⇒ Recorder
Get recorder from the stats context. If stats context nil then create new recorder and set into stats context.
67 68 69 |
# File 'lib/opencensus/stats.rb', line 67 def ensure_recorder self.recorder_context ||= Recorder.new end |
.recorder_context ⇒ Recorder?
Get the current thread-local stats recorder context/
Returns nil
if there is no current SpanContext.
60 61 62 |
# File 'lib/opencensus/stats.rb', line 60 def recorder_context OpenCensus::Context.get RECORDER_CONTEXT_KEY end |
.recorder_context=(context) ⇒ Object
Sets the current thread-local Recorder, which governs the behavior of the recorder creation methods of OpenCensus::Stats::Recorder.
45 46 47 |
# File 'lib/opencensus/stats.rb', line 45 def recorder_context= context OpenCensus::Context.set RECORDER_CONTEXT_KEY, context end |
.registered_measures ⇒ Array<Measure>
Get list of registered measures
103 104 105 |
# File 'lib/opencensus/stats.rb', line 103 def registered_measures MeasureRegistry.measures end |
.unset_recorder_context ⇒ Object
Unsets the current thread-local SpanContext, disabling stats recorder creation methods of OpenCensus::Stats::Recorder
52 53 54 |
# File 'lib/opencensus/stats.rb', line 52 def unset_recorder_context OpenCensus::Context.unset RECORDER_CONTEXT_KEY end |