No commit activity in last 3 years
No release in over 3 years
Fluentd websocket output plugin which can output JSON string or MessagePack binary to the clients.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Fluent::Plugin::Websocket¶ ↑

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.

This fork is from moccos/fluent-plugin-websocket, but locks in Ruby 1.9 as a minimum Ruby version. The newest fluentd gem dependency “serverengine” requires Ruby 2.1.

Installation¶ ↑

gem install fluent-plugin-websocket

This plugin depends on {em-websocket}.

Configuration¶ ↑

<match foo.**>
  type websocket
  host 192.168.1.1    # default: 0.0.0.0 (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
</match>
  • 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.

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

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

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.

Example¶ ↑

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

["foo.bar",1364699026,{"action":"login","user":6}]

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))
  ...
}

Contributing¶ ↑

  1. Fork it

  2. Create your feature branch (‘git checkout -b my-new-feature`)

  3. Commit your changes (‘git commit -am ’Add some feature’‘)

  4. Push to the branch (‘git push origin my-new-feature`)

  5. Create new Pull Request

Recent changes¶ ↑

  • 0.1.7 Add message buffering. (Thanks to SebastianOsuna)

  • 0.1.6 Added license to gemspec.

  • 0.1.5 Fixed dependencies. (Thanks to ca-gacky)

  • 0.1.4 Changed json parser to yajl. (Thanks to Kogarasi)

  • 0.1.3 Bug fix.

  • 0.1.2 Released gem.

Copyright

Copyright © 2013 IZAWA Tetsu (@moccos)

License

Apache License, Version 2.0