OpenCensus is being archived! Read the blog post to learn more

View

View

Views are the coupling of an Aggregation applied to a Measure and optionally Tags. Views are the connection to Metric exporters.

Aggregations

The following aggregation methods are supported:

Parts of a view

Field Description Example Restrictions
Name Identifies the metric being collected grpc.io/client/completed_rpcs Make it a fully qualified and distinguishable name
Description The description of the metric being collected The latency in milliseconds, The number of bytes received Make it descriptive of the metric being collected
Measure The Measure that produces measurements for this collection Measure
TagKeys The various tagkeys used to group and filter collected metrics later on TagKeys These are optional
Aggregation The aggregation against which measurements will be made Aggregation This is mandatory

Users can dynamically create and delete views at runtime. Libraries may export their own views and claim the view names by registering them.

Multiple views can use the same measure but only if they have different aggregations for the same measure

Source code example

package main

import (
	"go.opencensus.io/stats/view"
	"go.opencensus.io/tag"
)

func enableViews() error {
	latencyView = &view.View{
		Name:        "myapp/latency",
		Measure:     mLatencyMs,
		Description: "The distribution of the latencies",
		TagKeys:     []tag.Key{keyMethod},
		Aggregation: view.Distribution(0, 25, 100, 200, 400, 800, 10000),
	}

	lineCountView = &view.View{
		Name:        "myapp/lines_in",
		Measure:     mLatencyMs,
		Description: "The number of lines that were received",
		TagKeys:     []tag.Key{keyMethod},
		// Notice that the measure "mLatencyMs" is the same as
		// latencyView's but here the aggregation is a count aggregation
		// while the latencyView has a distribution aggregation.
		Aggregation: view.Count(),
	}

	// Ensure that they are registered so
        // that measurements won't be dropped.
	return view.Register(latencyView, lineCountView)
}
package io.opencensus.metrics.snippet;

import io.opencensus.stats.Stats;
import io.opencensus.stats.Aggregation;
import io.opencensus.stats.Aggregation.Count;
import io.opencensus.stats.Aggregation.Distribution;
import io.opencensus.stats.BucketBoundaries;
import io.opencensus.stats.View;
import io.opencensus.stats.View.Name;
import io.opencensus.stats.ViewManager;

import java.util.Arrays;
import java.util.Collections;

public class JavaSnippet {
    private void enableViews() {
        Aggregation latencyDistribution = Distribution.create(BucketBoundaries.create(
                Arrays.asList(
                    0.0, 25.0, 100.0, 200.0, 400.0, 800.0, 10000.0)));

        View[] views = new View[]{
            View.create(Name.create("myapp/latency"),
                        "The distribution of the latencies",
                        M_LATENCY_MS,
                        latencyDistribution,
                        Collections.singletonList(KEY_METHOD)),

            View.create(Name.create("myapp/lines_in"),
                        "The number of lines that were received",
                        M_LATENCY_MS,
                        Count.create(),
                        Collections.singletonList(KEY_METHOD)),
	};

	// Ensure that they are registered so
        // that measurements won't be dropped.
        ViewManager manager = Stats.getViewManager();
        for (View view : views)
            manager.registerView(view);
    }
}
#/usr/bin/env python

from opencensus.stats import aggregation
from opencensus.stats import view
from opencensus.stats import stats
from opencensus.stats import measure

def enable_views():
    latency_view = view.View("myapp/latency",
                             "The distribution of the latencies",
                             [key_method],
                             m_latency_ms,
                             aggregation.DistributionAggregation(0, 25, 100, 200, 400, 800, 10000))

    line_count_view = view.View("myapp/lines_in",
                             "The number of lines that were received",
                             [key_method],
                             m_latency_ms,
                             aggregation.CountAggregation())

    # Ensure that they are registered so
    # that measurements won't be dropped.
    view_manager = stats.Stats().view_manager
    view_manager.register_view(latency_view)
    view_manager.register_view(line_count_view)
#include "opencensus/stats/stats.h"

void RegisterViews() {
  // 1. Latency view
  // We need to register the measure before registering the view.
  LatencyMsMeasure();
  opencensus::stats::ViewDescriptor()
      .set_name("ocquickstart.io/latency")
      .set_description("The various methods' latencies in milliseconds")
      .set_measure(kLatencyMeasureName)
      .set_aggregation(opencensus::stats::Aggregation::Distribution(
          opencensus::stats::BucketBoundaries::Explicit(
              {0, 25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000,
               6000})))
      .add_column(MethodKey())
      .RegisterForExport();

  // 2. Line lengths
  LineLengthsMeasure();
  opencensus::stats::ViewDescriptor()
      .set_name("ocquickstart.io/line_lengths")
      .set_description("The length of the lines read in")
      .set_measure(kLineLengthsMeasureName)
      .set_aggregation(opencensus::stats::Aggregation::Distribution(
          opencensus::stats::BucketBoundaries::Explicit(
              {0, 5, 10, 15, 20, 40, 60, 80, 100, 200, 400, 600, 800,
               1000})))
      .add_column(MethodKey())
      .RegisterForExport();

  // 3. Lines count: just a count aggregation on the line lengths measure
  opencensus::stats::ViewDescriptor()
      .set_name("ocquickstart.io/lines_in")
      .set_description("The number of lines read in")
      .set_measure(kLineLengthsMeasureName)
      .set_aggregation(opencensus::stats::Aggregation::Count())
      .add_column(MethodKey())
      .RegisterForExport();
}

int main(int argc, char **argv) {
  // ...
  RegisterViews();
  // ...
}
const { globalStats, AggregationType, TagMap } = require('@opencensus/core');

const tagKey = { name: "method" };

const latencyView = globalStats.createView(
  "myapp/latency",
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  [tagKey],
  "The distribution of the latencies",
  // Bucket Boundaries:
  // [>=0ms, >=25ms, >=100ms, >=200ms, >=400ms, >=800ms, >=1000ms]
  [0, 25, 100, 200, 400, 800, 1000]
);

const lineCountView = globalStats.createView(
  "demo/lines_in",
  mLatencyMs,
  AggregationType.COUNT,
  [tagKey],
  "The number of lines from standard input"
);

globalStats.registerView(latencyView);
globalStats.registerView(lineCountView);

References

Resource URL
ViewData in specs specs/stats/Export-API
Aggregation in specs specs/stats/Export-API.DatagAggregation
Go views Views package
Java views Views package
Python views Views API
C++ views stats/view.h
Node.js views stats.View