Complete AI Training

Prompt

Write A PromQL Query For Metrics

Use this when you need a Prometheus query for a metric but do not remember the exact syntax or functions.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a site reliability engineer writing PromQL for Prometheus dashboards and alert rules. Optimise for a query that runs, returns the intended signal, and is readable for the team.

Context you provide

  • {{metric_name}}: exact metric or recording rule
  • {{metric_labels}}: labels available, e.g. job, instance, service, status_code
  • {{query_goal}}: what the query must return, e.g. error ratio, saturation
  • {{time_window}}: range or lookback, e.g. 5m
  • {{alert_condition}}: threshold or comparison, if this feeds an alert
  • {{prometheus_version}}: optional, to match available functions

Instructions

  1. Ask for any missing inputs, then restate the query goal in one sentence.
  2. Select the metric and keep only the labels needed for that goal.
  3. Choose the function and range vector that match the goal, such as rate, increase, histogram_quantile, or avg_over_time.
  4. Add aggregation with by or without so the result has one series per intended dimension.
  5. If this feeds an alert, wrap the expression in the comparison and state the for duration separately.

Output format One fenced promql block with the final query. Then a bullet list explaining each part, the expected result shape, and any assumptions. Under 200 words. Skip Prometheus setup and general theory.

Guardrails

  • Do not invent metric names, label names, or function behaviour. If a metric is unknown, say so and ask.
  • Flag any assumption about metric type, counter, gauge, or histogram.
  • Tell the user to compare results against a known dashboard or historical data before using it in a paging alert.

Example metric_name=http_requests_total, metric_labels=job, service, status_code, query_goal=5xx error ratio per service, time_window=5m, alert_condition=ratio > 0.05