From d6924d03030d89281bbc471c6460c94c4f8d7282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20St=C3=A4ber?= Date: Mon, 22 Oct 2018 15:26:31 +0200 Subject: [PATCH] add conditional example for boolean metrics --- CONFIG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONFIG.md b/CONFIG.md index 25a6c06e..baba3d4a 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -210,11 +210,14 @@ Now the Grok field `user` has the value `alice`, and the Grok field `val` has th * `'user {{.user}} with number {{.val}}.'` -> `user alice with number 1.5.` * `'{{gsub .user "ali" "beatri"}}'` -> `beatrice` * `'{{multiply .val 1000}}'` -> `1500` +* `'{{if eq .user "alice"}}1{{else}}0{{end}}'` -> `1` 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]. 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. +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]. + ### Expiring Old Labels 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`: