How to use the @opencensus/core.AggregationType.COUNT function in @opencensus/core

To help you get started, we’ve selected a few @opencensus/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github census-instrumentation / opencensus-node / examples / stats / web_client_monitoring / app.js View on Github external
const tagPhase = { name: "phase" };
const tagClient = { name: "client" };

const latencyView = globalStats.createView(
  "webmetrics/latency",
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  [tagPhase, tagClient],
  "Distribution of latencies",
  buckets
);
globalStats.registerView(latencyView);
const clickCountView = globalStats.createView(
  "webmetrics/click_count",
  mClickCount,
  AggregationType.COUNT,
  [tagClient],
  "The number of button clicks"
);
globalStats.registerView(clickCountView);
// [END web_client_monitoring_ocsetup]

// Process the metrics data posted to the server
app.post("/metrics", (req, res) => {
  const dnsTime = req.body["dnsTime"];
  const connectTime = req.body["connectTime"];
  const totalTime = req.body["totalTime"];
  const clickCount = req.body["count"];
  console.log(`totalTime ${totalTime}`);
  console.log(`connectTime ${connectTime}`);
  console.log(`dnsTime ${dnsTime}`);
  console.log(`count ${clickCount}`);
github census-instrumentation / opencensus-node / packages / opencensus-exporter-prometheus / src / prometheus-stats.ts View on Github external
private registerMetric(view: View, tags: Map): Metric {
    const metricName = this.getPrometheusMetricName(view);
    /** Get metric if already registered */
    let metric = this.registry.getSingleMetric(metricName);
    // Return metric if already registered
    if (metric) {
      return metric;
    }

    const labelNames = view.getColumns().map(tagKey => tagKey.name);
    // Create a new metric if there is no one
    const metricObj = { name: metricName, help: view.description, labelNames };

    // Creating the metric based on aggregation type
    switch (view.aggregation) {
      case AggregationType.COUNT:
        metric = new Counter(metricObj);
        break;
      case AggregationType.SUM:
      case AggregationType.LAST_VALUE:
        metric = new Gauge(metricObj);
        break;
      case AggregationType.DISTRIBUTION:
        this.validateDisallowedLeLabelForHistogram(labelNames);
        const distribution = {
          name: metricName,
          help: view.description,
          labelNames,
          buckets: this.getBoundaries(view, tags),
        };
        metric = new Histogram(distribution);
        break;
github census-instrumentation / opencensus-node / packages / opencensus-exporter-zpages / src / zpages-frontend / page-handlers / rpcz.page-handler.ts View on Github external
if (
              view.name === DefaultViews.CLIENT_RECEIVED_BYTES_PER_RPC ||
              view.name === DefaultViews.SERVER_RECEIVED_BYTES_PER_RPC
            ) {
              zMeasures[method].input.tot += snapshot.sum / 1024;
              zMeasures[method].input.min =
                this.getRate(
                  zMeasures[method].input.tot,
                  new Date(view.startTime)
                ) * 60;
              zMeasures[method].input.hr = zMeasures[method].input.min * 60;
            }
          }

          if (
            snapshot.type === AggregationType.COUNT &&
            (view.name === DefaultViews.CLIENT_COMPLETED_RPCS ||
              view.name === DefaultViews.SERVER_COMPLETED_RPCS)
          ) {
            // Fills the count columns for that method
            zMeasures[method].count.tot += snapshot.value;
            zMeasures[method].count.min =
              this.getRate(
                zMeasures[method].count.tot,
                new Date(view.startTime)
              ) * 60;
            zMeasures[method].count.hr = zMeasures[method].count.min * 60;

            // Fills the rate columns for that method
            zMeasures[method].rate.tot = this.getRate(
              zMeasures[method].count.tot,
              new Date(view.startTime)
github census-instrumentation / opencensus-node / examples / stats / exporter / stackdriver.js View on Github external
'demo/latency',
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  tagKeys,
  'The distribution of the repl latencies',
  // Latency in buckets:
  // [>=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, >=1s, >=2s, >=4s, >=6s]
  [25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000, 6000]
);
globalStats.registerView(latencyView);

// Create & Register the view.
const lineCountView = globalStats.createView(
  'demo/lines_in',
  mLineLengths,
  AggregationType.COUNT,
  tagKeys,
  'The number of lines from standard input'
);
globalStats.registerView(lineCountView);

// Create & Register the view.
const lineLengthView = globalStats.createView(
  'demo/line_lengths',
  mLineLengths,
  AggregationType.DISTRIBUTION,
  tagKeys,
  'Groups the lengths of keys in buckets',
  // Bucket Boudaries:
  // [>=5B, >=10B, >=15B, >=20B, >=40B, >=60B, >=80, >=100B, >=200B, >=400, >=600, >=800, >=1000]
  [5, 10, 15, 20, 40, 60, 80, 100, 200, 400, 600, 800, 1000]
);
github census-instrumentation / opencensus-node / examples / stats / exporter / prometheus.js View on Github external
'demo/latency',
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  tagKeys,
  'The distribution of the repl latencies',
  // Latency in buckets:
  // [>=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, >=1s, >=2s, >=4s, >=6s]
  [25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000, 6000]
);
globalStats.registerView(latencyView);

// Create & Register the view.
const lineCountView = globalStats.createView(
  'demo/lines_in',
  mLineLengths,
  AggregationType.COUNT,
  tagKeys,
  'The number of lines from standard input'
);
globalStats.registerView(lineCountView);

// Create & Register the view.
const lineLengthView = globalStats.createView(
  'demo/line_lengths',
  mLineLengths,
  AggregationType.DISTRIBUTION,
  tagKeys,
  'Groups the lengths of keys in buckets',
  // Bucket Boudaries:
  // [>=5B, >=10B, >=15B, >=20B, >=40B, >=60B, >=80, >=100B, >=200B, >=400, >=600, >=800, >=1000]
  [5, 10, 15, 20, 40, 60, 80, 100, 200, 400, 600, 800, 1000]
);
github census-instrumentation / opencensus-node / packages / opencensus-exporter-zpages / src / zpages-frontend / page-handlers / statsz.page-handler.ts View on Github external
path: currentViewPath,
          viewsCount: 1,
          isLastFolder,
        };
      }
    }

    if (selectedView) {
      const statsData = this.getStatsData(selectedView);
      const viewFile = this.loaderFile('statsz-view.ejs');
      let viewContentFile: string | undefined;
      let statsContent: string;

      switch (selectedView.aggregation) {
        // Loads the count aggregation type
        case AggregationType.COUNT:
          viewContentFile = this.loaderFile('statsz-view-count.ejs');
          break;

        // Loads the sum aggregation type
        case AggregationType.SUM:
          viewContentFile = this.loaderFile('statsz-view-sum.ejs').toString();
          break;

        // Loads the last value aggregation type
        case AggregationType.LAST_VALUE:
          viewContentFile = this.loaderFile('statsz-view-lastvalue.ejs');
          break;

        // Loads the distribution aggregation type
        case AggregationType.DISTRIBUTION:
          viewContentFile = this.loaderFile('statsz-view-distribution.ejs');
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc-stats / client-stats.ts View on Github external
'Distribution of round-trip latency, by method.',
  DEFAULT_MILLI_SECONDS_DISTRIBUTION
);

/**
 * {@link View} for completed client RPCs.
 *
 * This {@code View} uses measure {@code GRPC_CLIENT_ROUNDTRIP_LATENCY},
 * since completed RPCs can be inferred over any measure recorded once per RPC
 * (since it's just a count aggregation over the measure). It would be
 * unnecessary to use a separate "count" measure.
 */
const GRPC_CLIENT_COMPLETED_RPC_VIEW = globalStats.createView(
  'grpc.io/client/completed_rpcs',
  GRPC_CLIENT_ROUNDTRIP_LATENCY,
  AggregationType.COUNT,
  [GRPC_CLIENT_METHOD, GRPC_CLIENT_STATUS],
  'Count of RPCs by method and status.',
  DEFAULT_MESSAGE_COUNT_DISTRIBUTION
);

export const GRPC_BASIC_CLIENT_VIEWS: View[] = [
  GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC_VIEW,
  GRPC_CLIENT_RECEIVED_BYTES_PER_RPC_VIEW,
  GRPC_CLIENT_SENT_MESSAGES_PER_RPC_VIEW,
  GRPC_CLIENT_SENT_BYTES_PER_RPC_VIEW,
  GRPC_CLIENT_ROUNDTRIP_LATENCY_VIEW,
  GRPC_CLIENT_COMPLETED_RPC_VIEW,
];
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-http / src / http-stats.ts View on Github external
650,
  800,
  1000,
  2000,
  5000,
  10000,
  20000,
  50000,
  100000,
];

/** {@link View} for count of client-side HTTP requests completed. */
const HTTP_CLIENT_COMPLETED_COUNT_VIEW = globalStats.createView(
  'opencensus.io/http/client/completed_count',
  HTTP_CLIENT_ROUNDTRIP_LATENCY,
  AggregationType.COUNT,
  [HTTP_CLIENT_METHOD, HTTP_CLIENT_STATUS],
  'Count of client-side HTTP requests completed'
);

/** {@link View} for size distribution of client-side HTTP request body. */
const HTTP_CLIENT_SENT_BYTES_VIEW = globalStats.createView(
  'opencensus.io/http/client/sent_bytes',
  HTTP_CLIENT_SENT_BYTES,
  AggregationType.DISTRIBUTION,
  [HTTP_CLIENT_METHOD, HTTP_CLIENT_STATUS],
  'Size distribution of client-side HTTP request body',
  SIZE_DISTRIBUTION
);

/** {@link View} for size distribution of client-side HTTP response body. */
const HTTP_CLIENT_RECEIVED_BYTES_VIEW = globalStats.createView(
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc-stats / server-stats.ts View on Github external
'Distribution of server latency in milliseconds, by method.',
  DEFAULT_MILLI_SECONDS_DISTRIBUTION
);

/**
 * {@link View} for completed server RPCs.
 *
 * This {@code View} uses measure {@code GRPC_SERVER_SERVER_LATENCY}, since
 * completed RPCs can be inferred over any measure recorded once per RPC (since
 * it's just a count aggregation over the measure). It would be unnecessary to
 * use a separate "count" measure.
 */
const GRPC_SERVER_COMPLETED_RPC_VIEW = globalStats.createView(
  'grpc.io/server/completed_rpcs',
  GRPC_SERVER_SERVER_LATENCY,
  AggregationType.COUNT,
  [GRPC_SERVER_METHOD, GRPC_SERVER_STATUS],
  'Count of RPCs by method and status.',
  DEFAULT_MESSAGE_COUNT_DISTRIBUTION
);

export const GRPC_BASIC_SERVER_VIEWS: View[] = [
  GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC_VIEW,
  GRPC_SERVER_RECEIVED_BYTES_PER_RPC_VIEW,
  GRPC_SERVER_SENT_MESSAGES_PER_RPC_VIEW,
  GRPC_SERVER_SENT_BYTES_PER_RPC_VIEW,
  GRPC_SERVER_SERVER_LATENCY_VIEW,
  GRPC_SERVER_COMPLETED_RPC_VIEW,
];
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-http / src / http-stats.ts View on Github external
* {@link View} for roundtrip latency distribution of client-side HTTP requests.
 */
const HTTP_CLIENT_ROUNDTRIP_LATENCY_VIEW = globalStats.createView(
  'opencensus.io/http/client/roundtrip_latency',
  HTTP_CLIENT_ROUNDTRIP_LATENCY,
  AggregationType.DISTRIBUTION,
  [HTTP_CLIENT_METHOD, HTTP_CLIENT_STATUS],
  'Roundtrip latency distribution of client-side HTTP requests',
  LATENCY_DISTRIBUTION
);

/** {@link View} for count of server-side HTTP requests serving completed. */
const HTTP_SERVER_COMPLETED_COUNT_VIEW = globalStats.createView(
  'opencensus.io/http/server/completed_count',
  HTTP_SERVER_LATENCY,
  AggregationType.COUNT,
  [HTTP_SERVER_METHOD, HTTP_SERVER_ROUTE, HTTP_SERVER_STATUS],
  'Count of HTTP server-side requests serving completed'
);

/** {@link View} for size distribution of server-side HTTP request body. */
const HTTP_SERVER_RECEIVED_BYTES_VIEW = globalStats.createView(
  'opencensus.io/http/server/received_bytes',
  HTTP_SERVER_RECEIVED_BYTES,
  AggregationType.DISTRIBUTION,
  [HTTP_SERVER_METHOD, HTTP_SERVER_ROUTE, HTTP_SERVER_STATUS],
  'Size distribution of server-side HTTP request body',
  SIZE_DISTRIBUTION
);

/** {@link View} for size distribution of server-side HTTP response body. */
const HTTP_SERVER_SENT_BYTES_VIEW = globalStats.createView(