Skip to content

Commit a4e0583

Browse files
Merge pull request #1688 from fluent/alexakreizinger/sc-136150/update-fluent-bit-docs-pipeline-filters-log
2 parents 9e7fc4f + 46c7f34 commit a4e0583

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

pipeline/filters/log_to_metrics.md

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,39 @@ description: Generate metrics from logs
66

77
![](https://static.scarf.sh/a.png?x-pxid=768830f6-8d2d-4231-9e5e-259ce6797ba5)
88

9-
## Log To Metrics
9+
The _log to metrics_ filter lets you generate log-derived metrics. It supports modes to count records, provide a guage for field values, or create a histogram. You can also match or exclude specific records based on regular expression patterns for values or nested values.
1010

11-
The _Log To Metrics Filter_ plugin allows you to generate log-derived metrics. It currently supports modes to count records, provide a gauge for field values or create a histogram. You can also match or exclude specific records based on regular expression patterns for values or nested values. This filter plugin does not actually act as a record filter and does not change or drop records. All records will pass this filter untouched and generated metrics will be emitted into a seperate metric pipeline.
11+
This filter does not actually act as a record filter and therefore does not change or drop records. All records will pass through this filter untouched, and any generated metrics will be emitted into a separate metric pipeline.
1212

13-
_Please note that this plugin is an experimental feature and is not recommended for production use. Configuration parameters and plugin functionality are subject to change without notice._
13+
{% hint style="warning" %}
14+
This filter is an experimental feature and is not recommended for production use. Configuration parameters and other capabilities are subject to change without notice.
15+
{% endhint %}
1416

15-
### Configuration Parameters
17+
## Configuration parameters
1618

1719
The plugin supports the following configuration parameters:
1820

19-
| Key | Description | Mandatory | Value Format |
20-
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
21-
| tag | Defines the tag for the generated metrics record | Yes | |
22-
| metric\_mode | Defines the mode for the metric. Valid values are \[`counter`, `gauge` or `histogram`] | Yes | |
23-
| metric\_name | Sets the name of the metric. | Yes | |
24-
| metric\_description | Sets a help text for the metric. | Yes | |
25-
| bucket | Defines a bucket for `histogram` | Yes, for mode `histogram` | e.g. 0.75 |
26-
| add\_label | Add a custom label NAME and set the value to the value of KEY | | |
27-
| label\_field | Includes a record field as label dimension in the metric. | | Name of record key. Supports [Record Accessor](../../administration/configuring-fluent-bit/classic-mode/record-accessor.md) notation for nested fields. |
28-
| value\_field | Specify the record field that holds a numerical value | Yes, for modes \[`gauge` and `histogram`] | Name of record key. Supports [Record Accessor](../../administration/configuring-fluent-bit/classic-mode/record-accessor.md) notation for nested fields. |
29-
| kubernetes\_mode | If enabled, it will automatically put pod\_id, pod\_name, namespace\_name, docker\_id and container\_name into the metric as labels. This option is intended to be used in combination with the [kubernetes](kubernetes.md) filter plugin, which fills those fields. | | |
30-
| Regex | Include records in which the content of KEY matches the regular expression. | | KEY REGEX |
31-
| Exclude | Exclude records in which the content of KEY matches the regular expression. | | KEY REGEX |
32-
| Flush\_Interval\_Sec | The interval for metrics emission, in seconds. If **Flush\_Interval\_Sec** and **Flush\_Interval\_Nsec** are either both unset or both set to `0`, the filter emits metrics immediately after each filter match. Otherwise, if either parameter is set to a non-zero value, the filter emits metrics at the specified interval. Longer intervals help lower resource consumption in high-load situations. Default value: `0`. | | |
33-
| Flush\_Interval\_Nsec | The interval for metrics emission, in nanoseconds. This parameter works in conjunction with **Flush\_Interval\_Sec**. Default value: `0`. | | |
21+
| Parameter | Description | Value format |
22+
|---|---|---|
23+
| `tag` | Required. Defines the tag for the generated metrics record. | |
24+
| `metric_mode` | Required. Defines the mode for the metric. Valid values are `counter`, `gauge` or `histogram`. | |
25+
| `metric_name` | Required. Sets the name of the metric. | |
26+
| `metric_description` | Required. Sets a description for the metric. | |
27+
| `bucket` | Required for mode `histogram`. Defines a bucket for histograms. | For example, `0.75` |
28+
| `add_label` | Adds a custom label `NAME` and set the value to the value of `KEY`. | |
29+
| `label_field` | Includes a record field as label dimension in the metric. | Name of record key. Supports [record accessor](../administration/configuring-fluent-bit/classic-mode/record-accessor.md) notation for nested fields. |
30+
| `value_field` | Required for modes `gauge` and `histogram`. Specifies the record field that holds a numerical value. | Name of record key. Supports [record accessor](../administration/configuring-fluent-bit/classic-mode/record-accessor.md) notation for nested fields. |
31+
| `kubernetes_mode` | If enabled, adds `pod_id`, `pod_name`, `namespace_name`, `docker_id` and `container_name` to the metric as labels. This option is intended to be used in combination with the [kubernetes](../pipeline/filters/kubernetes.md) filter plugin, which fills those fields. | |
32+
| `Regex` | Includes records in which the content of `KEY` matches the regular expression. | `KEY REGEX` |
33+
| `Exclude` | Excludes records in which the content of `KEY` matches the regular expression. | `KEY REGEX` |
34+
| `Flush_Interval_Sec` | The interval for metrics emission, in seconds. If `Flush_Interval_Sec` and `Flush_Interval_Nsec` are either both unset or both set to `0`, the filter emits metrics immediately after each filter match. Otherwise, if either parameter is set to a non-zero value, the filter emits metrics at the specified interval. Longer intervals help lower resource consumption in high-load situations. Default value: `0`. | |
35+
| `Flush_Interval_Nsec` | The interval for metrics emission, in nanoseconds. This parameter works in conjunction with `Flush_Interval_Sec`. Default value: `0`. | |
3436

35-
### Getting Started
37+
## Examples
3638

37-
The following example takes records from two dummy inputs and counts all messages passing through the `log_to_metrics` filter. It then generates metric records which are provided to the `prometheus_exporter`:
39+
### Counter
3840

39-
#### Configuration - Counter
41+
The following example takes records from two `dummy` inputs and counts all messages that pass through the `log_to_metrics` filter. It then generate metric records, which are provided to the `prometheus_exporter` output:
4042

4143
```python
4244
[SERVICE]
@@ -68,7 +70,7 @@ The following example takes records from two dummy inputs and counts all message
6870
port 2021
6971
```
7072

71-
You can then use e.g. curl command to retrieve the generated metric:
73+
You can then use a tool like curl to retrieve the generated metric:
7274

7375
```
7476
> curl -s http://127.0.0.1:2021/metrics
@@ -79,9 +81,9 @@ You can then use e.g. curl command to retrieve the generated metric:
7981
log_metric_counter_count_all_dummy_messages 49
8082
```
8183

82-
#### Configuration - Gauge
84+
### Gauge
8385

84-
The `gauge` mode needs a `value_field` specified, where the current metric values are generated from. In this example we also apply a regex filter and enable the `kubernetes_mode` option:
86+
The `gauge` mode needs a `value_field` to specify where to generate the metric values from. This example also applies a `regex` filter and enables the `kubernetes_mode` option:
8587

8688
```python
8789
[FILTER]
@@ -99,7 +101,7 @@ The `gauge` mode needs a `value_field` specified, where the current metric value
99101
label_field shape
100102
```
101103

102-
You can then use e.g. curl command to retrieve the generated metric:
104+
You can then use a tool like curl to retrieve the generated metric:
103105

104106
```
105107
> curl -s http://127.0.0.1:2021/metrics
@@ -110,15 +112,15 @@ You can then use e.g. curl command to retrieve the generated metric:
110112
log_metric_gauge_current_duration{namespace_name="default",pod_name="pod1",container_name="mycontainer",docker_id="abc123",pod_id="def456",app="app1",color="blue",shape="square"} 60
111113
```
112114

113-
As you can see in the output, only one line is printed, as the records from the first input plugin are ignored, as they do not match the regex.
115+
In the resulting output, only one line is printed. Records from the first input plugin are ignored because they don't match the regular expression.
114116

115-
The filter also allows to use multiple rules which are applied in order, you can have many _Regex_ and _Exclude_ entries as required (see [grep](grep.md) filter plugin).
117+
This filter also lets you use multiple rules, which are applied in order. You can have as many `regex` and `exclude` entries as required (see [Grep](../pipeline/filters/grep.md) filter plugin).
116118

117-
If you execute the above `curl` command multiple times, you see, that in this example the metric value stays at `60`, as the messages generated by the dummy plugin are not changing. In a real-world scenario the values would change and return the last processed value.
119+
If you execute the example curl command multiple times, the example metric value remains at `60` because the messages generated by the Dummy plugin don't change. In a real-world scenario, the values would change and return to the last processed value.
118120

119-
**Metric label\_values**
121+
#### Metric `label_values`
120122

121-
As you can see, the label sets defined by `add_label` and `label_field` are added to the metric. The lines in the metric represent every combination of labels. Only actually used combinations are displayed here. To see this, you can add a dummy `dummy` input to your configuration.
123+
The label sets defined by `add_label` and `label_field` are added to the metric. The lines in the metric represent every combination of labels. Only combinations that are actualy used are displayed here. To see this, you can add a `dummy` input to your configuration.
122124

123125
The metric output would then look like:
124126

@@ -131,12 +133,11 @@ log_metric_gauge_current_duration{namespace_name="default",pod_name="pod1",conta
131133
log_metric_gauge_current_duration{namespace_name="default",pod_name="pod1",container_name="mycontainer",docker_id="abc123",pod_id="def456",app="app1",color="red",shape="circle"} 20
132134
133135
```
136+
You can also see that all Kubernetes labels have been attached to the metric accordingly.
134137

135-
You can also see, that all the kubernetes labels have been attached to the metric, accordingly.
138+
### Histogram
136139

137-
#### Configuration - Histogram
138-
139-
Similar to the `gauge` mode, `histogram` needs a `value_field` specified, where the current metric values are generated from. In this example we also apply a regex filter and enable the `kubernetes_mode` option:
140+
Similar to the `gauge` mode, the `histogram` mode needs a `value_field` to specify where to generate the metric values from. This example also applies a `regex` filter and enables the `kubernetes_mode` option:
140141

141142
```python
142143
[FILTER]
@@ -154,7 +155,7 @@ Similar to the `gauge` mode, `histogram` needs a `value_field` specified, where
154155
label_field shape
155156
```
156157

157-
You can then use e.g. curl command to retrieve the generated metric:
158+
You can then use a tool like curl to retrieve the generated metric:
158159

159160
```
160161
> curl -s http://127.0.0.1:2021/metrics
@@ -192,7 +193,7 @@ log_metric_histogram_current_duration_sum{namespace_name="default",pod_name="pod
192193
log_metric_histogram_current_duration_count{namespace_name="default",pod_name="pod1",container_name="mycontainer",docker_id="abc123",pod_id="def456",app="app1",color="blue",shape="circle"} 27
193194
```
194195

195-
As you can see in the output, there are per default the buckets `0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0` and `+Inf`, in which values are sorted into. A sum and a counter are also part of this metric. You can specify own buckets in the config, like in the following example:
196+
In the resulting output, there are several buckets by default: `0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0` and `+Inf`. Values are sorted into these buckets. A sum and a counter are also part of this metric. You can specify own buckets in the configuration, like in the following example:
196197

197198
```python
198199
[FILTER]
@@ -217,6 +218,8 @@ As you can see in the output, there are per default the buckets `0.005, 0.01, 0.
217218
label_field shape
218219
```
219220

220-
Please note, that the `+Inf` bucket will always be included implicitly. The buckets in a histogram are cumulative, so a value added to one bucket will add to all larger buckets, too.
221+
{% hint style="info" %}
222+
The `+Inf` bucket will always be included regardless of the buckets you specify. The buckets in a histogram are cumulative, so a value added to one bucket will be added to all larger buckets, too.
223+
{% endhint %}
221224

222225
This filter also attaches Kubernetes labels to each metric, identical to the behavior of `label_field`. This results in two sets for the histogram.

0 commit comments

Comments
 (0)