Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions pipeline/filters/type-converter.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
# Type Converter

The _Type Converter Filter_ plugin allows to convert data type and append new key value pair.
The _Type Converter_ filter plugin converts data types and appends new key-value pairs.

<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=8984f540-d95a-462b-8a08-09f72f5fab63" />

This plugin is useful in combination with plugins which expect incoming string value.
e.g. [filter_grep](grep.md), [filter_modify](modify.md)
You can use this filter in combination with plugins which expect incoming string value.
For example, [Grep](grep.md) and [Modify](modify.md).

## Configuration Parameters
## Configuration parameters

The plugin supports the following configuration parameters. It needs four parameters.

`<config_parameter> <src_key_name> <dst_key_name> <dst_data_type>`

_dst_data_type_ allows `int`, `uint`, `float` and `string`.

e.g. `int_key id id_str string`
```text
<config_parameter> <src_key_name> <dst_key_name> <dst_data_type>`
```

`dst_data_type` allows `int`, `uint`, `float`, and `string`. For example, `int_key id id_str string`.

| Key | Description |
| :--- | :--- |
| int_key | This parameter is for integer source.|
| uint_key | This parameter is for unsigned integer source.|
| float_key| This parameter is for float source.|
| str_key | This parameter is for string source.|
| `int_key` | This parameter is for an integer source.|
| `uint_key` | This parameter is for an unsigned integer source.|
| `float_key` | This parameter is for a float source.|
| `str_key` | This parameter is for a string source.|

## Getting Started
## Get started

In order to start filtering records, you can run the filter from the command line or through the configuration file.
To start filtering records, you can run the filter from the command line or through the configuration file.

This is a sample in\_mem record to filter.
This is a sample `in_mem` record to filter.

```text
{"Mem.total"=>1016024, "Mem.used"=>716672, "Mem.free"=>299352, "Swap.total"=>2064380, "Swap.used"=>32656, "Swap.free"=>2031724}
```

The plugin outputs uint values and filter_type_converter converts them into string type.
The plugin outputs `uint` values and `filter_type_converter` converts them into string type.

### Convert uint to string
### Convert `uint` to string

{% tabs %}
{% tab title="fluent-bit.conf" %}

```python
[INPUT]
Name mem
Expand All @@ -56,9 +56,11 @@ The plugin outputs uint values and filter_type_converter converts them into stri
Name stdout
Match *
```

{% endtab %}

{% tab title="fluent-bit.yaml" %}

```yaml
pipeline:
inputs:
Expand All @@ -74,13 +76,14 @@ pipeline:
- name: stdout
match: '*'
```

{% endtab %}
{% endtabs %}

You can also run the filter from command line.

```text
$ fluent-bit -i mem -o stdout -F type_converter -p 'uint_key=Mem.total Mem.total_str string' -p 'uint_key=Mem.used Mem.used_str string' -p 'uint_key=Mem.free Mem.free_str string' -m '*'
```shell
fluent-bit -i mem -o stdout -F type_converter -p 'uint_key=Mem.total Mem.total_str string' -p 'uint_key=Mem.used Mem.used_str string' -p 'uint_key=Mem.free Mem.free_str string' -m '*'
```

The output will be
Expand Down