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

Lav kushwahaLav kushwaha
8 min read

πŸ› οΈ 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
🐞 DebuggingPinpoint where performance drops or errors arise
πŸ“ˆ OptimizationAnalyze slow database queries or bottlenecked routes
⚠️ Early AlertsGet notified before your users complain
πŸ” Security MonitoringDetect suspicious activity or DDoS attacks
πŸ“Š Business InsightsUnderstand 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/AspectPrometheusNew Relic
πŸ“¦ TypeOpen-source, self-hostedManaged, commercial SaaS
🌐 HostingYou manage itFully cloud-hosted
πŸ“Š Metrics ModelPull-based (scrapes metrics)Agent-based, push metrics
πŸ“ Data StorageTime-series database (TSDB)Proprietary APM backend
πŸ“‰ DashboardsExternal via GrafanaBuilt-in UI and dashboards
πŸ”” AlertingBuilt-in (Alertmanager)Rich alerting via UI or APIs
πŸ’΅ CostFree & open sourcePaid (with free tier)
πŸ’‘ Best forDevOps, SREs, Kubernetes, custom infraFull-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.

0
Subscribe to my newsletter

Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lav kushwaha
Lav kushwaha