Observability in practice: instrumenting a Node.js API with Prometheus and Grafana

Learn to instrument a Node.js API with Prometheus and Grafana. Implement metrics, alerts, and dashboards in Docker. Practical observability!

jueves, 2 de julio de 2026 • 3 min read • Q2BSTUDIO Team

Measure your API performance with real-time metrics

Observability has become a fundamental pillar for any team developing and maintaining distributed systems. It is not enough to know that a server is running; we need to understand what happens internally when users experience slowness, intermittent errors, or cascading failures. Tools like Prometheus and Grafana allow technical teams to build a monitoring ecosystem that goes beyond static dashboards. In this article, we will explore how to instrument a Node.js API with Express to expose key metrics, visualize them in Grafana, and define proactive alerts, all from a practical and business perspective.

The traditional 'monitoring' approach falls short when architectures include microservices, message queues, and multiple databases. Observability, on the other hand, allows asking new questions without deploying additional code. By exposing metrics such as request count, latency percentiles, or error rate, we gain a granular view of system behavior. In this context, integrations with AWS and Azure cloud services facilitate scaling these solutions, as both providers offer managed services for metric collection and analysis. Additionally, combining with business intelligence services and Power BI allows unifying operational data with business indicators, offering a 360° view that transcends infrastructure.

To put it into practice, imagine a REST API that processes orders. With the Node.js prom-client library, we register counters for total requests, histograms for duration, and a business metric that distinguishes successful from failed orders. The key lies in label design: using method, route, and status code gives us the necessary dimensionality without falling into unbounded cardinality —a common mistake that can saturate Prometheus memory. By exposing a /metrics endpoint, Prometheus can scrape every few seconds and store the time series. With Docker Compose, we spin up three containers: the API, Prometheus, and Grafana, ready to be queried.

Once data flows, PromQL queries allow us to calculate request rate, 5xx error percentage, or the 95th latency percentile. These three metrics cover the well-known RED method (Rate, Errors, Duration), sufficient to diagnose the health of any service. But metrics without alerts are just pretty graphs. Defining alert rules that fire when the error rate exceeds 10% for two minutes or when p95 latency exceeds one second transforms data into immediate actions. This is where AI for businesses and AI agents can enrich the system, automating responses to alerts or correlating metrics with business events.

From Q2BSTUDIO's experience, we know that implementing observability must be part of the development cycle, not an afterthought. When developing custom applications, we include instrumentation with Prometheus and Grafana from the first sprint, ensuring each microservice exposes key metrics. The same applies to custom software projects in cloud environments, where AWS and Azure managed services simplify storage and scalability. Cybersecurity also benefits: well-configured observability allows detecting anomalous patterns that could indicate an attack, so our solutions integrate cybersecurity and pentesting to protect both data and exposed metrics.

In addition to infrastructure metrics, business metrics are equally important. Knowing that orders_processed_total{status='failed'} spikes is far more relevant than seeing a CPU peak. Therefore, when designing panels in Grafana, we combine technical indicators with business KPIs, facilitating data-driven decision-making. Artificial intelligence can enhance this analysis by detecting trends before they become incidents. Our team implements AI agent solutions that automate event correlation, reducing mean time to detection (MTTD) and mean time to response (MTTR).

If you haven't instrumented your services yet, now is the time. Start with a /metrics endpoint, define a few well-labeled metrics, and visualize them in Grafana. Then add alerts connected to your SLOs. At Q2BSTUDIO, we help companies implement complete observability, combining business intelligence services, cloud, and automation so that technology works for the business. Observability is not a luxury: it is a practice that separates reactive teams from proactive ones.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.