Skip to content

Commit d6924d0

Browse files
committed
add conditional example for boolean metrics
1 parent 694910a commit d6924d0

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

CONFIG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,14 @@ Now the Grok field `user` has the value `alice`, and the Grok field `val` has th
210210
* `'user {{.user}} with number {{.val}}.'` -> `user alice with number 1.5.`
211211
* `'{{gsub .user "ali" "beatri"}}'` -> `beatrice`
212212
* `'{{multiply .val 1000}}'` -> `1500`
213+
* `'{{if eq .user "alice"}}1{{else}}0{{end}}'` -> `1`
213214
214215
The syntax of the `gsub` function is `{{gsub input pattern replacement}}`. The pattern and replacement are is similar to [Elastic's mutate filter's gsub] (derived from Ruby's [String.gsub()]), except that you need to double-escape backslashes (\\\\ instead of \\). A more complex example (including capture groups) can be found in [this comment].
215216
216217
The arithmetic functions `add`, `subtract`, `multiply`, and `divide` are straightforward. These functions may not be useful for label values, but they can be useful as the `value:` in [gauge](#gauge-metric-type), [histogram](#histogram-metric-type), or [summary](#summary-metric-type) metrics. For example, they could be used to convert milliseconds to seconds.
217218
219+
Conditionals like `'{{if eq .user "alice"}}1{{else}}0{{end}}` are described in the [Go template] documentation. For example, they can be used to define boolean metrics, i.e. [gauge](#gauge-metric-type) metrics with a value of `1` or `0`. Another example can be found in [this comment].
220+
218221
### Expiring Old Labels
219222
220223
By default, metrics are kept forever. However, sometimes you might want metrics with old labels to expire. There are two ways to do this in `grok_exporter`:

0 commit comments

Comments
 (0)