npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nice-grpc-prometheus

v0.3.0

Published

Prometheus monitoring for nice-grpc

Readme

nice-grpc-prometheus npm version

Prometheus monitoring for nice-grpc. Uses @prometheus-io/client. Metrics mostly mimic go-grpc-prometheus.

Installation

npm install nice-grpc-prometheus

Usage

Import nice-grpc-prometheus metrics registry and merge it with the global registry:

import {register as globalRegistry, Registry} from '@prometheus-io/client';
import {registry as niceGrpcRegistry} from 'nice-grpc-prometheus';

// use `await mergedRegistry.metrics()` to export all metrics
const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry]);

Attach middleware as the first one on the server:

import {createServer} from 'nice-grpc';
import {prometheusServerMiddleware} from 'nice-grpc-prometheus';

const server = createServer()
  .use(prometheusServerMiddleware())
  .use(/* ... other middleware */);

Attach middleware as the first one on the client:

import {createClientFactory} from 'nice-grpc';
import {prometheusClientMiddleware} from 'nice-grpc-prometheus';

const clientFactory = createClientFactory()
  .use(prometheusClientMiddleware())
  .use(/* ... other middleware */);

const client = clientFactory.create(/* ... */);

Metrics

Following metrics are provided:

Server

| Name | Type | Description | Labels | | -------------------------------- | --------- | ------------------------------------------------------------------------------------------------------ | -------------------- | | grpc_server_started_total | Counter | Total number of RPCs started on the server. | Common (see below) | | grpc_server_handled_total | Counter | Total number of RPCs completed on the server, regardless of success or failure. | Common + grpc_code | | grpc_server_msg_received_total | Counter | Total number of RPC stream messages received by the server. | Common | | grpc_server_msg_sent_total | Counter | Total number of gRPC stream messages sent by the server. | Common | | grpc_server_handling_seconds | Histogram | Histogram of response latency (seconds) of gRPC that had been application-level handled by the server. | Common + grpc_code |

Client

| Name | Type | Description | Labels | | -------------------------------- | --------- | -------------------------------------------------------------------------------------------- | -------------------- | | grpc_client_started_total | Counter | Total number of RPCs started on the client. | Common | | grpc_client_handled_total | Counter | Total number of RPCs completed on the client, regardless of success or failure. | Common + grpc_code | | grpc_client_msg_received_total | Counter | Total number of RPC stream messages received by the client. | Common | | grpc_client_msg_sent_total | Counter | Total number of gRPC stream messages sent by the client. | Common | | grpc_client_handling_seconds | Histogram | Histogram of response latency (seconds) of the gRPC until it is finished by the application. | Common + grpc_code |

Labels

Common labels:

| Name | Description | Examples | | -------------- | ------------------------------ | -------------------------------------------------------- | | grpc_type | Call type | unary, server_stream, client_stream, bidi_stream | | grpc_path | Full path of a method | /my.package.MyService/MyMethod | | grpc_service | Full service name with package | my.package.MyService | | grpc_method | Method name | MyMethod |

Metrics that correspond to finished calls have extra label:

| Name | Description | Examples | | ----------- | ---------------------------------------------------------------------------- | ------------------------------ | | grpc_code | Status code name | OK, CANCELLED, NOT_FOUND |

Customization

You can use your own metric instances. This can be useful for example if you want to use your own buckets in histograms.

import {createClientFactory} from 'nice-grpc';
import {
  labelNamesWithCode,
  prometheusClientMiddleware,
} from 'nice-grpc-prometheus';
import {Histogram, Registry} from '@prometheus-io/client';

const registry = new Registry();

const clientHandlingSecondsMetric = new Histogram({
  registers: [registry],
  name: 'custom_grpc_client_handling_seconds',
  help: 'Custom histogram of response latency (seconds) of the gRPC until it is finished by the application.',
  labelNames: labelNamesWithCode,
  buckets: [0.1, 0.5, 1, 2, 3, 5, 10],
});

const clientFactory = createClientFactory()
  .use(prometheusClientMiddleware({clientHandlingSecondsMetric}))
  .use(/* ... other middleware */);

Don't forget to merge new registry with the global registry or use default registry instead.

Client middleware options:

{
  clientStartedMetric?: Counter; // labelNames: labelNames
  clientHandledMetric?: Counter; // labelNames: labelNamesWithCode
  clientStreamMsgReceivedMetric?: Counter; // labelNames: labelNames
  clientStreamMsgSentMetric?: Counter; // labelNames: labelNames
  clientHandlingSecondsMetric?: Histogram; // labelNames: labelNamesWithCode
}

Server middleware options:

{
  serverStartedMetric?: Counter; // labelNames: labelNames
  serverHandledMetric?: Counter; // labelNames: labelNamesWithCode
  serverStreamMsgReceivedMetric?: Counter; // labelNames: labelNames
  serverStreamMsgSentMetric?: Counter; // labelNames: labelNames
  serverHandlingSecondsMetric?: Histogram; // labelNames: labelNamesWithCode
}

Caution: Use the labelNames specified in the comment. Using incorrect labelNames may cause errors now or in the future.