Binary operators
Binary operators combine two expressions. Between vectors, series are matched by label set — the vector matching keywords control exactly how.
Arithmetic operators
Combines two expressions — or an expression and a scalar — with +, -, *, /, %, or ^. Between two vectors, series with identical label sets are matched pairwise; unmatched series drop out of the result.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
A vector expression or scalar literal on either side. |
Example
Compute each Kloudfuse query service’s share of the group’s total goroutines, as a percentage.
sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_name=~".*query-service"})
/ on () group_left ()
sum(go_goroutines{app_kubernetes_io_name=~".*query-service"})
* 100
| app_kubernetes_io_name | Value |
|---|---|
trace-query-service |
3.342 |
events-query-service |
3.296 |
logs-query-service |
21.32 |
rum-query-service |
1.438 |
query-service |
70.6 |
|
Division by zero produces no result for that series rather than an error. Standard precedence applies ( |
Comparison operators
Compares values with ==, !=, >, >=, <, or ⇐. Against a scalar the comparison filters: series that fail the test are dropped — exactly the shape an alert condition needs. The bool modifier keeps every series and returns 1 or 0 instead.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
The threshold, or another vector for pairwise comparison. |
|
Optional |
Return 1/0 per series instead of filtering: |
Example
Keep only the Kloudfuse services currently running more than 100 goroutines.
sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"})
> 100
| app_kubernetes_io_name | Value |
|---|---|
zapper |
2,566 |
kfuse-redis |
584 |
az-service |
1,009 |
logs-query-service |
19,306 |
query-service |
64,236 |
|
Alert rules use this form directly: the alert fires while the filtered result is non-empty. |
Set operators (and, or, unless)
Combines two vectors as sets keyed by label values: and keeps left-side series with a match on the right, or returns the left plus unmatched right-side series, and unless keeps left-side series with no match on the right. Values come from the left side.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
Vector expressions on both sides; matching is by identical label sets. |
Example
List Kloudfuse services' goroutine counts, excluding services that are currently above 500 — unless subtracts the right-hand set.
sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"})
unless
sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"}) > 500
| app_kubernetes_io_name | Value |
|---|---|
recorder |
14 |
archive-writer |
103 |
analytics-service |
11 |
|
|
Vector matching (on, ignoring, group_left)
By default a binary operator matches series whose full label sets are identical. on (labels) restricts matching to the listed labels; ignoring (labels) matches on everything else. When one side has fewer series, group_left / group_right declare the many-to-one direction and can copy labels from the one side.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Optional |
Match series using only these labels. |
|
Optional |
Match series using all labels except these. |
|
Optional |
Allow many-to-one matching; the side named by the modifier is the many side. |
Example
Divide each service’s goroutine count by the all-service total: on () matches every left series to the single right-side series, and group_left () permits the many-to-one pairing.
sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"})
/ on () group_left ()
sum(go_goroutines{app_kubernetes_io_instance="kfuse"})
| app_kubernetes_io_name | Value |
|---|---|
logs-transformer |
0.00696586 |
recorder |
3.63482e-05 |
trace-transformer |
0.2496 |
hydration-service |
0.00142796 |
ingress-nginx |
0.01019 |
|
Without |