Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coozzy/prometheus

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coozzy/prometheus - npm Package Compare versions

Comparing version 3.2.4 to 4.0.0

5

index.d.ts

@@ -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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc