Class: OpenCensus::Stats::Recorder
- Inherits:
-
Object
- Object
- OpenCensus::Stats::Recorder
- Defined in:
- lib/opencensus/stats/recorder.rb
Overview
Stats recorder.
Recorder record measurement against measure for registered views.
Instance Method Summary collapse
-
#clear_stats ⇒ Object
Clear recorded stats.
-
#record(*measurements, attachments: nil) ⇒ Object
Record measurements.
-
#register_view(view) ⇒ View
Register view.
-
#view_data(view_name) ⇒ ViewData
Get recorded data for given view name.
-
#views_data ⇒ Array<ViewData>
Get all views data list.
Instance Method Details
#clear_stats ⇒ Object
Clear recorded stats.
93 94 95 96 97 |
# File 'lib/opencensus/stats/recorder.rb', line 93 def clear_stats @measure_views_data.each_value do |views_data| views_data.each(&:clear) end end |
#record(*measurements, attachments: nil) ⇒ Object
Record measurements
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/opencensus/stats/recorder.rb', line 61 def record *measurements, attachments: nil return if measurements.any? { |m| m.value < 0 } measurements.each do |measurement| views_data = @measure_views_data[measurement.measure.name] next unless views_data views_data.each do |view_data| view_data.record measurement, attachments: end end end |
#register_view(view) ⇒ View
Register view
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opencensus/stats/recorder.rb', line 39 def register_view view return if @views.key? view.name @views[view.name] = view @measures[view.measure.name] = view.measure unless @measure_views_data.key? view.measure.name @measure_views_data[view.measure.name] = [] end @measure_views_data[view.measure.name] << ViewData.new( view, start_time: @time, end_time: @time ) view end |
#view_data(view_name) ⇒ ViewData
Get recorded data for given view name
78 79 80 81 82 83 84 |
# File 'lib/opencensus/stats/recorder.rb', line 78 def view_data view_name view = @views[view_name] return unless view views_data = @measure_views_data[view.measure.name] views_data.find { |view_data| view_data.view.name == view.name } end |
#views_data ⇒ Array<ViewData>
Get all views data list
88 89 90 |
# File 'lib/opencensus/stats/recorder.rb', line 88 def views_data @measure_views_data.values.flatten end |