ftail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/README.textile +44 -0
  4. data/bin/ftail +101 -0
  5. data/ftail.gemspec +16 -0
  6. data/lib/.gitkeep +0 -0
  7. metadata +73 -0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/README.textile ADDED
@@ -0,0 +1,44 @@
1
+ h1. ftail (custome tail command for Fluentd File output plugin)
2
+
3
+
4
+ h2. Installation
5
+
6
+ install it yourself as:
7
+
8
+ <pre>
9
+ $ gem install ftail
10
+ </pre>
11
+
12
+
13
+ h2. Usage
14
+
15
+ command example:
16
+
17
+ <pre>
18
+ $ ftail <filename>
19
+ $ ftail --grep [match-word] <filename>
20
+ $ ftail --grepv [invert-match-word] <filename>
21
+ $ ftail --grep [word] --grepv [word] <filename>
22
+ $ ftail <filename> --grep [word]
23
+ </pre>
24
+
25
+
26
+ grep example:
27
+
28
+ <pre>
29
+ $ tail /var/log/td-agent/td-agent_fileoutput.log
30
+ 2013-02-22T12:37:01Z fluent.info {"message"=>"", "date"=>2013-02-22T12:37:00Z}
31
+ 2013-02-22T12:37:02Z fluent.info {"message"=>"", "date"=>2013-02-22T12:37:01Z}
32
+
33
+ $ ftail /var/log/td-agent/td-agent_fileoutput.log
34
+ Tailing /var/log/td-agent/td-agent_fileoutput.log
35
+ 2013-02-22T12:37:01Z fluent.info
36
+ {"message"=>"",
37
+ "date"=>2013-02-22T12:37:00Z}
38
+ ----------------------------------------------------------------------------------------------------------------------------------------
39
+ 2013-02-22T12:37:02Z fluent.info
40
+ {"message"=>"",
41
+ "date"=>2013-02-22T12:37:01Z}
42
+ ----------------------------------------------------------------------------------------------------------------------------------------
43
+ </pre>
44
+
data/bin/ftail ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "eventmachine"
5
+ require "eventmachine-tail"
6
+ require "json"
7
+ require "io/console"
8
+ require "optparse"
9
+ require "pp"
10
+
11
+ class Reader < EventMachine::FileTail
12
+ def initialize(path, startpos=-1)
13
+ super(path, startpos)
14
+ puts "Tailing #{path}"
15
+ @buffer = BufferedTokenizer.new
16
+ end
17
+
18
+ def receive_data(data)
19
+ @buffer.extract(data).each do |line|
20
+ if /^(\S*)\s(\S*)\s(.*)$/=~ line
21
+ time = $1
22
+ tag = $2
23
+ records_string = $3
24
+
25
+ tag = grep(tag, $options[:grep]) || next
26
+ tag = grepv(tag, $options[:grepv]) || next
27
+
28
+ begin
29
+ records = JSON.parse(records_string)
30
+ rescue
31
+ records = records_string
32
+ end
33
+
34
+ puts time + "\t" + "\e[34m#{tag}\e[0m"
35
+ pp records
36
+ puts '-' * IO.console.winsize[1]
37
+ end
38
+ end
39
+ end
40
+
41
+ def grep(inputword,grepwords)
42
+ if grepwords
43
+ flg = false
44
+ grepwords.each do |grepword|
45
+ if /.*#{grepword}.*/=~inputword
46
+ flg = true
47
+ end
48
+ end
49
+ unless flg
50
+ return false
51
+ end
52
+ end
53
+ return inputword
54
+ end
55
+
56
+ def grepv(inputword,grepvwords)
57
+ if grepvwords
58
+ flg = false
59
+ grepvwords.each do |grepvword|
60
+ if /.*#{grepvword}.*/=~inputword
61
+ flg = true
62
+ end
63
+ end
64
+ if flg
65
+ return false
66
+ end
67
+ end
68
+ return inputword
69
+ end
70
+ end
71
+
72
+
73
+ def main(args)
74
+ $options = Hash.new
75
+
76
+ optparse = OptionParser.new
77
+
78
+ optparse.on('--grep [grep1,grep2]') {|v|
79
+ $options[:grep] = v.split(',')
80
+ }
81
+ optparse.on('--grepv ') {|v|
82
+ $options[:grepv] = v.split(',')
83
+ }
84
+
85
+ optparse.permute!(args)
86
+
87
+ if args.length == 0
88
+ puts "Usage: #{$0} <path> [path2] [...]"
89
+ return 1
90
+ end
91
+
92
+ EventMachine.run do
93
+ args.each do |path|
94
+ EventMachine::file_tail(path, Reader)
95
+ end
96
+ end
97
+ end
98
+
99
+ exit(main(ARGV))
100
+
101
+
data/ftail.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'ftail'
3
+ gem.version = '0.0.1'
4
+ gem.summary = 'ftail is a custom tail command for flutne-plugin-file'
5
+ gem.files = `git ls-files`.split($\)
6
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
7
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
8
+ gem.author = 'Yuichi UEMURA'
9
+ gem.email = 'yuichi.u@gmail.com'
10
+ gem.homepage = 'https://github.com/u-ichi/ftail'
11
+ gem.bindir = 'bin'
12
+ gem.add_dependency "eventmachine"
13
+ gem.add_dependency "eventmachine-tail"
14
+ gem.executables << 'ftail'
15
+ end
16
+
data/lib/.gitkeep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ftail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuichi UEMURA
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &13897760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13897760
25
+ - !ruby/object:Gem::Dependency
26
+ name: eventmachine-tail
27
+ requirement: &13897220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *13897220
36
+ description:
37
+ email: yuichi.u@gmail.com
38
+ executables:
39
+ - ftail
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.textile
46
+ - bin/ftail
47
+ - ftail.gemspec
48
+ - lib/.gitkeep
49
+ homepage: https://github.com/u-ichi/ftail
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.11
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: ftail is a custom tail command for flutne-plugin-file
73
+ test_files: []