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 **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.
4
4
5
5
## Configuration Parameters
6
6
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`|
| 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`|
17
17
18
18
## Getting Started
19
19
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:
21
21
22
22
### Command Line
23
23
@@ -29,74 +29,118 @@ http://host:port/something
29
29
30
30
Using the format specified, you could start Fluent Bit through:
31
31
32
-
```text
32
+
```shell
33
33
fluent-bit -i cpu -t cpu -o websocket://192.168.2.3:80/something -m '*'
34
34
```
35
35
36
36
### Configuration File
37
37
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" %}
39
60
40
-
```python
61
+
```text
41
62
[INPUT]
42
-
Name cpu
43
-
Tag cpu
63
+
Name cpu
64
+
Tag cpu
44
65
45
66
[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
52
73
```
53
74
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 %}
55
77
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.
56
79
57
80
## Testing
58
81
59
82
### Configuration File
60
83
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
+
61
110
```text
62
111
[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
67
116
68
117
[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
78
127
```
79
128
129
+
{% endtab %}
130
+
{% endtabs %}
131
+
80
132
Once Fluent Bit is running, you can send some messages using the _netcat_:
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.
127
172
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