UNPKG

nice-grpc-prometheus

Version:

Prometheus monitoring for nice-grpc

41 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.labelNamesWithCode = exports.labelNames = exports.latencySecondsBuckets = exports.codeLabel = exports.pathLabel = exports.methodLabel = exports.serviceLabel = exports.typeLabel = void 0; exports.getLabels = getLabels; exports.incrementStreamMessagesCounter = incrementStreamMessagesCounter; const prom_client_1 = require("prom-client"); exports.typeLabel = 'grpc_type'; exports.serviceLabel = 'grpc_service'; exports.methodLabel = 'grpc_method'; exports.pathLabel = 'grpc_path'; exports.codeLabel = 'grpc_code'; /** * 1ms, 4ms, 16ms, ..., ~1 hour in seconds */ exports.latencySecondsBuckets = (0, prom_client_1.exponentialBuckets)(0.001, 4, 12); exports.labelNames = [exports.typeLabel, exports.serviceLabel, exports.methodLabel, exports.pathLabel]; exports.labelNamesWithCode = [...exports.labelNames, exports.codeLabel]; function getLabels(method) { const callType = method.requestStream ? method.responseStream ? 'bidi_stream' : 'client_stream' : method.responseStream ? 'server_stream' : 'unary'; const { path } = method; const [serviceName, methodName] = path.split('/').slice(1); return { [exports.typeLabel]: callType, [exports.serviceLabel]: serviceName, [exports.methodLabel]: methodName, [exports.pathLabel]: path, }; } async function* incrementStreamMessagesCounter(iterable, counter) { for await (const item of iterable) { counter.inc(); yield item; } } //# sourceMappingURL=common.js.map