Skip to content

Commit 109decd

Browse files
committed
Merge pull request #179 from brian-brazil/label-replace
Document label_replace
2 parents b787cee + 451ae47 commit 109decd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

content/docs/querying/functions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ increase(http_requests_total{job="api-server"}[5m])
159159
human readability. Use `rate` in recording rules so that increases are tracked
160160
consistently on a per-second basis.
161161

162+
## `label_replace()`
163+
164+
For each timeseries in `v`, `label_replace(v instant-vector, dst_label string, replacement string,
165+
src_label string, regex string)` matches the regular expression `regex` against
166+
the label `src_label`. If it matches, then the timeseries is returned with the
167+
label `dst_label` replaced by the expansion of `replacement`. `$1` is replaced
168+
with the first matching subgroup, `$2` with the second etc. If the regular
169+
expression doesn't match then the timeseries is not returned.
170+
171+
172+
This example will return a vector with each time series having a `foo`
173+
label with the value `a` added to it:
174+
```
175+
label_replace(up{job="api-server",service="a:c"}, "foo", "$1", "service", "(.*):.*")
176+
```
177+
162178
## `ln()`
163179

164180
`ln(v instant-vector)` calculates the natural logarithm for all elements in `v`.

0 commit comments

Comments
 (0)