Gathering detailed insights and metrics for nestjs-hot-shots
Gathering detailed insights and metrics for nestjs-hot-shots
Gathering detailed insights and metrics for nestjs-hot-shots
Gathering detailed insights and metrics for nestjs-hot-shots
npm install nestjs-hot-shots
Typescript
Module System
Min. Node Version
Node Version
NPM Version
82.6
Supply Chain
97.8
Quality
94.6
Maintenance
100
Vulnerability
100
License
TypeScript (93.48%)
JavaScript (6.52%)
Total Downloads
719,563
Last Day
1,101
Last Week
5,502
Last Month
24,844
Last Year
285,598
MIT License
20 Stars
1,008 Commits
2 Watchers
1 Branches
2 Contributors
Updated on May 12, 2025
Minified
Minified + Gzipped
Latest Version
3.1.0
Package Id
nestjs-hot-shots@3.1.0
Unpacked Size
48.98 kB
Size
11.18 kB
File Count
55
NPM Version
10.9.2
Node Version
22.14.0
Published on
Apr 21, 2025
Cumulative downloads
Total Downloads
Last Day
1.8%
1,101
Compared to previous day
Last Week
-18%
5,502
Compared to previous week
Last Month
0.9%
24,844
Compared to previous month
Last Year
-11.7%
285,598
Compared to previous year
1
5
31
Hot-shots Module for Nest.js Framework. A Node.js client for Etsy's StatsD server, Datadog's DogStatsD server, and InfluxDB's Telegraf StatsD server.
Features
For questions and support please use the Issues.
1$ npm i nestjs-hot-shots hot-shots 2$ yarn add nestjs-hot-shots hot-shots 3$ pnpm add nestjs-hot-shots hot-shots
Once the installation process is complete, we can import the HotShotsModule
into the root AppModule
:
1import { Module } from '@nestjs/common' 2import { HotShotsModule } from 'nestjs-hot-shots'; 3 4@Module({ 5 imports: [ 6 HotShotsModule.forRoot({ 7 port: 8020, 8 globalTags: { env: process.env.NODE_ENV } 9 }) 10 ] 11}) 12export class AppModule { 13}
Then inject StatsD
provider for use hot-shots
:
1import { Injectable } from '@nestjs/common'; 2import { StatsD } from 'hot-shots'; 3 4@Injectable() 5export class AppMetrics { 6 public constructor(private readonly metrics: StatsD) { 7 } 8 9 public metricStuff() { 10 this.metrics.increment('somecounter'); 11 } 12}
You can use the MetricsService
for metrics collection. It`s factory for creating metrics. It provides a set of methods to create different
types of metrics, such as counters, gauges, and histograms.
1import { Controller, Post } from '@nestjs/common'; 2import { MetricsService } from 'nestjs-hot-shots'; 3import { StatsD } from 'hot-shots'; 4 5@Controller 6export class BooksController { 7 private readonly booksAdded = this.metricsService.getCounter('books.added.count'); 8 9 public constructor(private readonly metricsService: MetricsService) { 10 } 11 12 @Post() 13 public async addBook() { 14 // some logic 15 this.booksAdded.add(); 16 } 17}
Method | Description |
---|---|
getCounter(name: string) | Returns a counter metric with the given name. |
getGauge(name: string) | Returns a gauge metric with the given name. |
getHistogram(name: string) | Returns a histogram metric with the given name. |
getTimer(name: string) | Returns a timer metric with the given name. |
getUpDownCounter(name: string) | Returns an up-down counter metric with the given name. |
You can use the HttpMetricsMiddleware
to collect HTTP metrics. It will automatically collect metrics for all incoming requests and
outgoing responses.
1import { Module } from '@nestjs/common'; 2import { HotShotsModule } from 'nestjs-hot-shots'; 3import { HttpMetricsMiddleware } from 'nestjs-hot-shots'; 4 5@Module({ 6 imports: [ 7 HotShotsModule.forRoot({ 8 ... 9 }) 10 ] 11}) 12export class AppModule { 13 public configure(consumer: MiddlewareConsumer) { 14 consumer 15 .apply(HttpMetricsMiddleware) 16 .forRoutes('*'); 17 } 18}
Metric | Description | Type |
---|---|---|
http_server_request_count | Total number of requests received by the server | Counter |
http_server_response_count | Total number of responses sent by the server | Counter |
http_server_duration | Total time taken to process requests | Histogram |
http_server_request_size | Size of incoming bytes. | Histogram |
http_server_response_size | Size of outgoing bytes. | Histogram |
http_server_response_success_count | Total number of all successful responses. | Counter |
http_server_response_error_count | Total number of server error responses. | Counter |
http_client_request_error_count | Total number of client error requests. | Counter |
http_server_abort_count | Total number of aborted requests | Counter |
Inspired by nestjs-otel
See the hot-shots module for more details.
No vulnerabilities found.
No security vulnerabilities found.