• Stars
    star
    127
  • Rank 272,974 (Top 6 %)
  • Language
    Ruby
  • Created about 14 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby EventMachine file tailing and friends. 'gem install eventmachine-tail' to install.

eventmachine-tail

This project contains two EventMachine extensions.

First, it adds an event-driven file-following similar to the unix ‘tail -f’
command. For example, you could use it to follow /var/log/messages the same way
tail -f would.

Second, it adds event-driven file patterns allowing you to watch a given file
pattern for new or removed files. For example, you could watch /var/log/*.log
for new/deleted files.

Why?

For logstash, the log agents were
event-driven using EventMachine. The log agents mainly get their data from
logfiles. To that end, we needed a way to treat log files as a stream.

There’s a ruby gem ‘file-tail’ that implements tailing, but not in an
event-driven way. This makes it hard to use in EventMachine programs like
logstash.

Thus, eventmachine-tail was born.

Further, the usage patterns for logstash required the ability to watch a
directory (or a file pattern) for new log files.

Get eventmachine-tail

To install eventmachine-tail, you only need to use gem:

gem install eventmachine-tail

This will also install the rtail tool described below.

Implementation Thoughts

“Don’t block the reactor”

EventMachine::FileTail will only read one chunk (64K by default) from any file
for each tick of the reactor. This helps ensure we don’t spend too much time
reading from the file.

A consequence of not reading the file “as fast as possible until eof” can cause
longer data sets to take longer to read since there will be a small delay
between each read since the reactor only runs about once every 50ms (depending
on the polling features used).

EOF Handling

When we are at the end of file, we rely on EventMachine::FileWatch to notify us
when the file changes. On Linux this uses inotify and on OS X and FreeBSD will
use kqueue to get event-driven notifications of file changes.

File truncation

If the file length ever shortens, we assume this means the file was truncated.
When this happens, we seek to the beginning of the file and continue reading.

File rotation

If we notice that the inode (or underlying device) has changed, we will reopen
the file by pathname. This change is generally an indication that our file has
been rotated as part of some periodic log rotation.

Globs

You can also use file glob patterns
to select files to tail. This pattern is checked periodically to see if new
files are found.

For example, if your java app writes to logfiles with generated filenames that
are hard to predict, you should use EventMachine::FileGlobWatch to match any
generated files as they are generated.

Globs are implemented in a polling manner because of the “non-obviousness” of
implementing a glob notifier with file watches. It is on my todo list to
implement in this way, however.

Example code

For a simple file tailing example, look at tail.rb

For an example of using glob watching file patterns, look at globwatch.rb

For an example of using both glob watching and file tailing, check out glob-tail.rb – this project provides a glue class that helps you easily tail globs.

rtail tool

A script comes with eventmachine-tail called ‘rtail’

This script allows you to tail files similar to tail(1) but allows you to use
the glob watching feature of eventmachine-tail to watch file path patterns
(globs) in a tail-ey way.

For example, if you want to ‘tail -f’ all files, recursively, in /var/log
except ones matching ‘*.gz’, you would use:

rtail -x "*.gz" "/var/log/**/*"

This will follow any existing files and follow newly-created ones that match
the glob given as they are created.

By default, rtail checks the glob pattern every 5 seconds. You can change this
value with the ‘-i’ flag.

You can also tell rtail to not prefix each line with the filename by giving the
‘-n’ flag.

More Repositories

1

fpm

Effing package management! Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity.
Ruby
10,867
star
2

xdotool

fake keyboard/mouse input, window management, and more
C
2,728
star
3

pleaserun

An attempt to abstract this "init" script madness.
Ruby
1,168
star
4

heroku-buildpack-meteor

a heroku buildpack for meteor (meteor.com)
Shell
589
star
5

keynav

retire your mouse.
C
539
star
6

puppet-examples

A collection of advanced puppet examples (uses older versions of puppet v3/v2)
Puppet
392
star
7

grok

DRY and RAD for regular expressions and then some.
C
238
star
8

ruby-cabin

Structured+contextual logging experiments in Ruby
Ruby
154
star
9

experiments

random experiments
JavaScript
126
star
10

ruby-filewatch

ruby api for file watching and tailing.
Ruby
90
star
11

software-patterns

Ruby
71
star
12

fex

fex - flexible field/token extraction
Shell
57
star
13

ruby-grok

Pure-ruby implementation of grok.
Ruby
54
star
14

rvm-packaging

Automatic packaging (rpm/deb) for rvm and its rubies
Shell
51
star
15

fingerpoken

Use your browser as a remote and touchpad (iphone/ipad/laptop, etc)
Ruby
44
star
16

ruby-netty-eventmachine

EventMachine-compatible API on top of Netty - for JRuby
Ruby
44
star
17

s3cleaner

Amazon S3 file cleaner - delete things older than a certain age, matching a pattern, etc.
Python
41
star
18

ruby-stud

Common software patterns I use frequently.
Ruby
36
star
19

ruby-sshkeyauth

Use SSH keys for signing and verifying data (outside of ssh servers)
Ruby
36
star
20

syslog-shipper

UNMAINTAINED - Ship logs from files to a syslog server
Ruby
35
star
21

ruby-minstrel

A ruby instrumentation tool
Ruby
32
star
22

ruby-ftw

Ruby FTW - For The Web. Experimentation in web clients and servers.
Ruby
31
star
23

dotfiles

dotfiles and friends.
Ruby
28
star
24

jruby-elasticsearch

Native Java ElasticSearch for JRuby
Ruby
28
star
25

shatty

share tty (record, play, share)
Ruby
25
star
26

vagrant-port

Vagrant 'port' plugin (for querying forwarded ports)
Ruby
22
star
27

shebang

A better #! runner than /usr/bin/env
C
21
star
28

fosl

Ruby API using lsof(1)
Ruby
20
star
29

sysadvent

Systems Administrator Advent Calendar
Perl
18
star
30

ruby-arr-pm

Ruby RPM library (pure ruby, no librpm)
Ruby
16
star
31

procnanny

Process Nanny. It's like daemontools or supervisord, but fun.
C++
15
star
32

eventmachine-vnc

EventMachine VNC/RFB protocol support
Ruby
14
star
33

gem-packaging

gem packaging tools
Shell
12
star
34

batcave

An attempt to make a digital batcave.
Ruby
11
star
35

vxin

Visualization (v11n, v XI n) experiments
JavaScript
11
star
36

elasticsearch-on-heroku

ElasticSearch run on Heroku
Java
11
star
37

pam_captcha

Make ssh more fun with a figlet captcha.
C
10
star
38

python-rightscale

An object-oriented interface to RightScale's API.
Python
10
star
39

vagrant-tricks

A collection of vagrant tricks
Ruby
10
star
40

vim-ackmore

My vim stuff.
Vim Script
9
star
41

ruby-flores

Exploration in randomized testing (fuzzing, stress testing, etc)
Ruby
9
star
42

parasite

parasite? live on another process.
C
8
star
43

ruby-grok-ui

UNMAINTAINED - A grok ui.
JavaScript
7
star
44

python-packaging

DEPRECATED. Use: http://github.com/jordansissel/fpm
Shell
6
star
45

extlookup.rb

puppet's extlookup from the commandline
6
star
46

puppet-pleaserun

A custom type for puppet that allows you to use pleaserun to create init, launchd, upstart, systemd, and may more 'init' script thingies.
Ruby
6
star
47

presentation-an-implementation-of-puppet

Presentation of puppet use at loggly (masterless, nodeless, exported resources, style recommendations, etc)
JavaScript
5
star
48

grok-cpp

Grok written in C++, this is no longer maintained. Let it serve as a warning to others. ;)
C++
5
star
49

djbdnsplus

Fork of djbdns 1.05
C
5
star
50

ruby-backport-bij

Backporting ruby features so shit keeps working on systems people actually have in production.
Ruby
4
star
51

message-passing

experiments in message passing
Ruby
4
star
52

demo.logstash.net

config management for the demo.logstash.net machine(s)
Ruby
4
star
53

ruby-O_o

raise O_o
Ruby
4
star
54

websocket-log-demo

UNMAINTAINED
Ruby
4
star
55

firefox-tabsearch

Find-as-you-type tab searching for Firefox.
Shell
4
star
56

ruby-insist

I insist. (a testing tool for ruby)
Ruby
4
star
57

zmqexec

zmq exec
C
4
star
58

puppet-workstation

Puppet manifests for my workstation(s)
Puppet
4
star
59

tmux

svn-git mirrored tmux for me to play with.
C
4
star
60

semicomplete.com

semicomplete.com projects
HTML
3
star
61

ruby-lsof

You really want 'fosl'
3
star
62

node-packaging

npm -> another format, like .deb
Ruby
3
star
63

go-cabin

go logging and stuff.
Go
3
star
64

fastest_sites

Sort FreeBSD Ports MASTER_SITE_* things by speed to you.
Python
3
star
65

heroku-buildpack-varnish

Shell
3
star
66

xboxproxy

xboxproxy, resurrected.
Python
3
star
67

rubygems-regression

regression tests for rubygems
2
star
68

packer

UNMAINTAINED - an example tool for packing up ruby apps into a tarball including all dependencies. This was for an interview a while ago.
Ruby
2
star
69

ruby-rplot

Experimenting with SVG and graphint
Ruby
2
star
70

twitter-spamwatch

Maybe pick out some spam from the twitters.
2
star
71

perl-Term-Shelly

Term::Shelly is a readline-ish terminal interface for perl.
Perl
2
star
72

freebsd-newmoused

An old effort to improve moused on freebsd. Needs new owner.
C
2
star
73

python-pimp

Web-based self-managed mp3 radio. This project is not maintained.
JavaScript
2
star
74

heumon

Experiments in clicking.
JavaScript
2
star
75

tic

A terminal-based AIM client for Perl. Uses Net::OSCAR. Written in 2004, still seems to work :)
Perl
2
star
76

sample-rpms

RPMs for testing ruby-arr-pm
2
star
77

go-lumberjack

Moves logs... and stuff.
2
star
78

slashport

An experiment in exported metrics and monitoring
Ruby
2
star
79

ruby-cabin-web

UNMAINTAINED - A web interface to data flowing into cabin
Ruby
2
star
80

ruby-acme-tlap

Ruby Acme::TLAP (Talk Like A Pirate)
2
star
81

ifwm

A window manager project. Perhaps I'll finish it some day.
C
2
star
82

chef-lumberjack-cookbook

chef cookbook for lumberjack
Ruby
2
star
83

firefox-urledit

A url editor extension for Firefox
JavaScript
2
star
84

windows-winmgr

An attempt to add type-to-find to Windows.
C++
2
star
85

slideshow-template-jls

slideshow template 'jls'
JavaScript
2
star
86

googlemaps-traffic-sms

Email gateway for getting google maps traffic snapshots to your phone.
Python
2
star
87

semicomplete-googlecode-archive

An archive of my old semicomplete.googlecode.com svn repo. Hasn't been touched really since 2012.
C
1
star
88

react-boilerplate-fun

JavaScript
1
star
89

veewee-jenkins

Ruby
1
star
90

keymux

1
star
91

button-game

A toy I made.
Python
1
star
92

example

1
star
93

this-is-only-a-test

This is only a test. I promise!
1
star
94

ipmi

C++
1
star
95

omnibus-fpm

UNMAINTAINED
1
star