Skip to content

Commit 4f1187d

Browse files
committed
Adding YAML examples, formatting table, and cleaning up shell usage for WebSocket output plugin doc. Part of issue #1941.
Signed-off-by: Eric D. Schabell <[email protected]>
1 parent 4ccf56b commit 4f1187d

File tree

1 file changed

+97
-52
lines changed

1 file changed

+97
-52
lines changed

pipeline/outputs/websocket.md

Lines changed: 97 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# WebSocket
22

3-
The **websocket** output plugin allows to flush your records into a WebSocket endpoint. For now the functionality is pretty basic and it issues a HTTP GET request to do the handshake, and then use TCP connections to send the data records in either JSON or [MessagePack](http://msgpack.org) \(or JSON\) format.
3+
The **websocket** output plugin allows to flush your records into a WebSocket endpoint. For now the functionality is pretty basic, and it issues an HTTP GET request to do the handshake, and then use TCP connections to send the data records in either JSON or [MessagePack](http://msgpack.org) \(or JSON\) format.
44

55
## Configuration Parameters
66

7-
| Key | Description | default |
8-
| :--- | :--- | :--- |
9-
| Host | IP address or hostname of the target WebSocket Server | 127.0.0.1 |
10-
| Port | TCP port of the target WebSocket Server | 80 |
11-
| URI | Specify an optional HTTP URI for the target websocket server, e.g: /something | / |
12-
| Header | Add a HTTP header key/value pair. Multiple headers can be set. | |
13-
| Format | Specify the data format to be used in the HTTP request body, by default it uses _msgpack_. Other supported formats are _json_, _json\_stream_ and _json\_lines_ and _gelf_. | msgpack |
14-
| json\_date\_key | Specify the name of the date field in output | date |
15-
| json\_date\_format | Specify the format of the date. Supported formats are _double_, _epoch_, _iso8601_ (eg: _2018-05-30T09:39:52.000681Z_) and _java_sql_timestamp_ (eg: _2018-05-30 09:39:52.000681_) | double |
16-
| workers | The number of [workers](../../administration/multithreading.md#outputs) to perform flush operations for this output. | `0` |
7+
| Key | Description | default |
8+
|:-------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------|
9+
| Host | IP address or hostname of the target WebSocket Server | 127.0.0.1 |
10+
| Port | TCP port of the target WebSocket Server | 80 |
11+
| URI | Specify an optional HTTP URI for the target websocket server, e.g: /something | / |
12+
| Header | Add a HTTP header key/value pair. Multiple headers can be set. | |
13+
| Format | Specify the data format to be used in the HTTP request body, by default it uses _msgpack_. Other supported formats are _json_, _json\_stream_ and _json\_lines_ and _gelf_. | msgpack |
14+
| json\_date\_key | Specify the name of the date field in output | date |
15+
| json\_date\_format | Specify the format of the date. Supported formats are _double_, _epoch_, _iso8601_ (eg: _2018-05-30T09:39:52.000681Z_) and _java_sql_timestamp_ (eg: _2018-05-30 09:39:52.000681_) | double |
16+
| workers | The number of [workers](../../administration/multithreading.md#outputs) to perform flush operations for this output. | `0` |
1717

1818
## Getting Started
1919

20-
In order to insert records into a HTTP server, you can run the plugin from the command line or through the configuration file:
20+
In order to insert records into an HTTP server, you can run the plugin from the command line or through the configuration file:
2121

2222
### Command Line
2323

@@ -29,74 +29,118 @@ http://host:port/something
2929

3030
Using the format specified, you could start Fluent Bit through:
3131

32-
```text
32+
```shell
3333
fluent-bit -i cpu -t cpu -o websocket://192.168.2.3:80/something -m '*'
3434
```
3535

3636
### Configuration File
3737

38-
In your main configuration file, append the following _Input_ & _Output_ sections:
38+
In your main configuration file, append the following:
39+
40+
{% tabs %}
41+
{% tab title="fluent-bit.yaml" %}
42+
43+
```yaml
44+
pipeline:
45+
inputs:
46+
- name: cpu
47+
tag: cpu
48+
49+
outputs:
50+
- name: websocket
51+
match: '*'
52+
host: 192.168.2.3
53+
port: 80
54+
uri: /something
55+
format: json
56+
```
57+
58+
{% endtab %}
59+
{% tab title="fluent-bit.conf" %}
3960
40-
```python
61+
```text
4162
[INPUT]
42-
Name cpu
43-
Tag cpu
63+
Name cpu
64+
Tag cpu
4465

4566
[OUTPUT]
46-
Name websocket
47-
Match *
48-
Host 192.168.2.3
49-
Port 80
50-
URI /something
51-
Format json
67+
Name websocket
68+
Match *
69+
Host 192.168.2.3
70+
Port 80
71+
URI /something
72+
Format json
5273
```
5374

54-
Websocket plugin is working with tcp keepalive mode, please refer to [networking](https://docs.fluentbit.io/manual/v/master/administration/networking#configuration-options) section for details. Since websocket is a stateful plugin, it will decide when to send out handshake to server side, for example when plugin just begins to work or after connection with server has been dropped. In general, the interval to init a new websocket handshake would be less than the keepalive interval. With that strategy, it could detect and resume websocket connections.
75+
{% endtab %}
76+
{% endtabs %}
5577

78+
Websocket plugin is working with tcp keepalive mode, please refer to [networking](https://docs.fluentbit.io/manual/v/master/administration/networking#configuration-options) section for details. Since websocket is a stateful plugin, it will decide when to send out handshake to server side, for example when plugin just begins to work or after connection with server has been dropped. In general, the interval to init a new websocket handshake would be less than the keepalive interval. With that strategy, it could detect and resume websocket connections.
5679

5780
## Testing
5881

5982
### Configuration File
6083

84+
{% tabs %}
85+
{% tab title="fluent-bit.yaml" %}
86+
87+
```yaml
88+
pipeline:
89+
inputs:
90+
- name: tcp
91+
listen: 0.0.0.0
92+
port: 5170
93+
format: json
94+
95+
outputs:
96+
- name: websocket
97+
match: '*'
98+
host: 127.0.0.1
99+
port: 8080
100+
uri: /
101+
format: json
102+
workers: 4
103+
net.keepalive: on
104+
net.keepalive_idle_timeout: 30
105+
```
106+
107+
{% endtab %}
108+
{% tab title="fluent-bit.conf" %}
109+
61110
```text
62111
[INPUT]
63-
Name tcp
64-
Listen 0.0.0.0
65-
Port 5170
66-
Format json
112+
Name tcp
113+
Listen 0.0.0.0
114+
Port 5170
115+
Format json
67116

68117
[OUTPUT]
69-
Name websocket
70-
Match *
71-
Host 127.0.0.1
72-
Port 8080
73-
URI /
74-
Format json
75-
workers 4
76-
net.keepalive on
77-
net.keepalive_idle_timeout 30
118+
Name websocket
119+
Match *
120+
Host 127.0.0.1
121+
Port 8080
122+
URI /
123+
Format json
124+
workers 4
125+
net.keepalive on
126+
net.keepalive_idle_timeout 30
78127
```
79128

129+
{% endtab %}
130+
{% endtabs %}
131+
80132
Once Fluent Bit is running, you can send some messages using the _netcat_:
81133

82-
```bash
134+
```shell
83135
echo '{"key 1": 123456789, "key 2": "abcdefg"}' | nc 127.0.0.1 5170; sleep 35; echo '{"key 1": 123456789, "key 2": "abcdefg"}' | nc 127.0.0.1 5170
84136
```
85137

86138
In [Fluent Bit](http://fluentbit.io) we should see the following output:
87139

88-
```bash
89-
bin/fluent-bit -c ../conf/out_ws.conf
90-
Fluent Bit v1.7.0
91-
* Copyright (C) 2019-2020 The Fluent Bit Authors
92-
* Copyright (C) 2015-2018 Treasure Data
93-
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
94-
* https://fluentbit.io
95-
96-
[2021/02/05 22:17:09] [ info] [engine] started (pid=6056)
97-
[2021/02/05 22:17:09] [ info] [storage] version=1.1.0, initializing...
98-
[2021/02/05 22:17:09] [ info] [storage] in-memory
99-
[2021/02/05 22:17:09] [ info] [storage] normal synchronization mode, checksum disabled, max_chunks_up=128
140+
```shell
141+
$ fluent-bit -c ../conf/out_ws.conf
142+
143+
...
100144
[2021/02/05 22:17:09] [ info] [input:tcp:tcp.0] listening on 0.0.0.0:5170
101145
[2021/02/05 22:17:09] [ info] [out_ws] we have following parameter /, 127.0.0.1, 8080, 25
102146
[2021/02/05 22:17:09] [ info] [output:websocket:websocket.0] worker #1 started
@@ -119,10 +163,11 @@ Fluent Bit v1.7.0
119163
[2021/02/05 22:18:27] [ info] [output:websocket:websocket.0] thread worker #3 stopping...
120164
[2021/02/05 22:18:27] [ info] [output:websocket:websocket.0] thread worker #3 stopped
121165
[2021/02/05 22:18:27] [ info] [out_ws] flb_ws_conf_destroy
166+
...
122167
```
123168

124169
### Scenario Description
125170

126-
From the output of fluent-bit log, we see that once data has been ingested into fluent bit, plugin would perform handshake. After a while, no data or traffic is undergoing, tcp connection would been abort. And then another piece of data arrived, a retry for websocket plugin has been triggered, with another handshake and data flush.
171+
From the output of fluent-bit log, we see that once data has been ingested into fluent bit, plugin would perform handshake. After a while, no data or traffic is undergoing, tcp connection would be aborted. And then another piece of data arrived, a retry for websocket plugin has been triggered, with another handshake and data flush.
127172

128-
There is another scenario, once websocket server flaps in a short time, which means it goes down and up in a short time, fluent-bit would resume tcp connection immediately. But in that case, websocket output plugin is a malfunction state, it needs to restart fluent-bit to get back to work.
173+
There is another scenario, once websocket server flaps in a short time, which means it goes down and up in a short time, fluent-bit would resume tcp connection immediately. But in that case, websocket output plugin is a malfunction state, it needs to restart fluent-bit to get back to work.

0 commit comments

Comments
 (0)