Introduction to Prometheus and PromQL

Modern systems generate tons of metrics — CPU usage, memory consumption, request rates, error counts, latency, and much more. To monitor and analyze all of this efficiently, developers and DevOps engineers often rely on Prometheus, one of the most popular open-source monitoring and alerting tools.
In this blog, we’ll introduce Prometheus, set it up quickly, and walk through PromQL, the query language that makes Prometheus powerful.
What is Prometheus?
Prometheus is an open-source monitoring and alerting system originally built at SoundCloud. It has become the de facto standard for monitoring cloud-native environments like Kubernetes.
Key features of Prometheus:
Time-series database – stores metrics as time-stamped data.
Pull model – Prometheus scrapes (pulls) metrics from exporters or instrumented apps.
Powerful query language (PromQL) – allows flexible analysis of metrics.
Alertmanager – for handling alerts based on rules.
Rich ecosystem – exporters exist for databases, OS metrics, Kubernetes, and more.
Getting Started with Prometheus
Step 1: Install Prometheus
You can download Prometheus directly:
wget https://github.com/prometheus/prometheus/releases/download/v2.54.1/prometheus-2.54.1.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*/
Step 2: Run Prometheus
./prometheus --config.file=prometheus.yml
By default, it starts on port 9090. Open http://localhost:9090 to see the UI.
Step 3: Configure Targets
In prometheus.yml
, you can define scraping targets:
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
Here, Prometheus scrapes metrics from Node Exporter running on port 9100
.
Introduction to PromQL
PromQL (Prometheus Query Language) is what makes Prometheus special. It allows you to query, aggregate, and visualize metrics.
Basic PromQL Examples
Instant Vector – Current CPU usage
node_cpu_seconds_total
Shows the raw CPU seconds counter.
Rate of CPU usage per second
rate(node_cpu_seconds_total[5m])
Calculates the per-second average increase over the last 5 minutes.
Average CPU usage across all cores
avg(rate(node_cpu_seconds_total[5m])) by (instance)
Memory Usage
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes
Gives memory utilization ratio.
HTTP Request Rate
rate(http_requests_total[1m])
Requests per second averaged over 1 minute.
Visualizing Metrics
Prometheus comes with a basic graph UI, but it’s often paired with Grafana to create rich dashboards. Using PromQL queries inside Grafana, you can build interactive monitoring dashboards.
Alerts with Prometheus
Example alert rule (in alert.rules.yml
):
groups:
- name: example
rules:
- alert: HighCPUUsage
expr: avg(rate(node_cpu_seconds_total[5m])) > 0.9
for: 2m
labels:
severity: warning
annotations:
summary: "CPU usage is very high"
This triggers an alert if CPU usage is over 90% for more than 2 minutes.
Conclusion
Prometheus provides a powerful and flexible monitoring solution for modern infrastructure. Its pull-based architecture, time-series database, and PromQL make it ideal for monitoring microservices, Kubernetes clusters, or traditional servers.
By mastering PromQL, you unlock the real power of Prometheus, enabling you to query, visualize, and alert on any metric your systems expose.
Comments (1)
- AAbhishek Kumar•Nice post abhigyan.