Skip to content
TheChatArchiveThe Chat Archive
Qwenqwq-32b· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

What is PromQL

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.0-flash-001’s answer.
  1. User

    What is PromQL

  2. Qwen Assistant

    PromQL (Prometheus Query Language) is the domain-specific language used to query and analyze time series data stored in Prometheus, a popular open-source monitoring and alerting system. It is designed to efficiently retrieve, aggregate, and transform metrics for monitoring, alerting, and visualization.


    Key Features of PromQL

    1. Time Series Data Focus:

      • Works with timestamped data (each data point has a value and a timestamp).
      • Metrics are typically labeled (e.g., http_requests_total{method="post", handler="/api/v1"}).
    2. Label-Based Filtering:

      • Filter metrics using labels (e.g., {method="post"} selects metrics with the method label set to post).
      • Exclude labels with without or group by labels with by (e.g., sum by (handler)).
    3. Aggregation Functions:

      • Mathematical: sum, avg, max, min, count, stddev, etc.
      • Rate Calculations: rate() (per-second rate over a time window), irate() (instantaneous rate).
      • Range-Based: increase(), changes(), and absent().
    4. Vector Matching:

      • Combine metrics with matching labels using on() and ignoring() (e.g., A on(instance) + B matches on the instance label).
    5. Operators:

      • Arithmetic: +, -, *, /, ^.
      • Relational: ==, !=, >=, <=, >, <.
      • Logical: and, or, unless.
    6. Range Vectors and Instant Vectors:

      • Instant queries return the latest value (e.g., http_requests_total).
      • Range queries return a series of values over a time window (e.g., http_requests_total[5m] for the last 5 minutes).
    7. Subqueries and Offset:

      • Use offset to shift time series backward (e.g., http_requests_total offset 1h compares to data from an hour ago).

    Basic Syntax Elements

    • Metric Selection:
      metric_name{label1="value1", label2="value2"}
      Example: http_requests_total{method="post"}

    • Aggregation:
      sum(metric_name) by (label)
      Example: sum(rate(http_requests_total[5m])) by (handler)

    • Function Chaining:
      function1(function2(metric))
      Example: rate(http_requests_total[5m]) (calculates per-second rate over 5 minutes).

    • Vector Matching:
      A * on(label) group_left B
      Example: Multiply two metrics by matching on the instance label.


    Common Use Cases

    1. Monitoring:
      up{job="api-server"} == 0 alerts if an API server is down.
    2. Performance Analysis:
      rate(http_requests_total[5m]) shows request rate trends.
    3. Resource Utilization:
      avg(node_cpu{mode="idle"}) by (instance) monitors CPU idle time across instances.
    4. Alerting Rules:
      sum(rate(http_errors_total{job="web"}[5m])) > 10 triggers an alert for high error rates.

    Example Queries

    1. Filter by Labels:
      http_requests_total{method="get", handler="/health"}
    2. Aggregate and Group:
      sum by (handler) (http_requests_total)
    3. Rate of Counters:
      rate(prometheus_http_requests_total[5m])
    4. Comparison with Offset:
      node_load1 - node_load1 offset 1h

    Why PromQL?

    • Efficiency: Optimized for fast queries on large-scale time series data.
    • Flexibility: Combines metrics, labels, and functions to answer complex questions.
    • Integration: Used in Prometheus dashboards (e.g., Grafana), alerts, and alerting rules.

    PromQL is essential for anyone working with Prometheus to extract insights from metrics, set up alerts, and troubleshoot systems.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.