Arithmetic functions

Arithmetic functions apply a mathematical operation to every sample value of the input vector, preserving all labels.

abs

Applies abs to every sample value of the input vector, preserving all labels. Absolute value of every sample.

Syntax

abs(<expr>)
none

Example

Measure how far the query-service goroutine count moved in 30 minutes, regardless of direction.

abs(delta(go_goroutines{app_kubernetes_io_name="query-service"}[30m]))
Expected output
Value

1.678

1.119

0

0.3051

0.6102

ceil

Applies ceil to every sample value of the input vector, preserving all labels. Rounds every sample up to the nearest integer.

Syntax

ceil(<expr>)
none

Example

Round the Kloudfuse goroutine total up to the next thousand.

ceil(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}) / 1000)
Expected output
Value

386

clamp_max

Applies clamp_max to every sample value of the input vector, preserving all labels. Limits every sample to a maximum.

Syntax

clamp_max(<expr>, <max>)
none

Example

Cap the Kloudfuse goroutine total at 10,000.

clamp_max(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}), 10000)
Expected output
Value

10,000

clamp_min

Applies clamp_min to every sample value of the input vector, preserving all labels. Limits every sample to a minimum.

Syntax

clamp_min(<expr>, <min>)
none

Example

Treat any decrease in goroutines as zero, keeping only growth.

clamp_min(delta(go_goroutines{app_kubernetes_io_name="query-service"}[30m]), 0)
Expected output
Value

0.5085

0

0

0.05085

0

clamp

Applies clamp to every sample value of the input vector, preserving all labels. Limits every sample to a min–max range.

Syntax

clamp(<expr>, <min>, <max>)
none

Example

Cap the Kloudfuse goroutine total at 10,000 and floor it at 0 — outliers no longer stretch the chart axis.

clamp(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}), 0, 10000)
Expected output
Value

10,000

exp

Applies exp to every sample value of the input vector, preserving all labels. e raised to each sample value.

Syntax

exp(<expr>)
none

Example

Compute e^1 — the result is Euler’s number, ≈ 2.718.

exp(vector(1))
Expected output
Value

2.718

floor

Applies floor to every sample value of the input vector, preserving all labels. Rounds every sample down to the nearest integer.

Syntax

floor(<expr>)
none

Example

Round the Kloudfuse goroutine total down to the previous thousand.

floor(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}) / 1000)
Expected output
Value

385

ln

Applies ln to every sample value of the input vector, preserving all labels. Natural logarithm of every sample.

Syntax

ln(<expr>)
none

Example

Take the natural log of the Kloudfuse goroutine total — useful for charting values that span orders of magnitude.

ln(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}))
Expected output
Value

12.86

log10

Applies log10 to every sample value of the input vector, preserving all labels. Base-10 logarithm of every sample.

Syntax

log10(<expr>)
none

Example

Find the order of magnitude of the Kloudfuse goroutine total.

log10(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}))
Expected output
Value

5.585

log2

Applies log2 to every sample value of the input vector, preserving all labels. Base-2 logarithm of every sample.

Syntax

log2(<expr>)
none

Example

Compute log2(1024) — the result is 10.

log2(vector(1024))
Expected output
Value

10

round

Applies round to every sample value of the input vector, preserving all labels. Rounds every sample to the nearest multiple.

Syntax

round(<expr> [, <to-nearest>])
none

Example

Round the Kloudfuse goroutine total to the nearest hundred.

round(sum(go_goroutines{app_kubernetes_io_instance="kfuse"}), 100)
Expected output
Value

385,100

sgn

Applies sgn to every sample value of the input vector, preserving all labels. Sign of every sample: -1, 0, or 1.

Syntax

sgn(<expr>)
none

Example

Reduce the 30-minute goroutine trend to its direction: growing (1), flat (0), or shrinking (-1).

sgn(delta(go_goroutines{app_kubernetes_io_name="query-service"}[30m]))
Expected output
Value

-1

1

1

-1

-1

sqrt

Applies sqrt to every sample value of the input vector, preserving all labels. Square root of every sample.

Syntax

sqrt(<expr>)
none

Example

Compute the square root of 256 — the result is 16.

sqrt(vector(256))
Expected output
Value

16