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...

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

Learn how to create a stunning news portal and magazine website in 2023 with Laravel 10 . Follow this comprehensive guide for expert insights, step-by-step instructions, and creative tips. Introduction In the dynamic world of online media, a powerful content management system is the backbone of any successful news portal or magazine website. Laravel 10, the latest iteration of this exceptional PHP framework, offers a robust platform to build your digital empire. In this article, we will dive deep into the world of Laravel 10 , exploring how to create a news portal and magazine website that stands out in 2023. Laravel 10 — Build News Portal and Magazine Website (2023) News websites are constantly evolving, and Laravel 10 empowers you with the tools and features you need to stay ahead of the game. Let’s embark on this journey and uncover the secrets of building a successful news portal and magazine website in the digital age. Understanding Laravel 10 Laravel 10 , the most recent vers...

Google Ads MasterClass 2024 - All Campaign Builds & Features

  Introduction to Google Ads in 2024 Google Ads has evolved tremendously over the years, and 2024 is no different. Whether you are a small business owner, a marketer, or someone looking to grow their online presence, Google Ads is an essential tool in today’s digital landscape. What Is Google Ads? Google Ads is a powerful online advertising platform that allows businesses to reach potential customers through search engines, websites, and even YouTube. It gives businesses the ability to advertise their products or services precisely where their audience is spending their time. From local businesses to global enterprises, Google Ads helps companies of all sizes maximize their online visibility. The Importance of Google Ads for Modern Businesses In 2024, online competition is fiercer than ever. Businesses need to stand out, and Google Ads offers a way to do that. With the platform's variety of ad formats and targeting options, you can reach people actively searching for your product ...