乐闻世界logo
搜索文章和话题

What are the common PromQL functions and how to use them?

2月21日 15:39

PromQL (Prometheus Query Language) is the query language for Prometheus, with common functions including:

Aggregation Functions:

  • sum() - Summation
  • avg() - Average
  • max() - Maximum
  • min() - Minimum
  • count() - Count
  • count_values() - Count occurrences of each value

Time Functions:

  • rate() - Calculate average growth rate over a time window
  • irate() - Calculate instantaneous growth rate (more sensitive)
  • increase() - Calculate increment over a time window
  • delta() - Calculate difference

Mathematical Functions:

  • abs() - Absolute value
  • ceil() - Round up
  • floor() - Round down
  • round() - Round to nearest
  • exp() - Exponential
  • ln() - Natural logarithm

Prediction Functions:

  • predict_linear() - Predict future values based on linear regression

Example Queries:

promql
# Calculate QPS rate(http_requests_total[5m]) # Calculate memory usage rate sum(container_memory_usage_bytes) / sum(container_spec_memory_limit_bytes) * 100 # Predict when disk space will run out predict_linear(node_filesystem_avail_bytes[1h], 3600*24) < 0

Notes:

  • rate() and irate() should only be used with Counter types
  • Time window selection affects result accuracy
  • Use by clause for grouped aggregation
标签:Prometheus