Skip to main content

Command Palette

Search for a command to run...

Getting Started with Prometheus and Grafana

Published
3 min read
M
Full-Stack Developer (React, Next.js, Node.js) | Building modern web apps, SaaS products, and LMS platforms | Sharing code, tutorials & dev insights.

Monitoring is one of the most important parts of running modern applications. Whether you’re managing microservices, Docker containers, or cloud infrastructure, understanding what’s happening inside your system is crucial.

In this blog, we’ll explore Prometheus and Grafana—two of the most popular open-source monitoring tools. By the end, you’ll know how they work, how to set them up, and how to build beautiful dashboards.


🔍 What is Prometheus?

Prometheus is an open-source time-series database and monitoring system. It collects metrics from your applications and stores them so you can analyze performance over time.

Key Features of Prometheus

  • Pull-based scraping model

  • Powerful PromQL query language

  • Alerting support via Alertmanager

  • Easy integration with Kubernetes, Docker, Node.js, Go, Python, etc.

  • Lightweight and high performance


📊 What is Grafana?

Grafana is an open-source visualization and dashboarding tool. It connects with data sources like Prometheus to show beautiful charts, graphs, and alerts.

Why Grafana?

  • Supports 30+ data sources

  • Ready-made dashboard templates

  • Custom alerts

  • Permissions and sharing features

  • Modern and intuitive UI


🧩 How Prometheus and Grafana Work Together

  1. Prometheus scrapes metrics from your app or server.

  2. Metrics get stored in Prometheus as time-series data.

  3. Grafana connects to Prometheus as a data source.

  4. You visualize the metrics using dashboards and graphs.

This combination gives you full monitoring + visualization.


⚙️ Installing Prometheus and Grafana Using Docker

If you want a simple setup, Docker is the easiest way:

1. Create docker-compose.yml

version: '3.7'

services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana
    container_name: grafana
    ports:
      - "3000:3000"

2. Create Prometheus config file (prometheus.yml)

global:
  scrape_interval: 5s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

3. Start services

docker compose up -d

That’s it!
Prometheus → http://localhost:9090
Grafana → http://localhost:3000 (default login: admin / admin)


📈 Adding Prometheus as a Grafana Data Source

  1. Log in to Grafana

  2. Go to Settings → Data Sources

  3. Click Add Data Source

  4. Choose Prometheus

  5. Set URL: http://prometheus:9090 or http://localhost:9090

  6. Save & Test


📌 Creating Dashboards in Grafana

Grafana gives you many ways to visualize data:

  • Line graphs

  • Bar charts

  • Heatmaps

  • Gauges

  • Stat panels

Example: CPU Usage Query (Node Exporter)

rate(node_cpu_seconds_total{mode!="idle"}[5m])

Example: Memory Usage Query

node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100

Once you add a panel, you can customize:

  • Colors

  • Legends

  • Thresholds

  • Refresh intervals


🚨 Setting Up Alerts

You can configure alerts in either:

⚡ Prometheus → Alertmanager
🌈 Grafana → Alert rules inside dashboards

Grafana alerts are easier:

  1. Open a panel

  2. Click Alerts → Create Alert Rule

  3. Set conditions (e.g., CPU > 80%)

  4. Add notification channels (email, Slack, Webhooks)


📦 Exporters You Must Know

Exporters help Prometheus collect metrics. Popular options:

System Metrics

  • Node Exporter → CPU, RAM, disk, network

Containers

  • cAdvisor → Docker container metrics

Databases

  • MySQL Exporter

  • PostgreSQL Exporter

  • Redis Exporter

Applications

  • Node.js Prometheus client

  • Python prometheus_client

  • Go prometheus library


🎯 Final Thoughts

Prometheus + Grafana is the perfect monitoring stack for:

  • DevOps engineers

  • Backend developers

  • Cloud-native apps

  • Kubernetes clusters

  • Self-hosted servers

It’s open-source, powerful, and easy to use once you understand the basics.

If you're building scalable apps, real-time monitoring is not optional—it's essential.