Java Code Examples for io.opencensus.stats.ViewManager#registerView()

The following examples show how to use io.opencensus.stats.ViewManager#registerView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() throws Exception {
  ViewManager manager = StatsBenchmarksUtil.getViewManager(implementation);
  recorder = StatsBenchmarksUtil.getStatsRecorder(implementation);
  tagger = TagsBenchmarksUtil.getTagger(implementation);
  tags = TagsBenchmarksUtil.createTagContext(tagger.emptyBuilder(), 1);
  for (int i = 0; i < numValues; i++) {
    manager.registerView(StatsBenchmarksUtil.DOUBLE_COUNT_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.LONG_COUNT_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.DOUBLE_SUM_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.LONG_SUM_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.DOUBLE_DISTRIBUTION_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.LONG_DISTRIBUTION_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.DOUBLE_LASTVALUE_VIEWS[i]);
    manager.registerView(StatsBenchmarksUtil.LONG_LASTVALUE_VIEWS[i]);
  }
}
 
Example 2
Source File: OpenCensusMetrics.java    From google-maps-services-java with Apache License 2.0 5 votes vote down vote up
public static void registerAllViews(ViewManager viewManager) {
  View[] views_to_register =
      new View[] {
        Views.REQUEST_COUNT, Views.REQUEST_LATENCY, Views.NETWORK_LATENCY, Views.RETRY_COUNT
      };
  for (View view : views_to_register) {
    viewManager.registerView(view);
  }
}
 
Example 3
Source File: Quickstart.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
  // Register the view. It is imperative that this step exists,
  // otherwise recorded metrics will be dropped and never exported.
  View view =
      View.create(
          Name.create("task_latency_distribution"),
          "The distribution of the task latencies.",
          LATENCY_MS,
          Aggregation.Distribution.create(LATENCY_BOUNDARIES),
          Collections.emptyList());

  ViewManager viewManager = Stats.getViewManager();
  viewManager.registerView(view);

  // [START setup_exporter]
  // Enable OpenCensus exporters to export metrics to Stackdriver Monitoring.
  // Exporters use Application Default Credentials to authenticate.
  // See https://developers.google.com/identity/protocols/application-default-credentials
  // for more details.
  StackdriverStatsExporter.createAndRegister();
  // [END setup_exporter]

  // Record 100 fake latency values between 0 and 5 seconds.
  Random rand = new Random();
  for (int i = 0; i < 100; i++) {
    long ms = (long) (TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS) * rand.nextDouble());
    System.out.println(String.format("Latency %d: %d", i, ms));
    STATS_RECORDER.newMeasureMap().put(LATENCY_MS, ms).record();
  }

  // The default export interval is 60 seconds. The thread with the StackdriverStatsExporter must
  // live for at least the interval past any metrics that must be collected, or some risk being
  // lost if they are recorded after the last export.

  System.out.println(
      String.format(
          "Sleeping %d seconds before shutdown to ensure all records are flushed.",
          EXPORT_INTERVAL));
  Thread.sleep(TimeUnit.MILLISECONDS.convert(EXPORT_INTERVAL, TimeUnit.SECONDS));
}
 
Example 4
Source File: PubsubMessageToObjectNode.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Register a view for every measure.
 *
 * <p>If this is not called, e.g. during unit tests, recorded values will not be exported.
 */
private static void setupOpenCensus() {
  ViewManager viewManager = Stats.getViewManager();
  for (MeasureLong measure : ImmutableList.of(COERCED_TO_INT, NOT_COERCED_TO_INT,
      NOT_COERCED_TO_BOOL)) {
    viewManager.registerView(View.create(Name.create(measure.getName()),
        measure.getDescription(), measure, COUNT_AGGREGATION, ImmutableList.of()));
  }
}
 
Example 5
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerClientGrpcViews(ViewManager viewManager) {
  for (View view : GRPC_CLIENT_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 6
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerRealTimeMetricsViews(ViewManager viewManager) {
  for (View view : GRPC_REAL_TIME_METRICS_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 7
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerAllIntervalViews(ViewManager viewManager) {
  for (View view : RPC_INTERVAL_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 8
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerAllCumulativeViews(ViewManager viewManager) {
  for (View view : RPC_CUMULATIVE_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 9
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerServerGrpcBasicViews(ViewManager viewManager) {
  for (View view : GRPC_SERVER_BASIC_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 10
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerClientGrpcBasicViews(ViewManager viewManager) {
  for (View view : GRPC_CLIENT_BASIC_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 11
Source File: RpcViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerServerGrpcViews(ViewManager viewManager) {
  for (View view : GRPC_SERVER_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 12
Source File: HttpViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerAllServerViews(ViewManager viewManager) {
  for (View view : HTTP_SERVER_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 13
Source File: HttpViews.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void registerAllClientViews(ViewManager viewManager) {
  for (View view : HTTP_CLIENT_VIEWS_SET) {
    viewManager.registerView(view);
  }
}
 
Example 14
Source File: RecordMultipleViewsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Setup
public void setup() throws Exception {
  ViewManager manager = StatsBenchmarksUtil.getViewManager(implementation);
  recorder = StatsBenchmarksUtil.getStatsRecorder(implementation);
  tagger = TagsBenchmarksUtil.getTagger(implementation);
  tagContext = createContext(numViews);

  for (int i = 0; i < numViews; i++) {
    // count
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "DC" + i,
            StatsBenchmarksUtil.DOUBLE_COUNT_MEASURES[0],
            Aggregation.Count.create(),
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "LC" + i,
            StatsBenchmarksUtil.LONG_COUNT_MEASURES[0],
            Aggregation.Count.create(),
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    // sum
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "DS" + i,
            StatsBenchmarksUtil.DOUBLE_SUM_MEASURES[0],
            Aggregation.Sum.create(),
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "LS" + i,
            StatsBenchmarksUtil.LONG_SUM_MEASURES[0],
            Aggregation.Sum.create(),
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    // distribution
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "DD" + i,
            StatsBenchmarksUtil.DOUBLE_DISTRIBUTION_MEASURES[0],
            StatsBenchmarksUtil.DISTRIBUTION,
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "LD" + i,
            StatsBenchmarksUtil.LONG_DISTRIBUTION_MEASURES[0],
            StatsBenchmarksUtil.DISTRIBUTION,
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    // last value
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "DL" + i,
            StatsBenchmarksUtil.DOUBLE_LASTVALUE_MEASURES[0],
            Aggregation.LastValue.create(),
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
    manager.registerView(
        StatsBenchmarksUtil.createView(
            "LL" + i,
            StatsBenchmarksUtil.LONG_LASTVALUE_MEASURES[0],
            Aggregation.LastValue.create(),
            TagsBenchmarksUtil.TAG_KEYS.get(i)));
  }
}
 
Example 15
Source File: StackdriverQuickstart.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
/** Main launcher for the Stackdriver example. */
public static void main(String[] args) throws IOException, InterruptedException {
  // Register the view. It is imperative that this step exists,
  // otherwise recorded metrics will be dropped and never exported.
  View view =
      View.create(
          Name.create("task_latency_distribution"),
          "The distribution of the task latencies.",
          LATENCY_MS,
          Aggregation.Distribution.create(LATENCY_BOUNDARIES),
          Collections.<TagKey>emptyList());

  // Create the view manager
  ViewManager viewManager = Stats.getViewManager();

  // Then finally register the views
  viewManager.registerView(view);

  // [START setup_exporter]
  // Enable OpenCensus exporters to export metrics to Stackdriver Monitoring.
  // Exporters use Application Default Credentials to authenticate.
  // See https://developers.google.com/identity/protocols/application-default-credentials
  // for more details.
  StackdriverStatsExporter.createAndRegister();
  // [END setup_exporter]

  // Record 100 fake latency values between 0 and 5 seconds.
  Random rand = new Random();
  for (int i = 0; i < 100; i++) {
    long ms = (long) (TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS) * rand.nextDouble());
    System.out.println(String.format("Latency %d: %d", i, ms));
    STATS_RECORDER.newMeasureMap().put(LATENCY_MS, ms).record();
  }

  // The default export interval is 60 seconds. The thread with the StackdriverStatsExporter must
  // live for at least the interval past any metrics that must be collected, or some risk being
  // lost if they are recorded after the last export.

  System.out.println(
      String.format(
          "Sleeping %d seconds before shutdown to ensure all records are flushed.",
          EXPORT_INTERVAL));
  Thread.sleep(TimeUnit.MILLISECONDS.convert(EXPORT_INTERVAL, TimeUnit.SECONDS));
}
 
Example 16
Source File: Repl.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
private static void registerAllViews() {
  // Defining the distribution aggregations
  Aggregation latencyDistribution =
      Distribution.create(
          BucketBoundaries.create(
              Arrays.asList(
                  // [>=0ms, >=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms,
                  // >=1s, >=2s, >=4s, >=6s]
                  0.0,
                  25.0,
                  50.0,
                  75.0,
                  100.0,
                  200.0,
                  400.0,
                  600.0,
                  800.0,
                  1000.0,
                  2000.0,
                  4000.0,
                  6000.0)));

  Aggregation lengthsDistribution =
      Distribution.create(
          BucketBoundaries.create(
              Arrays.asList(
                  // [>=0B, >=5B, >=10B, >=20B, >=40B, >=60B, >=80B, >=100B, >=200B, >=400B,
                  // >=600B,
                  // >=800B, >=1000B]
                  0.0,
                  5.0,
                  10.0,
                  20.0,
                  40.0,
                  60.0,
                  80.0,
                  100.0,
                  200.0,
                  400.0,
                  600.0,
                  800.0,
                  1000.0)));

  // Define the count aggregation
  Aggregation countAggregation = Aggregation.Count.create();

  // So tagKeys
  List<TagKey> noKeys = new ArrayList<TagKey>();

  // Define the views
  View[] views =
      new View[] {
        View.create(
            Name.create("ocjavametrics/latency"),
            "The distribution of latencies",
            M_LATENCY_MS,
            latencyDistribution,
            Collections.singletonList(KEY_METHOD)),
        View.create(
            Name.create("ocjavametrics/lines_in"),
            "The number of lines read in from standard input",
            M_LINES_IN,
            countAggregation,
            noKeys),
        View.create(
            Name.create("ocjavametrics/errors"),
            "The number of errors encountered",
            M_ERRORS,
            countAggregation,
            Collections.singletonList(KEY_METHOD)),
        View.create(
            Name.create("ocjavametrics/line_lengths"),
            "The distribution of line lengths",
            M_LINE_LENGTHS,
            lengthsDistribution,
            noKeys)
      };

  // Create the view manager
  ViewManager vmgr = Stats.getViewManager();

  // Then finally register the views
  for (View view : views) {
    vmgr.registerView(view);
  }
}
 
Example 17
Source File: TelemetryUtils.java    From meghanada-server with GNU General Public License v3.0 4 votes vote down vote up
private static void registerAllViews() {
  Aggregation commandLatencyDistribution =
      Aggregation.Distribution.create(
          BucketBoundaries.create(
              Arrays.asList(
                  0.0, // >=0ms
                  25.0, // >=25ms
                  50.0, // >=50ms
                  100.0, // >=100ms
                  200.0, // >=200ms
                  400.0, // >=400ms
                  800.0, // >=800ms
                  1000.0, // >=1s
                  2000.0, // >=2s
                  5000.0, // >=5s
                  8000.0, // >=8s
                  10000.0 // >=10s
                  )));
  View[] views;
  views =
      new View[] {
        View.create(
            View.Name.create("meghanada/command_latency"),
            "The distribution of the command latencies",
            M_COMMAND_LATENCY_MS,
            commandLatencyDistribution,
            Collections.unmodifiableList(Arrays.asList(KEY_UID, KEY_COMMAND))),
        View.create(
            View.Name.create("meghanada/class_index_size"),
            "The number of class indexes",
            M_CLASS_INDEX,
            Aggregation.LastValue.create(),
            Collections.unmodifiableList(Collections.singletonList(KEY_UID))),
        View.create(
            View.Name.create("meghanada/autocomplete"),
            "The number of autocomplete count",
            M_AUTOCOMPLETE_COUNT,
            Aggregation.Sum.create(),
            Collections.unmodifiableList(Arrays.asList(KEY_UID, KEY_DESCRIPTION))),
        View.create(
            View.Name.create("meghanada/member_cache_hit_rate"),
            "The member cache hit rate",
            M_MEMBER_CACHE_HIT_RATE,
            Aggregation.LastValue.create(),
            Collections.unmodifiableList(Collections.singletonList(KEY_UID))),
        View.create(
            View.Name.create("meghanada/member_cache_load_exception_rate"),
            "The member cache load exception rate",
            M_MEMBER_CACHE_LOAD_ERROR_RATE,
            Aggregation.LastValue.create(),
            Collections.unmodifiableList(Collections.singletonList(KEY_UID))),
        View.create(
            View.Name.create("meghanada/member_cache_miss_rate"),
            "The member cache miss rate",
            M_MEMBER_CACHE_MISS_RATE,
            Aggregation.LastValue.create(),
            Collections.unmodifiableList(Collections.singletonList(KEY_UID))),
        View.create(
            View.Name.create("meghanada/vm_memory"),
            "The vm memory",
            M_MEMORY,
            Aggregation.LastValue.create(),
            Collections.unmodifiableList(Collections.singletonList(KEY_UID))),
      };

  ViewManager vmgr = Stats.getViewManager();
  for (View view : views) {
    vmgr.registerView(view);
  }
}