@coozzy/prometheus
Advanced tools
Comparing version 3.2.4 to 4.0.0
@@ -6,5 +6,2 @@ /*~ If this module is a UMD module that exposes a global variable 'myLib' when | ||
import {Request, Response, NextFunction} from "express"; | ||
import {ServerInterceptingCall} from "@grpc/grpc-js"; | ||
import {ServerInterceptingCallInterface} from "@grpc/grpc-js/src/server-interceptors"; | ||
import {ServerMethodDefinition} from "@grpc/grpc-js/build/src/make-client"; | ||
@@ -24,3 +21,3 @@ export as namespace metrics; | ||
function grpcMiddleware(methodDescriptor: ServerMethodDefinition<any, any>, call: ServerInterceptingCallInterface): ServerInterceptingCall; | ||
function grpcResponseTime(methodName: string, statusCode: number, responseTime: number): void; | ||
@@ -27,0 +24,0 @@ function incGrpcError(clientName: string, methodName: string, errorCode: number): void; |
42
index.js
const Prometheus = require('prom-client'); | ||
const http = require('http'); | ||
const grpc = require('@grpc/grpc-js'); | ||
const logger = require('@coozzy/logger'); | ||
@@ -85,31 +83,13 @@ | ||
module.exports.grpcMiddleware = function (methodDescriptor, call) { | ||
let startTime; | ||
const listener = new grpc.ServerListenerBuilder() | ||
.withOnReceiveMessage((message, next) => { | ||
startTime = Date.now(); | ||
next(message); | ||
}) | ||
.build(); | ||
const responder = new grpc.ResponderBuilder() | ||
.withStart(next => next(listener)) | ||
.withSendStatus((status, next) => { | ||
const responseTime = Date.now() - startTime; | ||
if (grpcRequestDurationMilliseconds) { | ||
grpcRequestDurationMilliseconds | ||
.observe( | ||
{ | ||
method: methodDescriptor.path ? methodDescriptor.path.substring(methodDescriptor.path.lastIndexOf('/') + 1): 'unknown-path', | ||
status_code: status.code | ||
}, | ||
responseTime | ||
); | ||
} | ||
next(status); | ||
}) | ||
.build() | ||
return new grpc.ServerInterceptingCall(call, responder); | ||
module.exports.grpcResponseTime = function (methodName, statusCode, responseTime) { | ||
if (grpcRequestDurationMilliseconds) { | ||
grpcRequestDurationMilliseconds | ||
.observe( | ||
{ | ||
method: methodName, | ||
status_code: statusCode | ||
}, | ||
responseTime | ||
); | ||
} | ||
}; | ||
@@ -116,0 +96,0 @@ |
{ | ||
"name": "@coozzy/prometheus", | ||
"version": "3.2.4", | ||
"version": "4.0.0", | ||
"description": "Helps collecting and exporting prometheus metrics", | ||
@@ -18,4 +18,3 @@ "main": "index.js", | ||
"@coozzy/logger": "1.3.2", | ||
"prom-client": "15.1.2", | ||
"@grpc/grpc-js": "1.10.6" | ||
"prom-client": "15.1.2" | ||
}, | ||
@@ -22,0 +21,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
8481
205
- Removed@grpc/grpc-js@1.10.6
- Removed@grpc/grpc-js@1.10.6(transitive)
- Removed@grpc/proto-loader@0.7.13(transitive)
- Removed@js-sdsl/ordered-map@4.4.2(transitive)
- Removed@protobufjs/aspromise@1.1.2(transitive)
- Removed@protobufjs/base64@1.1.2(transitive)
- Removed@protobufjs/codegen@2.0.4(transitive)
- Removed@protobufjs/eventemitter@1.1.0(transitive)
- Removed@protobufjs/fetch@1.1.0(transitive)
- Removed@protobufjs/float@1.0.2(transitive)
- Removed@protobufjs/inquire@1.1.0(transitive)
- Removed@protobufjs/path@1.1.2(transitive)
- Removed@protobufjs/pool@1.1.0(transitive)
- Removed@protobufjs/utf8@1.1.0(transitive)
- Removed@types/node@22.10.1(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedcliui@8.0.1(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescalade@3.2.0(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedlodash.camelcase@4.3.0(transitive)
- Removedlong@5.2.3(transitive)
- Removedprotobufjs@7.4.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@17.7.2(transitive)
- Removedyargs-parser@21.1.1(transitive)