Skip to content
Browse files

added in_debug_agent and fluent-debug command

  • Loading branch information...
1 parent 973a5da commit bcbfccc832aa42e77f88bdc0c55a16c007ec8fca @frsyuki frsyuki committed Aug 20, 2012
Showing with 148 additions and 1 deletion.
  1. +1 −1 Rakefile
  2. +6 −0 bin/fluent-debug
  3. +6 −0 fluent.conf
  4. +72 −0 lib/fluent/command/debug.rb
  5. +2 −0 lib/fluent/engine.rb
  6. +4 −0 lib/fluent/plugin.rb
  7. +57 −0 lib/fluent/plugin/in_debug_agent.rb
View
2 Rakefile
@@ -24,7 +24,7 @@ begin
gemspec.test_files = Dir["test/**/*.rb"]
gemspec.files = Dir["bin/**/*", "lib/**/*", "test/**/*.rb"] +
%w[fluent.conf VERSION AUTHORS Rakefile COPYING fluentd.gemspec Gemfile]
- gemspec.executables = ['fluentd', 'fluent-cat', 'fluent-gem']
+ gemspec.executables = ['fluentd', 'fluent-cat', 'fluent-gem', 'fluent-debug']
gemspec.required_ruby_version = '~> 1.9.2'
end
Jeweler::GemcutterTasks.new
View
6 bin/fluent-debug
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+require 'rubygems' unless defined?(gem)
+here = File.dirname(__FILE__)
+$LOAD_PATH << File.expand_path(File.join(here, '..', 'lib'))
+require 'fluent/command/debug'
View
6 fluent.conf
@@ -26,6 +26,12 @@
# tag apache.access
#</source>
+# Listen DRb for debug
+<source>
+ type debug_agent
+ port 24230
+</source>
+
## match tag=apache.access and write to file
#<match apache.access>
View
72 lib/fluent/command/debug.rb
@@ -0,0 +1,72 @@
+#
+# Fluent
+#
+# Copyright (C) 2011 FURUHASHI Sadayuki
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'optparse'
+
+op = OptionParser.new
+
+host = '127.0.0.1'
+port = 24230
+unix = nil
+
+op.on('-h', '--host HOST', "fluent host (default: #{host})") {|s|
+ host = s
+}
+
+op.on('-p', '--port PORT', "debug_agent tcp port (default: #{port})", Integer) {|i|
+ port = i
+}
+
+op.on('-u', '--unix PATH', "use unix socket instead of tcp") {|b|
+ unix = b
+}
+
+require 'drb/drb'
+
+if unix
+ uri = "drbunix:#{unix}"
+else
+ uri = "druby://#{host}:#{port}"
+end
+
+require 'fluent/load'
+
+$log = Fluent::Log.new(STDERR, Fluent::Log::LEVEL_TRACE)
+Fluent::Engine.init
+
+remote_engine = DRb::DRbObject.new_with_uri(uri)
+
+Fluent.module_eval do
+ remove_const(:Engine)
+ const_set(:Engine, remote_engine)
+end
+
+include Fluent
+
+puts "Connected."
+puts "Usage:"
+puts " Engine.match('some.tag').output : get an output plugin instance"
+puts " Engine.sources[i] : get input plugin instances"
+puts " Plugin.load_plugin(type,name) : load plugin class (use this if you get DRb::DRbUnknown)"
+puts ""
+
+Encoding.default_internal = nil if Encoding.respond_to?(:default_internal)
+
+require 'irb'
+IRB.start
+
View
2 lib/fluent/engine.rb
@@ -27,6 +27,8 @@ def initialize
@default_loop = nil
end
+ attr_reader :matches, :sources
+
def init
BasicSocket.do_not_reverse_lookup = true
Plugin.load_plugins
View
4 lib/fluent/plugin.rb
@@ -65,6 +65,10 @@ def load_plugin_dir(dir)
nil
end
+ def load_plugin(type, name)
+ try_load_plugin(name, type)
+ end
+
private
def load_gem_plugins
return unless defined? Gem
View
57 lib/fluent/plugin/in_debug_agent.rb
@@ -0,0 +1,57 @@
+#
+# Fluent
+#
+# Copyright (C) 2011 FURUHASHI Sadayuki
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+module Fluent
+
+
+class DebugAgentInput < Input
+ Plugin.register_input('debug_agent', self)
+
+ def initialize
+ require 'drb/drb'
+ super
+ end
+
+ config_param :bind, :string, :default => '0.0.0.0'
+ config_param :port, :integer, :default => 24230
+ config_param :unix_path, :integer, :default => nil
+ #config_param :unix_mode # TODO
+ config_param :object, :string, :default => 'Engine'
+
+ def configure(conf)
+ super
+ end
+
+ def start
+ if @unix_path
+ require 'drb/unix'
+ uri = "drbunix:#{@unix_path}"
+ else
+ uri = "druby://#{@bind}:#{@port}"
+ end
+ $log.info "listening dRuby", :uri => uri, :object => @object
+ obj = eval(@object)
+ @server = DRb::DRbServer.new(uri, obj)
+ end
+
+ def shutdown
+ @server.stop_service if @server
+ end
+end
+
+
+end

0 comments on commit bcbfccc

Please sign in to comment.
Something went wrong with that request. Please try again.