Skip to content
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
* [OpenTelemetry](pipeline/outputs/opentelemetry.md)
* [Output Formats](pipeline/outputs/output_formats.md)
* [Parseable](pipeline/outputs/parseable.md)
* [Plot](pipeline/outputs/plot.md)
* [PostgreSQL](pipeline/outputs/postgresql.md)
* [Prometheus exporter](pipeline/outputs/prometheus-exporter.md)
* [Prometheus remote write](pipeline/outputs/prometheus-remote-write.md)
Expand Down
131 changes: 131 additions & 0 deletions pipeline/outputs/plot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
description: Generate data file for GNU Plot
---

# Plot

The _Plot_ output plugin generates data files in a format compatible with [GNU Plot](http://www.gnuplot.info/) (gnuplot), a command-line graphing tool. This plugin allows you to export your telemetry data for visualization and analysis using gnuplot.

Check warning on line 7 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Spelling] Spelling check: 'gnuplot'? Raw Output: {"message": "[FluentBit.Spelling] Spelling check: 'gnuplot'?", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 7, "column": 243}}}, "severity": "INFO"}

Check warning on line 7 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.WordList] Use 'lets you' instead of 'allows you to'. Raw Output: {"message": "[FluentBit.WordList] Use 'lets you' instead of 'allows you to'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 7, "column": 165}}}, "severity": "INFO"}

Check warning on line 7 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Spelling] Spelling check: 'gnuplot'? Raw Output: {"message": "[FluentBit.Spelling] Spelling check: 'gnuplot'?", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 7, "column": 113}}}, "severity": "INFO"}

## Configuration parameters

This plugin supports the following parameters:

| Key | Description | Default |
|:--- |:----------- |:------- |
| `File` | Set filename to store the records. If not set, the filename will be the `tag` associated with the records. If the file cannot be opened, the plugin falls back to writing to STDOUT. | _none_ |

Check warning on line 15 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Contractions] Feel free to use 'can't' instead of 'cannot'. Raw Output: {"message": "[FluentBit.Contractions] Feel free to use 'can't' instead of 'cannot'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 15, "column": 131}}}, "severity": "INFO"}
| `Key` | Specify the key name from the record to extract as the value. The value must be a numeric type (integer or float). If not specified, the plugin uses the first field from the record. | _none_ |

## Output format

The Plot output plugin generates data files in a format suitable for gnuplot. The output format is space-separated values with two columns: timestamp and value.

Check warning on line 20 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Spelling] Spelling check: 'gnuplot'? Raw Output: {"message": "[FluentBit.Spelling] Spelling check: 'gnuplot'?", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 20, "column": 70}}}, "severity": "INFO"}

The output format is:

```text
timestamp value
```

Where:
- `timestamp` is a floating-point Unix timestamp
- `value` is the numeric value extracted from the specified key (or the first field if `Key` is not specified)

Check warning on line 30 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Contractions] Feel free to use 'isn't' instead of 'is not'. Raw Output: {"message": "[FluentBit.Contractions] Feel free to use 'isn't' instead of 'is not'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 30, "column": 94}}}, "severity": "INFO"}

The plugin only supports numeric values (integers or floats). If the specified key is not found or the value is not numeric, an error is logged and the record is skipped.

Check warning on line 32 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Contractions] Feel free to use 'isn't' instead of 'is not'. Raw Output: {"message": "[FluentBit.Contractions] Feel free to use 'isn't' instead of 'is not'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 32, "column": 110}}}, "severity": "INFO"}

Check warning on line 32 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Contractions] Feel free to use 'isn't' instead of 'is not'. Raw Output: {"message": "[FluentBit.Contractions] Feel free to use 'isn't' instead of 'is not'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 32, "column": 84}}}, "severity": "INFO"}

## Get started

You can run the plugin from the command line or through the configuration file.

### Command line

From the command line you can generate plot data files with the following options:

```shell
fluent-bit -i cpu -o plot -p file=cpu_data.dat -p key=cpu_p
```

This example extracts the `cpu_p` field from CPU metrics and writes timestamp-value pairs to `cpu_data.dat`.

### Configuration file

In your main configuration file append the following:

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

```yaml
pipeline:
inputs:
- name: cpu
tag: cpu

outputs:
- name: plot
match: '*'
file: cpu_data.dat
key: cpu_p
```

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

```text
[INPUT]
Name cpu
Tag cpu

[OUTPUT]
Name plot
Match *
File cpu_data.dat
Key cpu_p
```

{% endtab %}
{% endtabs %}

## Example usage with gnuplot

Check warning on line 86 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Spelling] Spelling check: 'gnuplot'? Raw Output: {"message": "[FluentBit.Spelling] Spelling check: 'gnuplot'?", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 86, "column": 23}}}, "severity": "INFO"}

After generating the data file with Fluent Bit, you can use gnuplot to visualize the data:

Check warning on line 88 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Spelling] Spelling check: 'gnuplot'? Raw Output: {"message": "[FluentBit.Spelling] Spelling check: 'gnuplot'?", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 88, "column": 61}}}, "severity": "INFO"}

1. Generate the data file:

```shell
fluent-bit -i cpu -o plot -p file=cpu_data.dat -p key=cpu_p -f 1
```

This command collects CPU metrics, extracts the `cpu_p` field (CPU percentage), and writes timestamp-value pairs to `cpu_data.dat`. The output file will contain lines like:

```text
1704067200.123456 25.5
1704067201.123456 30.2
1704067202.123456 28.7
```

2. Create a gnuplot script (e.g., `plot.gp`):

Check failure on line 104 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Latin] Use 'for example' instead of 'e.g.,'. Raw Output: {"message": "[FluentBit.Latin] Use 'for example' instead of 'e.g.,'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 104, "column": 29}}}, "severity": "ERROR"}

```text
set terminal png
set output "cpu_usage.png"
set xlabel "Time"
set ylabel "CPU Usage (%)"
set xdata time
set timefmt "%s"
set format x "%H:%M:%S"
plot "cpu_data.dat" using 1:2 with lines title "CPU Usage"
```

3. Run gnuplot:

```shell
gnuplot plot.gp
```

This will generate a PNG image file showing the CPU usage over time.

## Notes

- The `Key` parameter is optional. If not specified, the plugin uses the first field from the record.
- Only numeric values (integers or floats) are supported. Non-numeric values will cause the record to be skipped with an error logged.
- If the specified `Key` is not found in a record, an error is logged and that record is skipped.
- If the output file cannot be opened (e.g., due to permissions), the plugin automatically falls back to writing to STDOUT.

Check failure on line 130 in pipeline/outputs/plot.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [FluentBit.Latin] Use 'for example' instead of 'e.g.,'. Raw Output: {"message": "[FluentBit.Latin] Use 'for example' instead of 'e.g.,'.", "location": {"path": "pipeline/outputs/plot.md", "range": {"start": {"line": 130, "column": 40}}}, "severity": "ERROR"}
- The output file is opened in append mode, so new data is added to existing files.
Loading