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
-
VictoriaMetrics vmagent Stream Aggregation Rules Design Prompt
Design vmagent stream aggregation rules that pre-aggregate high-cardinality metrics at ingest, cutting stored series while preserving the dimensions your queries need.
-
Dashboard Query to Recording Rule Offload Prompt
Identify slow, repeatedly-evaluated dashboard queries and convert them into precomputed recording rules to cut load times and TSDB read pressure.
-
VictoriaMetrics Cardinality Explorer & TSDB Triage Prompt
Diagnose a VictoriaMetrics cluster suffering from high active time series and churn using the built-in Cardinality Explorer and TSDB status endpoints, then produce a prioritized remediation plan.
-
Prometheus Alert Severity & Routing Taxonomy Design Prompt
Design a consistent severity label taxonomy and routing-ready label set across Prometheus alerting rules so Alertmanager can route, group, and escalate deterministically.
More Prometheus & Monitoring prompts & error guides
Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.
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.