mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
docs :: querying :: functions :: label_replace
Clarify documentation for label_replace() because of ambiguities between label keys and label values. Signed-off-by: Matthew Smedberg <matthew.smedberg@gmail.com>
This commit is contained in:
parent
e36e5fa833
commit
8490273bac
|
@ -272,7 +272,7 @@ For each timeseries in `v`, `label_join(v instant-vector, dst_label string, sepa
|
|||
using `separator` and returns the timeseries with the label `dst_label` containing the joined value.
|
||||
There can be any number of `src_labels` in this function.
|
||||
|
||||
This example will return a vector with each time series having a `foo` label with the value `a,b,c` added to it:
|
||||
This example will return a vector with each time series having a `foo` label added to it, with the value `a,b,c`:
|
||||
|
||||
```
|
||||
label_join(up{job="api-server",src1="a",src2="b",src3="c"}, "foo", ",", "src1", "src2", "src3")
|
||||
|
@ -280,16 +280,14 @@ label_join(up{job="api-server",src1="a",src2="b",src3="c"}, "foo", ",", "src1",
|
|||
|
||||
## `label_replace()`
|
||||
|
||||
For each timeseries in `v`, `label_replace(v instant-vector, dst_label string,
|
||||
replacement string, src_label string, regex string)` matches the regular
|
||||
expression `regex` against the label `src_label`. If it matches, then the
|
||||
timeseries is returned with the label `dst_label` replaced by the expansion of
|
||||
`replacement`. `$1` is replaced with the first matching subgroup, `$2` with the
|
||||
second etc. If the regular expression doesn't match then the timeseries is
|
||||
returned unchanged.
|
||||
For each timeseries in `v`, `label_replace(v instant-vector, dst_label string, replacement string, src_label string, regex string)`
|
||||
matches the regular expression `regex` against the value of the label `src_label`. If it
|
||||
matches, the value of the label `dst_label` in the returned timeseries will be the expansion
|
||||
of `replacement`, together with the original labels in the input. Capturing groups in the
|
||||
regular expression can be referenced with `$1`, `$2`, etc. If the regular expression doesn't
|
||||
match then the timeseries is returned unchanged.
|
||||
|
||||
This example will return a vector with each time series having a `foo`
|
||||
label with the value `a` added to it:
|
||||
This example will return timeseries with the values `a:c` at label `service` and `a` at label `foo`:
|
||||
|
||||
```
|
||||
label_replace(up{job="api-server",service="a:c"}, "foo", "$1", "service", "(.*):.*")
|
||||
|
|
Loading…
Reference in a new issue