lib/fluent/plugin/in_monitor_agent.rb in fluentd-0.12.20 vs lib/fluent/plugin/in_monitor_agent.rb in fluentd-0.12.21
- old
+ new
@@ -12,26 +12,29 @@
# 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 'json'
+require 'webrick'
+require 'cgi'
+
+require 'cool.io'
+
+require 'fluent/input'
+require 'fluent/output'
+require 'fluent/filter'
+
module Fluent
class MonitorAgentInput < Input
Plugin.register_input('monitor_agent', self)
- require 'webrick'
+ config_param :bind, :string, default: '0.0.0.0'
+ config_param :port, :integer, default: 24220
+ config_param :tag, :string, default: nil
+ config_param :emit_interval, :time, default: 60
- def initialize
- require 'cgi'
- super
- end
-
- config_param :bind, :string, :default => '0.0.0.0'
- config_param :port, :integer, :default => 24220
- config_param :tag, :string, :default => nil
- config_param :emit_interval, :time, :default => 60
-
class MonitorServlet < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, agent)
@agent = agent
end
@@ -232,14 +235,14 @@
end
def start
log.debug "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins"
@srv = WEBrick::HTTPServer.new({
- :BindAddress => @bind,
- :Port => @port,
- :Logger => WEBrick::Log.new(STDERR, WEBrick::Log::FATAL),
- :AccessLog => [],
+ BindAddress: @bind,
+ Port: @port,
+ Logger: WEBrick::Log.new(STDERR, WEBrick::Log::FATAL),
+ AccessLog: [],
})
@srv.mount('/api/plugins', LTSVMonitorServlet, self)
@srv.mount('/api/plugins.json', JSONMonitorServlet, self)
@srv.mount('/api/config', LTSVConfigMonitorServlet, self)
@srv.mount('/api/config.json', JSONConfigMonitorServlet, self)
@@ -248,11 +251,11 @@
}
if @tag
log.debug "tag parameter is specified. Emit plugins info to '#{@tag}'"
@loop = Coolio::Loop.new
- opts = {:with_config => false}
+ opts = {with_config: false}
timer = TimerWatcher.new(@emit_interval, log) {
es = MultiEventStream.new
now = Engine.now
plugins_info_all(opts).each { |record|
es.add(now, record)
@@ -265,11 +268,11 @@
end
def run
@loop.run
rescue => e
- log.error "unexpected error", :error => e.to_s
+ log.error "unexpected error", error: e.to_s
log.error_backtrace
end
def shutdown
if @srv
@@ -372,10 +375,13 @@
all_plugins.map {|pe|
get_monitor_info(pe, opts)
}
end
+ # TODO: use %i() after drop ruby v1.9.3 support.
+ IGNORE_ATTRIBUTES = %W(@config_root_section @config @masked_config).map(&:to_sym)
+
# get monitor info from the plugin `pe` and return a hash object
def get_monitor_info(pe, opts={})
obj = {}
# Common plugin information
@@ -395,9 +401,10 @@
# include all instance variables if :with_debug_info is set
if opts[:with_debug_info]
iv = {}
pe.instance_eval do
instance_variables.each {|sym|
+ next if IGNORE_ATTRIBUTES.include?(sym)
key = sym.to_s[1..-1] # removes first '@'
iv[key] = instance_variable_get(sym)
}
end
obj['instance_variables'] = iv