Section 6 · Create an alert with code

When to choose Code mode over Builder, plus a hands-on Path for writing PromQL and creating a silence.

Estimated time: 1 min

Build an alert with the Code mode

You just built an alert in Builder mode. Code mode follows the same rule flow. The difference is how you write the query: you type PromQL instead of picking the metric and operations from menus in the UI.

Use caseRecommended mode
Standard metric, labels, and common operationsBuilder
Complex nested expressions or exact syntax controlCode
Team members new to PromQLBuilder

Start in Builder when you’re learning. Switch to Code when you need more control than Builder can express clearly.

Path

This Path walks you through writing the alert query in PromQL, then creating a silence to suppress notifications during maintenance.

Learning path

First alert rule with query language

Build a Grafana alert rule in Code mode — write a PromQL error-rate query, set a condition, add labels, configure evaluation and notifications, and save.

14 min
Intermediate
Docs & blog posts

Open in Grafana Cloud

Complete this learning path directly in your Grafana Cloud stack with an interactive learning experience.