Monitoring Full Stack Apps with Prometheus and Grafana

When you build a full stack app, your job doesn’t end after writing the code and launching the website. You also need to keep an eye on how your app is working. Is the server running fine? Are there any errors? Is the app too slow? This is where monitoring tools become very helpful.

One of the best ways to monitor your full stack applications is by using Prometheus and Grafana. These tools help you collect, understand, and display the data from your app in real-time. They can show charts, send alerts, and help you fix problems before your users even notice them.

If you are learning web development through full stack developer classes, knowing how to monitor your apps is a very useful skill. It not only makes you a better developer but also helps you understand what happens after your app goes live.

In this blog, we’ll explain what Prometheus and Grafana are, how they work, and how you can use them step by step to monitor a full stack app.

Why Monitoring Is Important

Before we dive into the tools, let’s understand why monitoring is important.

Imagine this:

  • Your app crashes in the middle of the night. 
  • Your website becomes very slow. 
  • A database error causes the signup page to stop working. 

If no one notices, users leave. You lose trust and maybe money. But if you have monitoring set up, you will get alerts when something goes wrong.

Monitoring helps you:

  • Find problems early 
  • Fix issues faster 
  • Keep your app running smoothly 
  • Understand how your app is performing 

That’s why developers and companies use tools like Prometheus and Grafana.

What Is Prometheus?

Prometheus is a tool that collects and stores data about your app. It checks your app again and again and saves information like:

  • CPU usage 
  • Memory usage 
  • Server uptime 
  • Response times 
  • Error rates 

This information is stored in a special database called a time-series database. Each piece of data is saved with the time it was collected.

Prometheus works by scraping data from your app. This means it goes to a specific URL in your app, reads the metrics, and saves them.

What Is Grafana?

Grafana is a tool that shows the data collected by Prometheus. It creates beautiful charts, graphs, and dashboards. It helps you understand what’s happening in your app, just by looking at a screen.

Grafana can also:

  • Send alerts 
  • Create custom dashboards 
  • Show data from many tools (not just Prometheus) 

So Prometheus collects the data, and Grafana shows it in a visual way.

How Prometheus and Grafana Work Together

Here’s how it works:

  1. Your app provides metrics at a URL (like /metrics). 
  2. Prometheus checks that URL every few seconds and saves the data. 
  3. Grafana reads data from Prometheus. 
  4. You see real-time charts and graphs on your dashboard. 
  5. If something goes wrong, Grafana can send you alerts. 

Now let’s see how to set this up step by step.

Step-by-Step: Monitoring a Node.js App

We’ll now set up a simple Node.js app and monitor it using Prometheus and Grafana.

Step 1: Create a Simple Node.js App

First, make a folder and create a simple Express app.

mkdir monitor-app

cd monitor-app

npm init -y

npm install express prom-client

Now, create a file named index.js:

const express = require(‘express’);

const client = require(‘prom-client’);

const app = express();

const register = new client.Registry();

// Create a counter metric

const counter = new client.Counter({

  name: ‘node_request_count’,

  help: ‘Total number of requests’,

});

register.registerMetric(counter);

// Endpoint to expose metrics

app.get(‘/metrics’, async (req, res) => {

  res.set(‘Content-Type’, register.contentType);

  res.end(await register.metrics());

});

// Regular endpoint

app.get(‘/’, (req, res) => {

  counter.inc(); // Count request

  res.send(‘Hello World!’);

});

app.listen(3000, () => {

  console.log(‘App is running on http://localhost:3000’);

});

Run the app:

node index.js

Visit http://localhost:3000/metrics to see the metrics Prometheus can read.

Step 2: Set Up Prometheus

Now install Prometheus. You can download it from prometheus.io.

After installing, create a file named prometheus.yml:

global:

  scrape_interval: 5s

scrape_configs:

  – job_name: ‘node-app’

    static_configs:

      – targets: [‘localhost:3000’]

This file tells Prometheus to scrape data every 5 seconds from our app.

Now run Prometheus:

./prometheus –config.file=prometheus.yml

Go to http://localhost:9090 to see the Prometheus web page.

Step 3: Set Up Grafana

Download Grafana from grafana.com.

After installing, run Grafana:

./bin/grafana-server

Visit http://localhost:3000 (Grafana uses port 3000 too, so change your app’s port if needed).

Login with:

  • Username: admin 
  • Password: admin 

Add Prometheus as a data source in Grafana:

  1. Go to Settings > Data Sources 
  2. Click Add Data Source 
  3. Choose Prometheus 
  4. Enter http://localhost:9090 and save 

Now you can create dashboards!

Step 4: Create a Dashboard

  1. Go to + Create > Dashboard 
  2. Click Add new panel 
  3. In the query box, type: node_request_count 
  4. You’ll see the graph appear 
  5. Click Apply to save it 

Now, every time someone visits your app, the counter goes up. You can see the live data on your Grafana dashboard!

Real-Life Metrics to Track

In real apps, you can track:

  • How fast your API responds 
  • How many users are online 
  • How much memory your app uses 
  • If your database is slow 
  • How many errors happen per hour 

This helps you build better apps and avoid problems.

Alerts and Notifications

Grafana can also send alerts. You can set a rule like:

  • If request time is more than 2 seconds, send an email 

You can get alerts by:

  • Email 
  • Slack 
  • SMS 
  • Telegram 

This helps you react quickly when something is wrong.

Common Problems and Fixes

  • Port conflict: Make sure Prometheus, Grafana, and your app use different ports. 
  • No metrics shown: Check if your app’s /metrics endpoint is working. 
  • Empty dashboard: Wait a few minutes, Prometheus needs time to collect data.

Why Monitoring Helps Full Stack Developers

As a full stack developer, you are responsible for both front end and back end. Monitoring helps you:

  • Make your app faster 
  • Find bugs earlier 
  • Learn how your app behaves in real life 
  • Improve user experience 
  • Work better in a team 

In jobs and interviews, companies love to see that you understand monitoring. It shows you care about quality.

Conclusion

Monitoring is one of the most important skills in full stack development. It helps you keep your app running smoothly and solve problems before users complain.

In this blog, you learned about Prometheus and Grafana, how to use them, and how to monitor a full stack app step by step. You also learned why these tools are helpful and how to create your own dashboard.

If you want to build real-world apps and learn modern developer tools, joining a full stack course can help you a lot. You’ll learn how to use Prometheus, Grafana, Docker, CI/CD, and much more with hands-on guidance.

Start monitoring your apps today, and become a smarter and more reliable developer!

Business Name: ExcelR – Full Stack Developer And Business Analyst Course in Bangalore

Address: 10, 3rd floor, Safeway Plaza, 27th Main Rd, Old Madiwala, Jay Bheema Nagar, 1st Stage, BTM 1st Stage, Bengaluru, Karnataka 560068

Phone: 7353006061

Business Email: [email protected]

Latest Post

FOLLOW US

Related Post