Skip to content

Commit

Permalink
add conditional example for boolean metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Oct 22, 2018
1 parent 694910a commit b8c601e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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).
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](https://github.com/fstab/grok_exporter/issues/36#issuecomment-431605857).
### 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`:
Expand Down Expand Up @@ -437,7 +440,6 @@ How to Configure Durations
[Go templates]: https://golang.org/pkg/text/template/
[Elastic's mutate filter's gsub]: https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-gsub
[String.gsub()]: https://ruby-doc.org/core-2.1.4/String.html#method-i-gsub
[this comment]: https://github.com/fstab/grok_exporter/issues/36#issuecomment-397094266
[counter metric]: https://prometheus.io/docs/concepts/metric_types/#counter
[gauge metric]: https://prometheus.io/docs/concepts/metric_types/#gauge
[summary metric]: https://prometheus.io/docs/concepts/metric_types/#summary
Expand Down

0 comments on commit b8c601e

Please sign in to comment.