# nice-grpc-prometheus

> Prometheus monitoring for nice-grpc

Latest version **0.2.12** (published 2026-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install nice-grpc-prometheus
pnpm add nice-grpc-prometheus
yarn add nice-grpc-prometheus
bun add nice-grpc-prometheus
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.12 |
| Published | 2026-08-04 |
| First published | 2022-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 41.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 538 |
| Author | Daniel Lytkin <aikoven@deeplay.io> |
| Maintainers | aikoven |
| Keywords | grpc, nice-grpc, prometheus, monitoring, metrics |

## Links

- npm: https://www.npmjs.com/package/nice-grpc-prometheus
- Repository: https://github.com/deeplay-io/nice-grpc
- Homepage: https://github.com/deeplay-io/nice-grpc/tree/master/packages/nice-grpc-prometheus#readme
- Issues: https://github.com/deeplay-io/nice-grpc/issues
- npm.io page: https://npm.io/package/nice-grpc-prometheus

## Dependencies (3)

- [prom-client](https://npm.io/package/prom-client.md) ^15.1.0
- [nice-grpc-common](https://npm.io/package/nice-grpc-common.md) ^2.0.4
- [abort-controller-x](https://npm.io/package/abort-controller-x.md) ^0.5.0

## Recent versions

- 0.2.12 (latest) — 2026-08-04
- 0.2.11 — 2026-04-24
- 0.2.10 — 2026-04-12
- 0.2.9 — 2025-11-12
- 0.2.8 — 2025-10-01
- 0.2.7 — 2025-03-26
- 0.2.6 — 2025-02-18
- 0.2.5 — 2024-09-24
- 0.2.4 — 2024-06-06
- 0.2.3 — 2024-03-11
- 0.2.2 — 2023-10-19
- 0.2.1 — 2023-10-17
- 0.2.0 — 2023-08-24
- 0.1.7 — 2023-07-16
- 0.1.6 — 2023-03-31
- … 6 more at https://npm.io/package/nice-grpc-prometheus/versions

## README

# nice-grpc-prometheus [![npm version][npm-image]][npm-url]

[Prometheus](https://prometheus.io/) monitoring for
[nice-grpc](https://github.com/deeplay-io/nice-grpc). Uses
[prom-client](https://github.com/siimon/prom-client). Metrics mostly mimic
[go-grpc-prometheus](https://github.com/grpc-ecosystem/go-grpc-prometheus).

## Installation

    npm install nice-grpc-prometheus

## Usage

Import `nice-grpc-prometheus` metrics registry and
[merge it with the global registry](https://github.com/siimon/prom-client#multiple-registries):

```ts
import {register as globalRegistry, Registry} from 'prom-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:

```ts
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:

```ts
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](https://grpc.github.io/grpc/core/md_doc_statuscodes.html) name | `OK`, `CANCELLED`, `NOT_FOUND` |

[npm-image]: https://badge.fury.io/js/nice-grpc-prometheus.svg
[npm-url]: https://badge.fury.io/js/nice-grpc-prometheus

### Customization

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

```ts
import {createClientFactory} from 'nice-grpc';
import {
  labelNamesWithCode,
  prometheusClientMiddleware,
} from 'nice-grpc-prometheus';
import {Histogram, Registry} from 'prom-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](https://github.com/siimon/prom-client#multiple-registries)
or use default registry instead.

Client middleware options:

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

Server middleware options:

```ts
{
  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.

---
_Source: https://npm.io/package/nice-grpc-prometheus · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
