Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
);
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
// 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]
);
globalStats.registerView(lineLengthView);
// The begining of our REPL loop
let [_, startNanoseconds] = process.hrtime();
let endNanoseconds;
// REPL is the read, evaluate, print and loop
lineReader.on('line', function (line) {
// Read
try {
snapshot.tagValues[serverStatusIndex]!.value !== 'OK');
if (error) {
zMeasures[method].errors.tot += snapshot.value;
zMeasures[method].errors.min =
this.getRate(
zMeasures[method].errors.tot,
new Date(view.startTime)
) * 60;
zMeasures[method].errors.hr = zMeasures[method].errors.min * 60;
}
}
// Fills the avgLatency columns for that method
if (
snapshot.type === AggregationType.DISTRIBUTION &&
(view.name === DefaultViews.CLIENT_ROUDTRIP_LATENCY ||
view.name === DefaultViews.SERVER_SERVER_LATENCY)
) {
zMeasures[method].avgLatency.tot = snapshot.mean;
zMeasures[method].avgLatency.min =
this.getRate(
zMeasures[method].avgLatency.tot,
new Date(view.startTime)
) * 60;
zMeasures[method].avgLatency.hr =
zMeasures[method].avgLatency.min * 60;
}
}
}
}
if (json) {
// Create a stream to read our file
const stream = fs.createReadStream('./test.txt');
// Create an interface to read and process our file line by line
const lineReader = readline.createInterface({ input: stream });
const methodKey = { name: 'method' };
const statusKey = { name: 'status' };
const tagKeys = [methodKey, statusKey];
// Create & Register the view.
const latencyView = globalStats.createView(
'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'
);
method = snapshot.tagValues[clientMethodIndex]
? snapshot.tagValues[clientMethodIndex]!.value
: '';
zMeasures = rpczData.measuresSent;
} else if (serverMethodIndex !== -1) {
// Switches to received data if it's a server
method = snapshot.tagValues[serverMethodIndex]
? snapshot.tagValues[serverMethodIndex]!.value
: '';
zMeasures = rpczData.measuresReceived;
}
if (zMeasures && method) {
if (!zMeasures[method]) {
zMeasures[method] = this.newEmptyZMeasure();
}
if (snapshot.type === AggregationType.DISTRIBUTION) {
// Fills the output columns for that method
if (
view.name === DefaultViews.CLIENT_SENT_BYTES_PER_RPC ||
view.name === DefaultViews.SERVER_SENT_BYTES_PER_RPC
) {
zMeasures[method].output.tot += snapshot.sum / 1024;
zMeasures[method].output.min =
this.getRate(
zMeasures[method].output.tot,
new Date(view.startTime)
) * 60;
zMeasures[method].output.hr = zMeasures[method].output.min * 60;
}
// Fills the input columns for that method
if (
// 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]
);
globalStats.registerView(lineLengthView);
// The begining of our REPL loop
let [_, startNanoseconds] = process.hrtime();
let endNanoseconds;
// REPL is the read, evaluate, print and loop
lineReader.on('line', function (line) {
// Read
try {
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');
break;
default:
break;
}
statsViewData = { view: selectedView, statsData };
statsContent = ejs.render(viewContentFile, statsViewData, options);
tableContent = ejs.render(
viewFile,
{ view: selectedView, stats_content: statsContent },
options
);
} else {
tableContent = ejs.render(directoriesFile, { folders }, options);
}
);
/** {@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(
'opencensus.io/http/server/sent_bytes',
HTTP_SERVER_SENT_BYTES,
AggregationType.DISTRIBUTION,
[HTTP_SERVER_METHOD, HTTP_SERVER_ROUTE, HTTP_SERVER_STATUS],
'Size distribution of server-side HTTP response body',
SIZE_DISTRIBUTION
);
/**
/**
* Tag key that represents a server gRPC canonical status. Refer to
* https://github.com/grpc/grpc/blob/master/doc/statuscodes.md.
*
* {@link #GRPC_SERVER_STATUS} is set when an incoming request finishes and
* is only available around metrics recorded at the end of the incoming request.
*/
export const GRPC_SERVER_STATUS = {
name: 'grpc_server_status',
};
/** {@link View} for server received messages per RPC. */
const GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC_VIEW = globalStats.createView(
'grpc.io/server/received_messages_per_rpc',
GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC,
AggregationType.DISTRIBUTION,
[GRPC_SERVER_METHOD],
'Distribution of messages received count per RPC, by method.',
DEFAULT_MESSAGE_COUNT_DISTRIBUTION
);
/** {@link View} for server received bytes per RPC. */
const GRPC_SERVER_RECEIVED_BYTES_PER_RPC_VIEW = globalStats.createView(
'grpc.io/server/received_bytes_per_rpc',
GRPC_SERVER_RECEIVED_BYTES_PER_RPC,
AggregationType.DISTRIBUTION,
[GRPC_SERVER_METHOD],
'Distribution of received bytes per RPC, by method.',
DEFAULT_BYTES_DISTRIBUTION
);
/** {@link View} for server sent messages per RPC. */
];
/** {@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(
'opencensus.io/http/client/received_bytes',
HTTP_CLIENT_RECEIVED_BYTES,
AggregationType.DISTRIBUTION,
[HTTP_CLIENT_METHOD, HTTP_CLIENT_STATUS],
'Size distribution of client-side HTTP response body',
SIZE_DISTRIBUTION
);
/**