mogilefsd_log_tailer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@mlt
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in mogilefsd_log_tailer.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mogilefsd_log_tailer (0.0.1)
5
+ eventmachine
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ eventmachine (0.12.10)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ mogilefsd_log_tailer!
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ require 'mogilefsd_log_tailer'
7
+ require 'mogilefsd_log_tailer/version'
8
+
9
+ lt = MogilefsdLogTailer.new
10
+ lt.parse_options!
11
+ lt.run
@@ -0,0 +1,3 @@
1
+ class MogilefsdLogTailer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,71 @@
1
+ require 'mogilefsd_log_tailer/version'
2
+ require 'optparse'
3
+ require 'eventmachine'
4
+ require 'socket'
5
+
6
+ class MogilefsdLogTailer
7
+ module Handler
8
+ def post_init
9
+ @received_data = ''
10
+ send_data("!watch\r\n")
11
+ end
12
+
13
+ def receive_data(data)
14
+ port, ip = Socket.unpack_sockaddr_in(get_peername)
15
+ # puts("Received #{data.inspect} from #{ip}:#{port}")
16
+ if data =~ /\r\n/
17
+ lines = data.split("\r\n")
18
+ lines.each_with_index do |line, i|
19
+ # puts("line #{i}: #{line.inspect}")
20
+ if i == 0
21
+ print_log_entry(@received_data + line, ip, port)
22
+ @received_data = ''
23
+ elsif i == lines.size - 1
24
+ @received_data << line
25
+ else
26
+ print_log_entry(line, ip, port)
27
+ end
28
+ end
29
+ else
30
+ @received_data << data
31
+ end
32
+ # puts("@received_data = #{@received_data.inspect}")
33
+ end
34
+
35
+ def print_log_entry(line, ip, port)
36
+ puts("#{Time.now.to_s}: #{ip}:#{port}: #{line}")
37
+ end
38
+ end
39
+
40
+ def initialize
41
+ @hosts = []
42
+ end
43
+
44
+ def parse_options!
45
+ OptionParser.new do |o|
46
+ script_name = File.basename($0)
47
+ o.set_summary_indent(' ')
48
+ o.banner = "#{script_name} version #{VERSION}\nUsage: #{script_name} [options] tracker1:port1 tracker2:port2 ..."
49
+ o.separator ""
50
+ o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
51
+ end.parse!
52
+
53
+ while (h = ARGV.shift)
54
+ @hosts << h
55
+ end
56
+
57
+ if @hosts.empty?
58
+ STDERR.puts("No hosts to tail.")
59
+ exit(1)
60
+ end
61
+ end
62
+
63
+ def run
64
+ EventMachine.run do
65
+ @hosts.each do |hp|
66
+ host, port = hp.split(':')
67
+ EventMachine.connect(host, port.to_i, Handler)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8; mode: ruby -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mogilefsd_log_tailer/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mogilefsd_log_tailer"
7
+ s.version = MogilefsdLogTailer::VERSION
8
+ s.authors = ["Andrew Watts"]
9
+ s.email = ["ahwatts@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Script to do "tail -f" on the "!watch" output from several MogileFS trackers.}
12
+ s.description = %q{Script to do "tail -f" on the "!watch" output from several MogileFS trackers.}
13
+
14
+ s.rubyforge_project = "mogilefsd_log_tailer"
15
+
16
+ s.add_dependency('eventmachine')
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mogilefsd_log_tailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Watts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &16747740 !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: *16747740
25
+ description: Script to do "tail -f" on the "!watch" output from several MogileFS trackers.
26
+ email:
27
+ - ahwatts@gmail.com
28
+ executables:
29
+ - mogilefsd_tail
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - .rvmrc
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - Rakefile
38
+ - bin/mogilefsd_tail
39
+ - lib/mogilefsd_log_tailer.rb
40
+ - lib/mogilefsd_log_tailer/version.rb
41
+ - mogilefsd_log_tailer.gemspec
42
+ homepage: ''
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: mogilefsd_log_tailer
62
+ rubygems_version: 1.8.6
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Script to do "tail -f" on the "!watch" output from several MogileFS trackers.
66
+ test_files: []