PromQL Basics: The Query Language That Changed How I Debug
The Query That Saved Production
histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m]))What Is PromQL?
Your First PromQL Query
Label Selectors: Filtering Data
Exact Match (=)
Negative Match (!=)
Regex Match (=~)
Negative Regex (!~)
Combining Selectors
Range Vectors vs Instant Vectors
Instant Vector
Range Vector
The rate() Function: Your Best Friend
Basic Usage
Why [5m]?
Aggregation Operators
sum() - Total Across All Series
sum() by - Group By Labels
sum() without - Exclude Labels
Other Aggregation Functions
Arithmetic Operators
Basic Arithmetic
Real Example: Error Rate by Endpoint
Comparison Operators
Essential Functions for TypeScript Apps
histogram_quantile() - Percentiles
increase() - Total Increase
irate() - Instant Rate
delta() - Difference for Gauges
deriv() - Derivative
predict_linear() - Trend Prediction
Time Functions
Time Shifting with offset
Useful Queries I Use Daily
1. Request Rate by Endpoint
2. Error Rate Percentage
3. Top 5 Slowest Endpoints
4. Database Query Performance
5. Memory Usage Percentage
6. Active Connections
7. Request Success Rate
8. Traffic Breakdown by Status Code
Debugging Queries
Step 1: Start Simple
Step 2: Add Filters
Step 3: Add Range
Step 4: Add Functions
Step 5: Aggregate
Common Mistakes I Made
1. Using rate() on Gauges
2. Forgetting the Range Vector
3. Short Time Ranges
4. Aggregating Without by/without
Testing Queries in Prometheus UI
PromQL Cheat Sheet
Real Alert Queries
Key Takeaways
PreviousInstrumenting TypeScript Applications: From Zero to Production MetricsNextPrometheus Configuration: From Localhost to Production
Last updated