Logo

dev-resources.site

for different kinds of informations.

[Open Source] Simplify Metrics Reporting in NestJS with a Zero-Dependency-Injection Global Reporter

Published at
12/13/2024
Categories
nestjs
metrics
prometheus
monitoring
Author
netanelavr
Author
10 person written this
netanelavr
open
[Open Source] Simplify Metrics Reporting in NestJS with a Zero-Dependency-Injection Global Reporter

Hey everyone! πŸ‘‹

I'd like to share an open-source package I recently developed called nestjs-metrics-reporter. It's designed to make metrics reporting in NestJS as simple and seamless as possible.

Why Did I Create This?

When using other metrics libraries, I found that the dependency injection setup and boilerplate often got in the way more than they helped. Because of this, I wrote a zero-dependency-injection alternative to make reporting metrics from anywhere in your codebase easier.

I wrote about the motivation and technical details in more depth in my Medium article Avoid Prometheus Mess in NestJS

Key Features

  • No Dependency Injection – Global static ReporterService for clean, portable code.
  • Effortless Integration – Zero-setup, start tracking metrics instantly.
  • Support for Pushgateway – Push batch job metrics effortlessly.
  • Designed for Simplicity – Spend time coding, rather than dealing with complex configurations.

How It Works

With a minimal setup in your AppModule, you'll start reporting metrics like counters, gauges, histograms, and summaries in no time:

1. Install the package:

npm install nestjs-metrics-reporter
Enter fullscreen mode Exit fullscreen mode

2. Configure the module:

ReporterModule.forRoot({
   defaultMetricsEnabled: true,
   defaultLabels: {
     app: 'my-app',
   },
}),
Enter fullscreen mode Exit fullscreen mode

3. Report metrics anywhere in your application:

ReporterService.gauge('active_users', 42, { region: 'us-east-1' });
Enter fullscreen mode Exit fullscreen mode

I'd be happy to hear your feedback! Feel free to dive in, open issues, or send PRs my way.

πŸ‘‰ GitHub Repo: nestjs-metrics-reporter

πŸ‘‰ NPM Package: nestjs-metrics-reporter

If you find this helpful, please consider starring ⭐ the repo on GitHub and using the package in your projects. Your feedback will help make it even better.

prometheus Article's
30 articles in total
Favicon
Monitoring AWS Infrastructure: Building a Real-Time Observability Dashboard with Amazon CloudWatch and Prometheus
Favicon
Monitor Your Static App memory usage EC2 Instances with Prometheus and Grafana
Favicon
Scraping Custom Django Metrics with Prometheus
Favicon
Prometheus
Favicon
[HANDS ON] Service Discovery in Prometheus
Favicon
CloudOps Challenge - Real-Time Projects
Favicon
Prometheus Instance Exposed
Favicon
Deploying Prometheus With Docker
Favicon
Prometheus json_exporter: Monitor any JSON API endpoint with Prometheus
Favicon
Prometheus for Absolute Beginners
Favicon
Dockerized Deployment of a Full Stack Application with Reverse Proxy, Monitoring & Observability
Favicon
Monitoring Containerized Applications with Kubernetes Tools: A Comprehensive Guide
Favicon
What is Observability?
Favicon
Kubernetes Metrics and Monitoring with Prometheus and Grafana
Favicon
Monitoring Modbus via Prometheus and Grafana
Favicon
RabbitMQ Monitoring with Prometheus and Grafana
Favicon
Docker with Prometheus and Grafana: Real-Time Monitoring Simplified
Favicon
How to Configure a Remote Data Store for Prometheus
Favicon
EKS & NGINX Load Balancer Monitor with Prometheus, Grafana, andΒ Alerts
Favicon
[Open Source] Simplify Metrics Reporting in NestJS with a Zero-Dependency-Injection Global Reporter
Favicon
Docker to the Rescue: Deploying React And FastAPI App With Monitoring
Favicon
A Beginner's Guide To Service Discovery in Prometheus
Favicon
Usando stack de monitoria opensource no Kubernetes (sem Prometheus)
Favicon
Prometheus - How it's work
Favicon
Prometheus 3.0: A Quantum Leap in Monitoring
Favicon
Observability - 3(Prometheus Explanation)
Favicon
Observability - 2(Metrics, Monitoring & Prometheus)
Favicon
Golang com Opentelemetry, prometheus, Grafana tempo OSS e Grafana padrΓ£o
Favicon
Prometheus vs CloudWatch for Cloud Native Applications (Updated in 2024)
Favicon
Prometheus Stack Components Usage in K8 Cluster using Helm

Featured ones: