How to use the @opencensus/core.MeasureUnit.UNIT 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
// The project id must be provided for running in a local environment
const project = process.env.GOOGLE_CLOUD_PROJECT;
assert(typeof project !== 'undefined' && project,
  "Please set environment variable GOOGLE_CLOUD_PROJECT to the project id.");
console.log(`Sending metrics data to project: ${project}`);

// OpenCensus setup
// [START web_client_monitoring_ocsetup]
const exporter = new StackdriverStatsExporter({projectId: project});
globalStats.registerExporter(exporter);
const mLatencyMs = globalStats.createMeasureDouble("webmetrics/latency",
                       MeasureUnit.MS,
                       "Latency related to page loading");
const mClickCount = globalStats.createMeasureInt64("webmetrics/click_count",
                       MeasureUnit.UNIT,
                       "Number of clicks");
const buckets = [0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80,
                100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000,
                5000, 10000, 20000, 50000, 100000];

const tagPhase = { name: "phase" };
const tagClient = { name: "client" };

const latencyView = globalStats.createView(
  "webmetrics/latency",
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  [tagPhase, tagClient],
  "Distribution of latencies",
  buckets
);
github census-instrumentation / opencensus-node / examples / gauge / derived-gauge-quickstart.js View on Github external
constructor () { this.depth = 0; }
  getPendingJobs () { return this.depth; }
  addJob () { this.depth++; }
}

// a registry is a collection of metric objects.
const metricRegistry = Metrics.getMetricRegistry();

// application labels - applied to each metric / gauge.
const labelKeys = [{ key: 'VM', description: 'VM Description' }];
const labelValues = [{ value: 'localhost' }];

// a new gauge instance - builds a new Int64 gauge to be added to the registry.
const metricOptions = {
  description: 'Number of active handles',
  unit: MeasureUnit.UNIT,
  labelKeys: labelKeys
};
const gauge = metricRegistry.addDerivedInt64Gauge('active_handles_total', metricOptions);

const queue = new QueueManager();
queue.addJob();

// The value of the gauge is observed from a function whenever metrics are
// collected. In this case it will be 1.
gauge.createTimeSeries(labelValues, () => queue.getPendingJobs());
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc-stats / server-stats.ts View on Github external
globalStats,
  Measure,
  MeasureUnit,
  View,
} from '@opencensus/core';

import {
  DEFAULT_BYTES_DISTRIBUTION,
  DEFAULT_MESSAGE_COUNT_DISTRIBUTION,
  DEFAULT_MILLI_SECONDS_DISTRIBUTION,
} from './common-distributions';

/** {@link Measure} for number of messages received in each RPC. */
export const GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/server/received_messages_per_rpc',
  MeasureUnit.UNIT,
  'Number of messages received in each RPC. Has value 1 for non-streaming RPCs.'
);

/** {@link Measure} for gRPC server latency in milliseconds. */
export const GRPC_SERVER_SERVER_LATENCY: Measure = globalStats.createMeasureDouble(
  'grpc.io/server/server_latency',
  MeasureUnit.MS,
  'Time between first byte of request received to last byte of response sent, or terminal error.'
);

/** {@link Measure} for number of messages sent in each RPC. */
export const GRPC_SERVER_SENT_MESSAGES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/server/sent_messages_per_rpc',
  MeasureUnit.UNIT,
  'Number of messages sent in each RPC. Has value 1 for non-streaming RPCs.'
);
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc-stats / server-stats.ts View on Github external
'grpc.io/server/received_messages_per_rpc',
  MeasureUnit.UNIT,
  'Number of messages received in each RPC. Has value 1 for non-streaming RPCs.'
);

/** {@link Measure} for gRPC server latency in milliseconds. */
export const GRPC_SERVER_SERVER_LATENCY: Measure = globalStats.createMeasureDouble(
  'grpc.io/server/server_latency',
  MeasureUnit.MS,
  'Time between first byte of request received to last byte of response sent, or terminal error.'
);

/** {@link Measure} for number of messages sent in each RPC. */
export const GRPC_SERVER_SENT_MESSAGES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/server/sent_messages_per_rpc',
  MeasureUnit.UNIT,
  'Number of messages sent in each RPC. Has value 1 for non-streaming RPCs.'
);

/** {@link Measure} for total bytes received across all messages per RPC. */
export const GRPC_SERVER_RECEIVED_BYTES_PER_RPC: Measure = globalStats.createMeasureDouble(
  'grpc.io/server/received_bytes_per_rpc',
  MeasureUnit.BYTE,
  'Total bytes received across all messages per RPC.'
);

/**
 * {@link Measure} for total bytes sent across all response messages per RPC.
 */
export const GRPC_SERVER_SENT_BYTES_PER_RPC: Measure = globalStats.createMeasureDouble(
  'grpc.io/server/sent_bytes_per_rpc',
  MeasureUnit.BYTE,
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc-stats / client-stats.ts View on Github external
AggregationType,
  globalStats,
  Measure,
  MeasureUnit,
  View,
} from '@opencensus/core';
import {
  DEFAULT_BYTES_DISTRIBUTION,
  DEFAULT_MESSAGE_COUNT_DISTRIBUTION,
  DEFAULT_MILLI_SECONDS_DISTRIBUTION,
} from './common-distributions';

/** {@link Measure} for number of messages sent in the RPC. */
export const GRPC_CLIENT_SENT_MESSAGES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/client/sent_messages_per_rpc',
  MeasureUnit.UNIT,
  'Number of messages sent in the RPC (always 1 for non-streaming RPCs).'
);

/**
 * {@link Measure} for total bytes sent across all request messages per RPC.
 */
export const GRPC_CLIENT_SENT_BYTES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/client/sent_bytes_per_rpc',
  MeasureUnit.BYTE,
  'Total bytes sent across all request messages per RPC.'
);

/** {@link Measure} for number of response messages received per RPC. */
export const GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/client/received_messages_per_rpc',
  MeasureUnit.UNIT,
github census-instrumentation / opencensus-node / packages / opencensus-instrumentation-grpc / src / grpc-stats / client-stats.ts View on Github external
'Number of messages sent in the RPC (always 1 for non-streaming RPCs).'
);

/**
 * {@link Measure} for total bytes sent across all request messages per RPC.
 */
export const GRPC_CLIENT_SENT_BYTES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/client/sent_bytes_per_rpc',
  MeasureUnit.BYTE,
  'Total bytes sent across all request messages per RPC.'
);

/** {@link Measure} for number of response messages received per RPC. */
export const GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/client/received_messages_per_rpc',
  MeasureUnit.UNIT,
  'Number of response messages received per RPC (always 1 for non-streaming RPCs).'
);

/**
 * {@link Measure} for total bytes received across all response messages per RPC
 */
export const GRPC_CLIENT_RECEIVED_BYTES_PER_RPC: Measure = globalStats.createMeasureInt64(
  'grpc.io/client/received_bytes_per_rpc',
  MeasureUnit.BYTE,
  'Total bytes received across all response messages per RPC.'
);

/** {@link Measure} for gRPC client roundtrip latency in milliseconds. */
export const GRPC_CLIENT_ROUNDTRIP_LATENCY: Measure = globalStats.createMeasureDouble(
  'grpc.io/client/roundtrip_latency',
  MeasureUnit.MS,