logstash-plugins / logstash-input-jmx

Apache License 2.0
17 stars 27 forks source link

Logstash-input-jmx new feature proposal #12

Open graziano1955 opened 9 years ago

graziano1955 commented 9 years ago

I used the JMX plugin to capture data from a WSO2 platform nodes, reading the attributes exposed by their JMX Beans. But not all data can be captured reading attributes, many data can be read only invoking specific methods and passing parameters. So I investigated the JMX plugin (I know Java, C++, Delphi, ecc. but I dont know Ruby) and I saw that the plugin use a component developed by Jeff Mesnil in 2007 which interfaces the Java JMX components. This component supports attributes but also operations (methods). So i tried to implement the operations support in JMX plugin and for some reason (I don't know Ruby!) now I am able to capture data from operations invocation. I hope this can be a little contribution to the JMX plugin authors and possibly a new featura in the next plugin release.

CHANGES in jmx.rb:

• added in validate_configuration: if query.has_key?("operations") && !query["operations"].respond_to?(:each) validation_errors << BAD_TYPE_QUERY_PARAMETER % { :param => 'operations', :index => index, :expected => Enumerable, :actual => query['operations'].class } end

• added in thread_jmx: if query.has_key?('operations') @logger.debug("Retrieves operations #{query['operations']} to #{jmx_object_name.object_name}") query['operations'].each do |operation| begin @logger.debug("operation: #{operation[0]} params: #{operation[1].join(', ')}")
jmx_operation_value = jmx_object_name.send(operation[0], *operation[1]) if jmx_operation_value.instance_of? Java::JavaxManagementOpenmbean::CompositeDataSupport @logger.debug('The jmx value is a composite_data one') jmx_operation_value.each do |jmx_operation_value_composite| @logger.debug("Get jmx value #{jmx_operation_value[jmx_operation_value_composite]} for operation #{operation}.#{jmx_operation_value_composite} to #{jmx_object_name.object_name}") send_event_to_queue(queue, thread_hash_conf['host'], "#{base_metric_path}.#{object_name}.#{operation}.#{jmx_operation_value_composite}", jmx_operation_value[jmx_operation_value_composite]) end else @logger.debug("Get jmx value #{jmx_operation_value} for operation #{operation} to #{jmx_object_name.object_name}") send_event_to_queue(queue, thread_hash_conf['host'], "#{base_metric_path}.#{object_name}.#{operation}", jmx_operation_value) end rescue Exception => ex @logger.warn("Failed retrieving metrics for operation #{operation} on object #{jmx_object_name.object_name}") @logger.warn(ex.message) end end end

CHANGES in jmx configuration: ...... { "object_name" : "java.lang:type=Threading", "attributes" : [ "ThreadCount", "TotalStartedThreadCount", "DaemonThreadCount", "PeakThreadCount" ], "object_alias" : "Threading" }, { "object_name" : "org.wso2.carbon:type=StatisticsAdmin", "operations" : [ ["getServiceRequestCount", ["MMGQueryPazienteProxy"]], ["getServiceFaultCount", ["MMGQueryPazienteProxy"]], ["getServiceResponseCount", ["MMGQueryPazienteProxy"]], ["getOperationRequestCount", ["MMGQueryPazienteProxy", "QueryPaziente"]], ["getOperationFaultCount", ["MMGQueryPazienteProxy", "QueryPaziente"]], ["getOperationResponseCount", ["MMGQueryPazienteProxy", "QueryPaziente"]] ], "object_alias" : "StatisticsAdmin" } ]

Operations is an array of jmx operations. Each array element has as the first element the operation name and as the second element an array of parameters.

Graziano

sreltgen commented 9 years ago

@graziano1955 Hello ! I'm also monitoring WSO2 ESB instances and your contribution seems to be the perfect match for what I'm looking for. Congrats for your comment and the work done. I tried to modify jmx.rb following your comment, but with no luck for now... Do you mind sharing your modified plugin with me ? Maybe a pull-request linked to this ticket could be the right thing to do, in order for your contribution to be merged into the plugin ? I can offer help to do the pull-request, if needed... Thanks again !

graziano1955 commented 9 years ago

Hello, sorry for the late answer but i was in holiday ... I have no problems to share plugin with you ... Please send a request to graziano.derivo@insiel.it I am new to github, so if u tell me how to do a pull-request you are welcome ....

Best regards