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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rnw-community/nestjs-rxjs-metrics

v1.8.2

Published

NestJS RxJS logger

Readme

NestJS RxJS metrics

NestJS prometheus metrics wrapper for using with RxJS streams with full TypeScript support.

npm version npm downloads

Installation

Install additional peer dependencies:

Configuration

  • Create custom metrics objects for each type of metrics, this is needed for safe TS usage inside the service operators:
export const counterMetrics = { my_counter_metric: 'My counter metric description' };
export const gaugeMetrics = { my_gauge_metric: 'My gauge metric description' };
export const histogramMetrics = { my_histogram_metric: 'My histogram metric description' };
export const summaryMetrics = { my_summary_metric: 'My summary metric description' };
  • Create custom histogram and summary metrics labels objects, this is needed for safe TS usage inside the service operators:

Using [...] as const is important for TS type checking to work

const histogramLabels = {
    my_histogram_metric: ['my_histogram_metric_label'] as const,
};

const summaryLabels = {
    my_summary_metric: ['my_summary_label'] as const,
};
  • Create metrics module and service for NestJS DI, this module and service should be used in the project:
import { Inject, Injectable } from '@nestjs/common';

import { MetricsServiceMixin } from '@rnw-community/nestjs-rxjs-metrics';

import type { counterMetrics } from './counter.metrics';
import type { gaugeMetrics } from './gauge.metrics';
import type { histogramMetrics } from './histogram.metrics';
import type { summaryMetrics } from './summary.metrics';

export const [BaseMetricsModule, BaseMetricsService] = NestJSRxJSMetricsModule.create({
    counterMetrics,
    gaugeMetrics,
    histogramMetrics,
    summaryMetrics,
    summaryLabels,
    histogramLabels,
    controller: PrometheusController,
});

@Injectable()
export class MetricsService extends BaseMetricsService {}

@Module({
    imports: [BaseMetricsModule],
    providers: [MetricsService],
    exports: [MetricsService],
})
export class MetricsModule {}

Usage

This package provides a set of RxJS operators for beautiful usage of prometheus metrics inside the streams. Take a look at best practises and other useful docs from official prometheus documentation.

Counter

Counter supports next operator:

  • counter(CounterMetric, value = 1) operator - increment counter metric by value
const counterMetrics = { my_counter_metric: 'Text counter metric' };

@Injectable()
export class MyService {
    constructor(private readonly metrics: MetricsService) {}

    externalAction$() {
        return of(true).pipe(
            // perform actions
            this.metrics.counter('my_counter_metric' /* defaut value is 1, you can proide another number */)
        );
    }
}

Gauge

Gauge supports next operators:

  • gauge(GaugeMetric, handler: (gauge: Gauge<string>) => void) operator - observe Gauge metric and perform callback on it
  • gaugeInc(GaugeMetric, value = 1) => void) operator - increment Gauge metric by value
  • gaugeDec(GaugeMetric, value = 1) => void) operator - decrement Gauge metric by value
const gaugeMetrics = { my_gauge_metric: 'Text gauge metric' };

@Injectable()
export class MyService {
    constructor(private readonly metrics: MetricsService) {}

    activateAction$() {
        return of(true).pipe(
            // perform actions
            this.metrics.gaugeInc('my_gauge_metric' /* defaut value is 1, you can proide another number */)
        );
    }

    deactivateAction$() {
        return of(true).pipe(
            // perform actions
            this.metrics.gaugeDec('my_gauge_metric' /* defaut value is 1, you can proide another number */)
        );
    }
}

Histogram

Histogram supports next operators:

  • histogramStart(HistogramMetric, labels?: LabelValues<L>) operator - start observing Histogram metric with labels
  • histogramEnd(HistogramMetric, labels?: LabelValues<L>)) operator - finish observing Histogram metric with labels
const histogramMetrics = { my_histogram_metric: 'Text histogram metric' };
const histogramLabels = { my_histogram_metric: ['my_histogram_metric_label1'] as const };

@Injectable()
export class MyService {
    constructor(private readonly metrics: MetricsService) {}

    exampleAction$() {
        return of(true).pipe(
            this.metrics.histogramStart('my_histogram_metric', { my_histogram_metric_label1: 1 }),
            // perform actions
            this.metrics.histogramEnd('my_histogram_metric', { my_histogram_metric_label1: 2 })
        );
    }
}

Summary

Summary supports next operators:

  • histogramStart(SumaryMetric, labels?: LabelValues<L>) operator - start observing Summary metric with labels
  • histogramEnd(SummaryMetric, labels?: LabelValues<L>)) operator - finish observing Summary metric with labels
const summaryMetrics = { my_summary_metric: 'Text summary metric' };
const summaryLabels = { my_summary_metric: ['my_summary_metric_label1'] as const };

@Injectable()
export class MyService {
    constructor(private readonly metrics: MetricsService) {}

    exampleAction$() {
        return of(true).pipe(
            this.metrics.histogramStart('my_summary_metric', { my_summary_metric_label1: 1 }),
            // perform actions
            this.metrics.histogramEnd('my_summary_metric', { my_summary_metric_label1: 2 })
        );
    }
}

License

This library is licensed under The MIT License.