---
title: "Write your query in Code mode | Grafana Labs"
description: "Switch to Code mode and write a PromQL error-rate query for QuickPizza."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Write your query in Code mode

Your alert watches how often QuickPizza’s server fails. You want it to fire when more than 5 in every 100 requests fail.

You switch to **Code** and write PromQL so the full ratio is one clear expression.

What the query does:

- `quickpizza_server_http_requests_total` counts every request.
- `rate(...[5m])` converts that count to a per-second rate over 5 minutes.
- `{status=~"5.."}` keeps only 5xx failures.
- Dividing failed by all requests, then multiplying by 100, gives a percentage.

<!--THE END-->

1. Choose **grafanacloud-play-prom** as the data source.
2. Click **Code** on the mode toggle.
3. Click **Run queries**.

The query reports QuickPizza’s error rate as a percentage. Next, you set the threshold and recovery while you’re still in this section.
