DevTools Logo

PromQL Builder & Validator

PromQL Builder & Validator

Compose Prometheus queries and alert rules, and check PromQL syntax and argument types, in your browser.

Runs in your browser
Try an example

Query options

Generated PromQL

instant vector
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))
What this check does not cover
  • Whether the metrics and labels exist in your Prometheus
  • Exact RE2 regex syntax in =~ and !~ matchers (a JavaScript regex is used as a stand-in)
  • Quoted UTF-8 metric and label names (Prometheus 3)
  • Experimental or very recent functions that are not in the built-in table
  • Evaluation behaviour: vector matching cardinality, staleness, step alignment

About

Compose PromQL locally with rate, irate, increase, histogram_quantile, by/without grouping, offsets, and range selectors. Generate deterministic Prometheus alert rule YAML and catch unbalanced parentheses, unknown functions, and common rate mistakes without uploading data.

Examples

p95 latency from buckets

Input
buildPromQL({ metric: "http_request_duration_seconds_bucket", fn: "rate", range: "5m", grouping: "by", groupLabels: ["le"], histogramQuantile: 0.95 })
Output
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))

Rate over 5m, summed by le, then histogram_quantile extracts the 95th percentile.

Offset comparison query

Input
buildPromQL({ metric: "http_requests_total", fn: "rate", range: "5m", offset: "1h" })
Output
rate(http_requests_total[5m] offset 1h)

The offset modifier compares current throughput against the same range one hour ago.

About this tool

PromQL Builder & Validator composes queries with buildPromQL(config): labels attach as {k="v"} with backslash/quote escaping, fn wraps the metric with an optional [range] and offset modifier, grouping wraps it as sum by/without (labels) (...), and histogramQuantile wraps the whole expression — the canonical histogram_quantile(0.95, sum by (le) (rate(metric[5m]))) falls out of one call.

Validation with validatePromQL(source) is a deterministic local lint: empty input fails, unbalanced opening/closing parens report as errors, unknown function names (anything outside rate/irate/increase/histogram_quantile/sum/avg/min/max/count/quantile/topk/bottomk) report Unknown function, range-less rate/irate/increase calls error, and counter-shaped rate calls add a warning. generateAlertRuleYaml then emits a sorted, single-quoted groups/rules document.

Grouping modifiers differ semantically — sum by (job) keeps only job while sum without (job) drops only job — and offset shifts the evaluation instant (e.g. offset 1h). Duration helpers accept ms/s/m/h/d/w/y compounds via isPromQLDuration; nothing is sent anywhere, so queries stay in the browser.

How to use this tool

  1. Pick the metric and range function

    Enter the metric name, add label matchers, then wrap with rate/irate/increase plus a range like 5m — offsets like 1h shift the instant.

  2. Aggregate and quantize

    Choose sum by or sum without with group labels, and set histogramQuantile 0.95 on _bucket metrics for latency percentiles.

  3. Validate, then export the alert

    Run the validator to catch parens, unknown functions, and missing ranges, then generate the alert-rule YAML for Prometheus.

Use cases

Building latency SLO queries

Compose histogram_quantile percentiles over bucket metrics for p50/p95/p99 dashboards and alerts.

Linting pasted PromQL

Catch unbalanced parens, misspelled functions, and range-less rate calls before saving rules.

Scaffolding alert rules

Turn validated expressions into quoted Prometheus group YAML with for/labels/annotations intact.

Common mistakes

Mistake:Calling rate without a range vector.

Fix:rate(up) errors with rate, irate, and increase need a range vector — write rate(up[5m]) instead.

Mistake:Confusing by with without.

Fix:sum by (job) keeps only job; sum without (job) keeps everything except job — swapping them inverts the aggregation.

Mistake:Assuming unknown functions warn only.

Fix:frobnicate(up) is an error-severity Unknown function finding that flips valid to false — fix the name before deploying.

Frequently asked questions

What does this tool do?

It composes PromQL with buildPromQL (labels, range function, offset, by/without aggregation, histogram_quantile), lints with validatePromQL (empty, parens, unknown functions, missing ranges), and exports alert YAML with generateAlertRuleYaml.

What is the canonical histogram query, and how do by/without differ?

histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m]))). sum by (job) keeps only job; sum without (job) keeps everything except job — swapping them inverts the aggregation.

Is my query uploaded or stored?

No. Building, validation, and YAML export are 100% client-side — metrics and expressions never leave your browser.

What fails validation?

Empty queries, unbalanced parens, unknown functions like frobnicate (error severity), and range-less rate/irate/increase calls such as rate(up). Counter-shaped rate calls add a warning to verify the metric type.

References & standards