Prometheus with Grafana from BASIC to ADVANCE level – Complete Prometheus Guide to Master DevOps Infra Monitoring
🔍 Introduction
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:
Windows:
-
Download
.zip
from Prometheus releases -
Extract and run
prometheus.exe
🧾 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:
📊 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:
🧩 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
📺 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:
⚡ 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
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
Post a Comment