Skip to main content

Prometheus with Grafana from BASIC to ADVANCE level – Complete Prometheus Guide to Master DevOps Infra Monitoring

 

🔍 Introduction

Infrastructure monitoring is like the health monitor for your servers, applications, and services. It lets you know when things go wrong before your users do. And if you’re in DevOps, Prometheus and Grafana are the two tools you must master.

In this complete guide, we’ll take you from zero to hero in Prometheus and Grafana — from basic installation to advanced visualization and alerting. Ready to take your DevOps monitoring skills to the next level? Let’s go!


🚀 Getting Started with Prometheus

What is Prometheus?

Prometheus is an open-source systems monitoring and alerting toolkit built originally at SoundCloud. It’s designed for reliability and scalability, making it perfect for dynamic cloud environments.

Core Features

  • A powerful time series database

  • Pull-based model over HTTP

  • PromQL – a flexible query language

  • Integrated Alertmanager

  • Service discovery integrations (Kubernetes, EC2, etc.)

Prometheus Architecture

  • Prometheus Server – scrapes and stores metrics

  • Exporters – expose metrics

  • Pushgateway – for ephemeral jobs

  • Alertmanager – handles alerts

  • Grafana – for visualizing data


🛠️ Installing Prometheus

System Requirements

  • 1-2 GB RAM minimum

  • 2 CPU cores

  • Go or Docker (optional)

Step-by-Step Installation

Linux/macOS:

bash
wget https://github.com/prometheus/prometheus/releases/download/v2.x.x/prometheus-2.x.x.linux-amd64.tar.gz tar -xvf prometheus-2.x.x.linux-amd64.tar.gz cd prometheus-2.x.x.linux-amd64 ./prometheus

Windows:


🧾 Understanding Prometheus Configuration

prometheus.yml File

This is the heart of your Prometheus config. It includes:

  • global config (scrape intervals, timeouts)

  • scrape_configs for job targets

  • Relabel configs

Example:

yaml
scrape_configs: - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100']

📊 Key Concepts in Prometheus

Time Series Data

Prometheus stores data as a time series — a stream of timestamped values belonging to the same metric and label set.

Metric Types

  • Counter: Only increases (e.g., HTTP requests)

  • Gauge: Goes up and down (e.g., memory usage)

  • Histogram/Summary: For latency, durations, etc.


📈 Instrumenting Applications

Use client libraries like:

  • Go: prometheus/client_golang

  • Java: simpleclient

  • Python: prometheus_client

  • Node.js: prom-client

Example in Python:

python
from prometheus_client import start_http_server, Counter c = Counter('http_requests_total', 'Description of counter') start_http_server(8000)

🧩 Exporters in Prometheus

What are Exporters?

Exporters expose metrics on behalf of another system (like MySQL, Redis, etc.)

Popular Exporters

  • Node Exporter – OS metrics

  • Blackbox Exporter – probe endpoints

  • MySQL Exporter

  • Docker, HAProxy, JMX


📣 Alerting with Prometheus

Setting Up Alertmanager

Install and run alertmanager. Configure it in prometheus.yml under alerting.

Creating Alerts

yaml
groups: - name: example rules: - alert: HighCPUUsage expr: node_cpu_seconds_total > 90 for: 1m labels: severity: critical annotations: summary: "High CPU usage detected!"

📺 Introduction to Grafana

Grafana is the UI layer. It connects to Prometheus and turns raw metrics into beautiful, interactive dashboards.


📥 Installing Grafana

  • Download and install from Grafana Downloads

  • Start the server and access at http://localhost:3000


📊 Creating Dashboards

  • Add Prometheus as a data source

  • Create a new dashboard

  • Use PromQL queries to fill panels

Example query:

promql
rate(http_requests_total[5m])

⚡ Advanced Grafana Visualization

  • Use variables to build dynamic dashboards

  • Annotations for marking events

  • Alert rules inside panels


🧪 Real-Time Monitoring Project

Let’s say we want to monitor a Node.js API.

  • Instrument it using prom-client

  • Expose metrics on /metrics

  • Scrape using Prometheus

  • Build a Grafana dashboard with memory, CPU, and request rate

  • Set up alerts to Slack for 5xx errors


📡 Scaling Prometheus

For high-scale environments:

  • Federation: Query one Prometheus from another

  • Remote Storage: Use Cortex, Thanos for long-term storage


🧠 DevOps Monitoring Best Practices

  • Use labels wisely – they are cardinality bombs!

  • Reduce query load – don’t overuse heavy queries

  • Alert with context – use annotations for clarity


✅ Conclusion

Mastering Prometheus and Grafana gives you superpowers in DevOps. You’ll be able to track every part of your infrastructure in real-time, build sleek dashboards, and act on alerts proactively.

This stack is open-source, scalable, and future-proof. So, whether you’re an SRE, DevOps engineer, or just monitoring curious — it’s time to go beyond basic logging and take full control of your infrastructure!


❓ FAQs

Q1: Can I use Prometheus without Grafana?
Yes, but Grafana offers far better visualization than Prometheus' built-in UI.

Q2: Is Prometheus suitable for cloud-native monitoring?
Absolutely! It integrates well with Kubernetes, EC2, and more.

Q3: Can I monitor Windows servers?
Yes, using exporters like windows_exporter.

Q4: Does Prometheus support logs?
No, Prometheus is for metrics. Use Loki for logs.

Q5: What's the best way to scale Prometheus for large infra?
Use Thanos or Cortex for horizontal scaling and long-term storage.

Comments

Popular posts from this blog

Laravel 10 — Build News Portal and Magazine Website (2023)

The digital landscape is ever-evolving, and in 2023, Laravel 10 will emerge as a powerhouse for web development . This article delves into the process of creating a cutting-edge News Portal and Magazine Website using Laravel 10. Let’s embark on this journey, exploring the intricacies of Laravel and the nuances of building a website tailored for news consumption. I. Introduction A. Overview of Laravel 10 Laravel 10 , the latest iteration of the popular PHP framework, brings forth a myriad of features and improvements. From enhanced performance to advanced security measures, Laravel 10 provides developers with a robust platform for crafting dynamic and scalable websites. B. Significance of building a News Portal and Magazine Website in 2023 In an era where information is king, establishing an online presence for news and magazines is more crucial than ever. With the digital audience constantly seeking up-to-the-minute updates, a well-crafted News Portal and Magazine Website beco...

Python Programming Complete Beginners Course Bootcamp 2025

  Introduction to Python Programming Bootcamp 2025 Welcome to the ultimate Python Programming Complete Beginners Course Bootcamp 2025 ! If you've ever wanted to break into the world of coding, this is your golden ticket. Python is not just another programming language — it’s the Swiss Army knife of modern tech. From web development to AI, Python is everywhere. And this bootcamp? It’s designed to take you from zero to hero. Why Python is the Future of Programming Python’s clean syntax and readability make it perfect for beginners. But don’t be fooled by its simplicity — it powers giants like Google, Netflix, and Instagram. As we head into 2025, demand for Python developers is only growing. Who Should Join This Bootcamp? Anyone with a desire to learn! Whether you're a high school student, a working professional switching careers, or just someone curious about code — this course is for you. Getting Started with Python Setting Up Your Environment Before diving into code,...

Creating Twitch Clone - Practical MERN Stack Course 2023

Introduction In today’s digital age, the world of online streaming has taken the entertainment industry by storm. Platforms like Twitch have revolutionized the way people connect, share content, and engage with their audience. If you’ve ever wondered how to create your own streaming platform similar to Twitch, you’re in the right place. In this article, we will explore the practical steps to build a Twitch clone using the MERN (MongoDB, Express, React, Node.js) stack in 2023. What is MERN Stack? MERN Stack Components Before diving into the development process, let’s briefly understand the key components of the MERN stack : 1. MongoDB MongoDB is a NoSQL database that stores data in a flexible, JSON-like format. It is an ideal choice for handling large amounts of unstructured data, making it perfect for storing user profiles, video metadata, and chat logs in our Twitch clone. 2. Express.js Express.js is a web application framework for Node.js. It simplifies the development of robust...