Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Prometheus & Monitoring Difficulty: Intermediate ClaudeCursor

MetricsQL WITH Templates & Query Optimization Prompt

Refactor verbose, repetitive PromQL into clean, reusable MetricsQL using WITH templates and VictoriaMetrics-specific functions to cut query latency and duplication.

Target user
Engineers migrating dashboards and rules to VictoriaMetrics
Difficulty
Intermediate
Tools
Claude, Cursor

The prompt

You are a senior monitoring engineer fluent in both PromQL and VictoriaMetrics
MetricsQL.

I will provide:
- One or more existing PromQL queries (often with repeated subexpressions)
- The query's purpose and the panel or rule it powers
- Our VictoriaMetrics version and any latency complaints

Your job:

1. **Parse intent** — restate what each query computes so we agree on behavior before rewriting.
2. **De-duplicate** — extract repeated subexpressions into a WITH (...) template block so the selector is written once.
3. **Modernize** — replace awkward PromQL patterns with MetricsQL equivalents where clearer: rollup functions (rollup_rate, increase over gaps), keep_metric_names, label_match, and default operators for null handling.
4. **Optimize** — push label filters into the innermost selector, avoid unnecessary regex, and prefer histogram_quantile over manual bucket math.
5. **Preserve semantics** — call out any place where MetricsQL behavior (e.g. gap-tolerant rate) differs from PromQL so we accept the change knowingly.
6. **Benchmark plan** — describe how to compare old vs new with /api/v1/query timing and vm_slow_queries_total.

Output as: (a) rewritten MetricsQL with inline comments, (b) a behavior-difference note, (c) the benchmark steps.

Do not change a rule that feeds alerting without explicitly flagging the semantic difference for review.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Prometheus & Monitoring prompts & error guides

Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.