Skip to content

Commit b8c601e

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

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CONFIG.md

Lines changed: 4 additions & 2 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
214-
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].
215+
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](https://github.com/fstab/grok_exporter/issues/36#issuecomment-397094266).
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](https://github.com/fstab/grok_exporter/issues/36#issuecomment-431605857).
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`:
@@ -437,7 +440,6 @@ How to Configure Durations
437440
[Go templates]: https://golang.org/pkg/text/template/
438441
[Elastic's mutate filter's gsub]: https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-gsub
439442
[String.gsub()]: https://ruby-doc.org/core-2.1.4/String.html#method-i-gsub
440-
[this comment]: https://github.com/fstab/grok_exporter/issues/36#issuecomment-397094266
441443
[counter metric]: https://prometheus.io/docs/concepts/metric_types/#counter
442444
[gauge metric]: https://prometheus.io/docs/concepts/metric_types/#gauge
443445
[summary metric]: https://prometheus.io/docs/concepts/metric_types/#summary

0 commit comments

Comments
 (0)