You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `retention_check_interval` is the interval at which `grok_exporter` checks for expired metrics. By default, metrics don't expire so this is relevant only if `retention` is configured explicitly with a metric. The `retention_check_interval` is optional, the value defaults to `53s`. The default value is reasonable for production and should not be changed. This property is intended to be used in tests, where you might not want to wait 53 seconds until an expired metric is cleaned up. The format is described in [How to Configure Durations] below.
55
55
@@ -141,13 +141,17 @@ At least one of `patterns_dir` or `additional_patterns` is required: If `pattern
141
141
Metrics Section
142
142
---------------
143
143
144
+
### Metric Types Overview
145
+
144
146
The metrics section contains a list of metric definitions, specifying how log lines are mapped to Prometheus metrics. Four metric types are supported:
145
147
146
148
* [Counter](#counter-metric-type)
147
149
* [Gauge](#gauge-metric-type)
148
150
* [Histogram](#histogram-metric-type)
149
151
* [Summary](#summary-metric-type)
150
152
153
+
### Example Log Lines
154
+
151
155
To exemplify the different metrics configurations, we use the following example log lines:
152
156
153
157
```
@@ -163,17 +167,19 @@ Each line consists of a date, time, user, and a number. Using [Grok's default pa
163
167
%{DATE} %{TIME} %{USER} %{NUMBER}
164
168
```
165
169
166
-
One of the main features of Prometheus is its multi-dimensional data model: A Prometheus metric can be further partitioned using different labels.
170
+
### Labels
171
+
172
+
One of the main features of Prometheus is its multi-dimensional data model: A Prometheus metric can be further partitioned using labels.
167
173
168
-
Labels are defined in two steps:
174
+
In order to define a label, you need to first define a Grok field name in the `match:` pattern, and second add label template under `labels:`.
169
175
170
176
1. _Define Grok field names._ In Grok, each field, like `%{USER}`, can be given a name, like `%{USER:user}`. The name `user` can then be used in label templates.
171
177
2. _Define label templates._ Each metric type supports `labels`, which is a map of name/template pairs. The name will be used in Prometheus as the label name. The template is a [Go template] that may contain references to Grok fields, like `{{.user}}`.
172
178
173
179
Example: In order to define a label `user` for the example log lines above, use the following fragment:
@@ -182,6 +188,33 @@ The `match` stores whatever matches the `%{USER}` pattern under the Grok field n
182
188
183
189
This simple example shows a one-to-one mapping of a Grok field to a Prometheus label. However, the label definition is pretty flexible: You can combine multiple Grok fields in one label, and you can define constant labels that don't use Grok fields at all.
184
190
191
+
### Label Template Functions
192
+
193
+
Label values are defined as [Go templates]. As of v0.2.6, `grok_exporter` supports the following template functions: `gsub`, `add`, `subtract`, `multiply`, `divide`.
194
+
195
+
For example, let's assume we have the match from above:
We apply this pattern to the first log line of our example:
202
+
203
+
```yaml
204
+
30.07.2016 14:37:03 alice 1.5
205
+
```
206
+
207
+
Now the Grok field `user` has the value `alice`, and the Grok field `val` has the value `1.5`. The following example show how to use these fields as label values using the [Go template] language:
208
+
209
+
* `'{{.user}}'` -> `alice`
210
+
* `'user {{.user}} with number {{.val}}.'` -> `user alice with number 1.5.`
211
+
* `'{{gsub .user "ali" "beatri"}}'` -> `beatrice`
212
+
* `'{{multiply .val 1000}}'` -> `1500`
213
+
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
+
216
+
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.
217
+
185
218
### Expiring Old Labels
186
219
187
220
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