Skip to main content

Metric based query

Combine expressions​

In an alert's metric query, you can combine up to five expressions into one query, for example to alert on the ratio of failed requests to all requests.

  1. Build the first expression: select a metric, then add filters and functions.
  2. Select Add expression. A new expression appears below, joined to the one above it by an operator.
  3. Select the operator, then choose Division, Multiplication, Addition, or Subtraction. A new expression starts with Division.
  4. Build the new expression. Repeat to add more expressions, up to five.

To delete an expression, select Remove expression on it. A query always keeps at least one expression.

The builder joins the expressions and operators, from first to last, into a single PromQL query in the form <expression 1> / <expression 2>, and the alert evaluates that query. Standard PromQL rules apply to the result:

  • Operator precedence: Multiplication and division are evaluated before addition and subtraction.
  • Label matching: An operator between two expressions pairs series that have the same labels. Aggregate both expressions by the same labels, for example sum by(service), so that their series match.

In Query mode, each expression has its own PromQL editor, and the operators between them stay in place.

Next steps​

Set up machine-learning-based alerting for your logs in Anomaly detection alerts.

Last updated on