5th Week :- Why Monitoring Should Be a Developerβs Responsibility Too

Table of contents
- π οΈ Monitoring in Modern Applications β A Deep Dive with New Relic
- π What is Monitoring?
- π― Why Monitoring Matters
- π§ New Relic β Full Stack Observability
- βοΈ How to Set Up New Relic in a Node.js App
- π What You Can Monitor with New Relic
- π§ͺ Example: Monitor High CPU Route
- π‘ Best Practices for Monitoring
- π Conclusion
- π Prometheus vs New Relic β Which Monitoring Tool Should You Use?
- π₯ Prometheus vs New Relic: Key Differences
- β Why Use Prometheus over New Relic?
- π What is Prometheus?
- π What is Grafana?
- π How to Set Up Prometheus + Grafana Monitoring (Step-by-Step)
- β¨ Advanced Features You Can Add
π οΈ Monitoring in Modern Applications β A Deep Dive with New Relic
In today's fast-paced development world, deploying an application is not the end β maintaining performance, catching bugs, and ensuring uptime are just as critical. This is where Monitoring and tools like New Relic come into play.
In this blog, weβll break down:
π What is Monitoring?
β Why Monitoring Matters?
π§ How to implement it using New Relic
π¦ Real-world examples with code snippets
π What is Monitoring?
Monitoring is the practice of actively observing the health, performance, and availability of an application or system over time.
Monitoring tools help you track:
β API response time
β CPU and memory usage
β Network and I/O performance
β Application errors
β Database query times
β Uptime & downtime events
It answers the questions:
Is my app healthy?
How is it performing in production?
Are users experiencing latency or failure?
π― Why Monitoring Matters
Letβs face it β once your code is live, anything can go wrong.
π§© Purpose | π‘ Description |
π Debugging | Pinpoint where performance drops or errors arise |
π Optimization | Analyze slow database queries or bottlenecked routes |
β οΈ Early Alerts | Get notified before your users complain |
π Security Monitoring | Detect suspicious activity or DDoS attacks |
π Business Insights | Understand user behavior and traffic patterns |
Without monitoring, youβre blind to whatβs happening in real-time production environments.
π§ New Relic β Full Stack Observability
New Relic is a cloud-based observability platform offering Application Performance Monitoring (APM), infrastructure monitoring, logs, alerts, and dashboards, all in one place.
π§ Key Features of New Relic:
Application Performance Monitoring (APM)
Real-Time Metrics
Distributed Tracing
Custom Dashboards
Alerting & Notifications
Logs in Context
Browser & Mobile Monitoring
βοΈ How to Set Up New Relic in a Node.js App
Letβs go through how you can integrate New Relic step-by-step in a Node.js backend.
1οΈβ£ Install New Relic Agent
npm install newrelic
2οΈβ£ Add New Relic Configuration File
Create a file named newrelic.js
in the root of your project.
// newrelic.js
'use strict';
exports.config = {
app_name: ['My Node App'],
license_key: 'YOUR_NEW_RELIC_LICENSE_KEY',
logging: {
level: 'info', // 'trace' for debugging
},
};
Replace YOUR_NEW_RELIC_LICENSE_KEY
with your real New Relic key.
3οΈβ£ Require New Relic at the Start of Your App
In your main entry file (e.g., index.js
or app.js
), require it before anything else:
require('newrelic'); // <- MUST come first
const express = require('express');
const app = express();
4οΈβ£ Start Your App
node app.js
That's it! Your application is now connected to New Relic and sending real-time data.
π What You Can Monitor with New Relic
Once the setup is complete, log in to one.newrelic.com to access:
π¦ Application Monitoring
See all API endpoints
Monitor throughput (requests per minute)
Track error rate and response time
π Distributed Tracing
Trace requests across multiple services (microservices)
Pinpoint latency in complex architectures
π§ Error Analytics
Analyze stack traces
Group and filter by error type
π Infrastructure Monitoring
CPU and memory usage of your container or VM
Disk space, network I/O, etc.
π Alert Policies
Set alerts for:
CPU > 80% for 5 mins
Error rate > 5%
Response time > 1s
And get notified via Slack, Email, PagerDuty, etc.
π§ͺ Example: Monitor High CPU Route
// Simulate a CPU-intensive task
app.get('/cpu', (req, res) => {
let sum = 0;
for (let i = 0; i < 1e7; i++) sum += i;
res.send('Done');
});
With New Relic, this endpoint will be flagged for high latency and CPU usage. You can use that data to optimize performance.
π‘ Best Practices for Monitoring
Monitor both frontend and backend
Set up alerts for critical metrics
Add custom attributes for more context
Enable distributed tracing for microservices
Keep dashboards simple and focused
π Conclusion
Monitoring is not a luxury β itβs a necessity in modern development. It helps you stay ahead of performance issues, reduce downtime, and improve user experience.
Tools like New Relic provide powerful observability for the full stack: backend, frontend, infrastructure, and everything in between.
βIf itβs not monitored, it doesnβt exist.β
π Prometheus vs New Relic β Which Monitoring Tool Should You Use?
When it comes to application monitoring, two tools often appear in the spotlight: New Relic and Prometheus.
They both serve the same core purpose β observability, but their approach, architecture, and target audience are different.
Letβs break down the comparison π
π₯ Prometheus vs New Relic: Key Differences
Feature/Aspect | Prometheus | New Relic |
π¦ Type | Open-source, self-hosted | Managed, commercial SaaS |
π Hosting | You manage it | Fully cloud-hosted |
π Metrics Model | Pull-based (scrapes metrics) | Agent-based, push metrics |
π Data Storage | Time-series database (TSDB) | Proprietary APM backend |
π Dashboards | External via Grafana | Built-in UI and dashboards |
π Alerting | Built-in (Alertmanager) | Rich alerting via UI or APIs |
π΅ Cost | Free & open source | Paid (with free tier) |
π‘ Best for | DevOps, SREs, Kubernetes, custom infra | Full-stack monitoring with ease-of-use focus |
β Why Use Prometheus over New Relic?
Prometheus shines in environments where you need:
Full control over monitoring setup
Kubernetes-native metrics scraping
Custom service-level monitoring
Zero vendor lock-in
No data egress costs (host your own data)
Integration with Grafana, Alertmanager, Pushgateway
Especially for microservices, IoT, self-hosted apps, and DevOps-heavy teams, Prometheus is often the go-to tool.
π What is Prometheus?
Prometheus is an open-source monitoring system with a built-in time-series database. It works by scraping metrics from HTTP endpoints.
π§ Sample Metric Output:
HELP http_requests_total Total number of HTTP requests
TYPE http_requests_total counter
http_requests_total{method="GET", handler="/"} 1256
http_requests_total{method="POST", handler="/login"} 79
Every 15 seconds (default), Prometheus pulls this data and stores it.
π What is Grafana?
Grafana is a powerful open-source visualization layer used with Prometheus. It lets you:
π Create custom dashboards
π Visualize time-series metrics
π¨ Set thresholds and alerts
π€ Share live graphs with teams
π§ Think of Grafana as the UI layer on top of Prometheus.
π How to Set Up Prometheus + Grafana Monitoring (Step-by-Step)
Letβs go step-by-step to monitor a Node.js app using Prometheus + Grafana.
π§± 1. Export Metrics in Your App
Install Prom
npm install prom-client
Add metrics to your server:
const express = require('express');
const client = require('prom-client');
const app = express();
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics();
const counter = new client.Counter({
name: 'node_app_requests_total',
help: 'Total number of requests',
});
app.get('/', (req, res) => {
counter.inc();
res.send('Hello World');
});
// Expose metrics endpoint
app.get('/metrics', async (req, res) => {
res.set('Content-Type', client.register.contentType);
res.end(await client.register.metrics());
});
app.listen(3000, () => console.log('App running on port 3000'));
π‘ 2. Install Prometheus
Download from: https://prometheus.io/download
Then configure prometheus.yml
:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node_app'
static_configs:
- targets: ['localhost:3000']
Run Prometheus:
./prometheus --config.file=prometheus.yml
Visit http://localhost:9090 to see the Prometheus UI.
π 3. Install Grafana and Connect Prometheus
Install Grafana from https://grafana.com/grafana/download
Start Grafana:
./bin/grafana-server
Visit: http://localhost:3000
(Default user/pass: admin/admin
)
Add Prometheus as a data source:
Go to βοΈ Configuration > Data Sources
Choose Prometheus
URL:
http://localhost:9090
Save & Test
Now, you can build dashboards using queries like:
rate(node_app_requests_total[1m])
β¨ Advanced Features You Can Add
π 1. Custom Metrics
Define your own counters, gauges, histograms, or summaries:
const latency = new client.Histogram({
name: 'http_request_duration_seconds',
help: 'Request latency in seconds',
buckets: [0.1, 0.5, 1, 2, 5],
});
π 2. Alertmanager
Use Prometheus' Alertmanager to notify you when conditions are met:
groups:
- name: alert.rules
rules:
- alert: HighRequestRate
expr: rate(node_app_requests_total[1m]) > 100
for: 2m
labels:
severity: warning
annotations:
summary: "High request rate"
Alertmanager can send notifications to:
π© Email
π± Slack
π PagerDuty
π OpsGenie
π 3. Pushgateway
Use when your app canβt be scraped directly (e.g., batch jobs).
Instead of exposing /metrics
, your script pushes data to Prometheus via Pushgateway:
echo "my_job_success 1" | curl --data-binary @- http://localhost:9091/metrics/job/myjob
π 4. Kubernetes Integration
Prometheus has native support for Kubernetes. It can auto-discover pods, services, and labels using annotations:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "3000"
No manual config needed β ideal for dynamic environments!
π Final Thoughts
π’ Use New Relic if:
You want full-stack observability out of the box
Prefer minimal setup
Need frontend + backend + infra in one place
π΅ Use Prometheus + Grafana if:
You want full control and flexibility
You're running microservices or Kubernetes
You prefer open-source and self-hosting
You love to write your own metrics and dashboards
π¬ βPrometheus gives you the building blocks. New Relic gives you the whole building.β
Both are powerful in their own way β choose based on your use case, budget, and team expertise.
Subscribe to my newsletter
Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
