diff --git a/lib/fluent/plugin/in_monitor_agent.rb b/lib/fluent/plugin/in_monitor_agent.rb index e007c0d919..6b9127c038 100644 --- a/lib/fluent/plugin/in_monitor_agent.rb +++ b/lib/fluent/plugin/in_monitor_agent.rb @@ -85,6 +85,10 @@ def build_object(req, res) opts[:pretty_json] = true end + if ivars = (qs['with_ivars'] || []).first + opts[:ivars] = ivars.split(',') + end + if with_config = get_search_parameter(qs, 'with_config'.freeze) opts[:with_config] = Fluent::Config.bool_value(with_config) end @@ -364,6 +368,13 @@ def get_monitor_info(pe, opts={}) } end obj['instance_variables'] = iv + elsif ivars = opts[:ivars] + iv = {} + ivars.each {|name| + iname = "@#{name}" + iv[name] = pe.instance_variable_get(iname) if pe.instance_variable_defined?(iname) + } + obj['instance_variables'] = iv end obj diff --git a/test/plugin/test_in_monitor_agent.rb b/test/plugin/test_in_monitor_agent.rb index fced1175da..24ffeb7e98 100644 --- a/test/plugin/test_in_monitor_agent.rb +++ b/test/plugin/test_in_monitor_agent.rb @@ -350,6 +350,39 @@ def get(uri, header = {}) assert_equal(expected_null_response, null_response) end + test "/api/plugins.json with 'with_ivars'. response contains specified instance variables of each plugin" do + d = create_driver(" + @type monitor_agent + bind '127.0.0.1' + port #{@port} + tag monitor +") + d.instance.start + expected_test_in_response = { + "output_plugin" => false, + "plugin_category" => "input", + "plugin_id" => "test_in", + "retry_count" => nil, + "type" => "test_in", + "instance_variables" => {"id" => "test_in"} + } + expected_null_response = { + "buffer_queue_length" => 0, + "buffer_total_queued_size" => 0, + "output_plugin" => true, + "plugin_category" => "output", + "plugin_id" => "null", + "retry_count" => 0, + "type" => "null", + "instance_variables" => {"id" => "null", "num_errors" => 0} + } + response = JSON.parse(get("http://127.0.0.1:#{@port}/api/plugins.json?with_config=no&with_retry=no&with_ivars=id,num_errors")) + test_in_response = response["plugins"][0] + null_response = response["plugins"][5] + assert_equal(expected_test_in_response, test_in_response) + assert_equal(expected_null_response, null_response) + end + test "/api/config" do d = create_driver(" @type monitor_agent