Fluentd websocket output plugin.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 2b9e063 Jan 4, 2018




Fluentd websocket output plugin.

This plugin works as websocket server which can output JSON string or MessagePack binary.

In the current version, emitted data will be broadcasted to the all connected clients.


gem install fluent-plugin-websocket


<match foo.**>
  type websocket
  host      # default: (ANY)
  port 8080             # default: 8080
  use_msgpack false     # default: false
  add_time false        # default: false
  add_tag true          # default: true
  buffered_messages 100 # default: 0
  token SomeToken       # default: nil
  • host: WebSocket server IP address.

  • port: WebSocket server port.

  • use_msgpack: Send MessagePack format binary. Otherwise, you send JSON format text.

  • add_time: Add timestamp to the data.

  • add_tag: Add fluentd tag to the data.

  • buffered_messages: The number of messages to be buffered. The new connection receives them.

  • token: Authentication token. Passed as get param. If set to nil, authentication is disabled.

If there are no websocket connections, this plugin silently discards data. You may use out_copy plugin like this:

<match foo.**>
  type copy
    type file
    path /var/log/foo/bar.log
    type websocket
    port 8080

If buffered_messages is greater than 0, the last stored data is sent to the client upon new connection.

Data format

[tag, timestamp, data_object]
  • tag is appended when add_tag option is true.

  • timestamp is appended when add_time option is true.


curl -X POST -d 'json={"action":"login","user":6}' http://localhost:8888/foo/bar


Client sample

JSON format (use_msgpack: false)

function onMessage(evt) {
  data = JSON.parse(evt.data);

Msgpack format binary (use_msgpack: true)

Extract data by msgpack.js.

websocket.binaryType = "arraybuffer"
function onMessage(evt) {
  data = msgpack.unpack(new Uint8Array(evt.data))

Authentication and filtering

curl --include \
     --no-buffer \
     --header "Connection: Upgrade" \
     --header "Upgrade: websocket" \
     --header "Host:" \
     --header "Origin:" \
     --header "Sec-WebSocket-Key: SGVabG8sIHOvcmxDIQ==" \
     --header "Sec-WebSocket-Version: 13" \
  • If token setting in config file is not nil, websocket server checks token parameter

  • Client will receive data which include {“foo”: “bar”}


  • 0.1.8 Add authentication and filtering

  • 0.1.7 Add message buffering.

  • 0.1.6 Added license to gemspec.

  • 0.1.5 Fixed dependencies.

  • 0.1.4 Changed json parser to yajl.

  • 0.1.3 Bug fix.

  • 0.1.2 Released gem.

See commit logs about contributors.



Copyright © 2013 Tetsu Izawa (@moccos)


Apache License, Version 2.0