GithubHelp home page GithubHelp logo

inhwankim / fluent-plugin-event-tail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imkira/fluent-plugin-event-tail

0.0 2.0 0.0 211 KB

fluentd input plugin derived from in_tail and inspired by in_forward for reading [tag, time, record] messages from a file

License: MIT License

Ruby 100.00%

fluent-plugin-event-tail's Introduction

fluent-plugin-event-tail, a plugin for Fluentd

Build Status

event-tail is an input plugin for fluentd based on in_tail but for reading [tag, time, record] JSON messages from a file.

If you use fluent-logger-ruby, fluent-logger-node, and so on, you are probably connecting to 'localhost' (or worse, to a remote host) and sending messages via TCP sockets.

That's all fine but what happens if fluentd is down for some reason? Well, most (if not all) logger implementations keep a list of pending failed messages and try sending them periodically. But what if your application dies before having the chance to flush everything to fluentd? Well, you will probably lose those pending messages.

The reason I made this plugin is to allow me (and hopefully you too) to rather send those messages, not via TCP sockets, but directly to a file and have fluentd read them. The obvious advantage is that you always have backups of your logs in your hard disks in case fluentd is not running or the DB where you are aggregating them died for some reason. Another reason is, your logs are still human readable and easily transformable (they are just newline separated JSON strings).

The format of the messages is based on in_forward plugin:

stream:
  message...

message:
  [tag, time, record]
  or
  [tag, [[time,record], [time,record], ...]]

example:
  ["myapp.access", [1308466941, {"a"=>1}], [1308466942, {"b"=>2}]]

This plugin is mostly based on in_tail, and therefore you are expected to append newline separated JSON strings of messages in the above format. Also note that this plugin supports formatted time strings via the time_format config parameter, not just numeric UNIX timestamps.

Installation

Add this line to your application's Gemfile:

gem 'fluent-plugin-event-tail'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fluent-plugin-event-tail

Configuration

This plugin has the same configuration as in_tail, with the exception of tag and format that were removed.

# fluent.conf
<source>
  type event_tail
  path /var/log/your_app.log
  pos_file /var/log/your_app.log.pos
# disable next line to enable custom time formatting
# time_format %d %b %Y %H:%M:%S
</source>

Usage

After running fluentd, you can emit events by appending to the file:

# time 0 means "current time on server"
echo '["prefix.debug",0,{"foo":"bar"}]' >> /var/log/your_app.log
# time passed as UNIX timestamp (2013-02-20 01:18:31 +0900)
echo '["prefix.debug1",1361290711,{"foo1":"bar1"}]' >> /var/log/your_app.log
# same time but passed as string
echo '["prefix.debug2","2009-03-26 22:33:12 +0900",{"foo2":"bar2"}]' >> /var/log/your_app.log
# group multiple events in one line by tag
echo '["prefix.debug3",[[1361290714,{"foo3":"bar3"}],[1361290716,{"foo4":"bar4"}]]]' >> /var/log/your_app.log

fluentd will report something like:

prefix.debug: {"foo":"bar"}
prefix.debug1: {"foo1":"bar1"}
prefix.debug2: {"foo2":"bar2"}
prefix.debug3: {"foo3":"bar3"}
prefix.debug3: {"foo4":"bar4"}

Please note that contrarily to in_forward that only accepts UNIX timestamps, fluent-plugin-event-tail supports the original in_tail time_format parameter, so you can also pass strings as event times. The default value of time_format is '%Y-%m-%d %H:%M:%S %z. If you pass a numeric UNIX timestamp then time_format will be ignored.

Contributing

You are very welcome to submit patches or improve this plugin. Just make sure you send me a pull request.

License

fluent-plugin-event-tail is licensed under the MIT license:

www.opensource.org/licenses/MIT

Copyright

Copyright (c) 2013 Mario Freitas. See LICENSE.txt for further details.

fluent-plugin-event-tail's People

Contributors

imkira avatar kiyoto avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.