Using PromQL to Analyze CPU, Memory, and Network Metrics Effectively

August 12, 2025 · prometheus, promql, monitoring, infrastructure, devops, grafana, observability

If you’ve ever stared at a Grafana dashboard wondering why your server’s CPU is spiking like a caffeinated squirrel, you’re not alone. Prometheus and PromQL are my go-to tools for making sense of infrastructure metrics—once you get the hang of them, they’re like having X-ray vision for your systems.

In this guide, I’ll walk you through writing effective PromQL queries to monitor CPU, memory, and network performance. Whether you’re debugging a mysterious latency issue or just keeping an eye on resource usage, these tips will save you hours of head-scratching.


What You’ll Need

Before diving into PromQL, make sure you have:


Step 1: Understanding CPU Metrics

CPU usage is a goldmine for spotting performance bottlenecks. Let’s break down the key metrics:

Key CPU Metrics in Prometheus

Example Query: CPU Utilization by Mode

100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

This query shows CPU usage as a percentage, excluding idle time.

Pro Tip: Use mode="user" to isolate application load or mode="system" for kernel overhead.


Step 2: Memory Usage Analysis

Memory leaks are like uninvited houseguests—they hog resources until everything grinds to a halt. Here’s how to track them:

Key Memory Metrics

Example Query: Memory Usage Percentage

(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100

This gives a realistic view of used memory, accounting for buffers/caches.

Troubleshooting: If MemAvailable is low but Cached is high, your system might just be efficiently using RAM—don’t panic!


Step 3: Network Traffic Monitoring

Network issues can be sneaky. PromQL helps you catch bottlenecks before users complain.

Key Network Metrics

Example Query: Network Throughput (Bytes/sec)

rate(node_network_receive_bytes_total{device="eth0"}[1m]) * 8

Multiply by 8 to convert bytes to bits (useful for bandwidth monitoring).

Gotcha: Filter by device to avoid aggregating loopback/virtual interfaces.


Advanced PromQL Tips

  1. Use sum() Sparingly: Aggregating across all instances can hide outliers. Try by (instance) first.
  2. Label Manipulation: Rename confusing labels with label_replace().
    label_replace(rate(node_cpu_seconds_total[5m]), "cpu_core", "$1", "cpu", "(.*)")
    
  3. Avoid Thundering Herds: Long ranges ([30m]) smooth spikes but delay alerts.

Troubleshooting Common Issues


FAQ

Q: Why is my CPU query showing >100%?

A: You’re likely summing across cores. Use avg instead of sum for percentages.

Q: How do I monitor disk I/O with PromQL?

A: Use node_disk_io_time_seconds_total and rate(). Here’s a full guide.

Q: Can I alert on PromQL results?

A: Absolutely! Grafana alerts or Prometheus’s ALERTS metric work great.


Wrapping Up

PromQL turns raw metrics into actionable insights—whether you’re optimizing a smart home server or a cloud cluster. Start with these queries, tweak them for your use case, and soon you’ll be diagnosing issues like a pro.

For more, check out my posts on Grafana alerting or Zigbee2MQTT monitoring.

Got a PromQL headache? Drop a comment below—I’ve probably been there too!

Building something like this in production?

I help teams turn setups like this into reliable, monitored infrastructure.

Get a free consulting call

Get my monitoring stack checklist

The exact checklist I use when setting up observability for a new team. No spam, unsubscribe anytime.