Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Fix stats example #119

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions examples/stats/quickstart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,49 @@
require "opencensus"

MIB = 1 << 20
fontend_key = "my.org/keys/frontend"
video_size_measure = OpenCensus::Stats.measure_int(
frontend_key = "my.org/keys/frontend"
video_size_measure = OpenCensus::Stats.create_measure_int(
name: "my.org/measures/video_size",
unit: "By",
description: "size of processed videos"
)
video_size_distribution = OpenCensus::Stats.distribution_aggregation(
video_size_distribution = OpenCensus::Stats.create_distribution_aggregation(
[0.0, 16.0 * MIB, 256.0 * MIB]
)

video_size_view = OpenCensus::Stats.create_view(
# You can either create, and then register the view. Or use
# create_and_register_view to register it to the global thingy.
video_size_view = OpenCensus::Stats::View.new(
name: "my.org/views/video_size",
measure: video_size_measure,
aggregation: video_size_distribution,
description: "processed video size over time",
columns: [fontend_key]
columns: [frontend_key]
)

stats_recorder = OpenCensus::Stats.recorder
stats_recorder = OpenCensus::Stats::Recorder.new
stats_recorder.register_view(video_size_view)

tag_map = OpenCensus::Tags::TagMap.new(fontend_key => "mobile-ios9.3.5")

# setup up our in-context tags, and record some measurements
tag_map_ios = OpenCensus::Tags::TagMap.new(frontend_key => "mobile-ios9.3.5")
stats_recorder.record(
video_size_measure.measurement(25 * MIB),
tags: tag_map
video_size_measure.create_measurement(value: 10 * MIB, tags: tag_map_ios),
video_size_measure.create_measurement(value: 11 * MIB, tags: tag_map_ios),
video_size_measure.create_measurement(value: 12 * MIB, tags: tag_map_ios),
video_size_measure.create_measurement(value: 13 * MIB, tags: tag_map_ios),
video_size_measure.create_measurement(value: 14 * MIB, tags: tag_map_ios)
)

view_data = stats_recorder.view_data video_size_view.name
# Another context's data
tag_map_osx = OpenCensus::Tags::TagMap.new(frontend_key => "desktop-osx10.14.4")
stats_recorder.record(
video_size_measure.create_measurement(value: 20 * MIB, tags: tag_map_osx),
video_size_measure.create_measurement(value: 21 * MIB, tags: tag_map_osx),
video_size_measure.create_measurement(value: 22 * MIB, tags: tag_map_osx),
video_size_measure.create_measurement(value: 23 * MIB, tags: tag_map_osx),
video_size_measure.create_measurement(value: 24 * MIB, tags: tag_map_osx)
)

p view_data.data
# create an exporter and export data
log_exporter = OpenCensus::Stats::Exporters::Logger.new(Logger.new(STDOUT))
log_exporter.export(stats_recorder.views_data)