Handy JRuby / JMX MBean Info

I was tired of using the jmx-console and clicking through multiple pages, so
I created a little wrapper around the JMX connector to obtain server info data for my app servers…

http://appserver:8080/systems?host=my-box&port=12345 will report back the top 15 threads and the stack trace and a full dump of the running threads.
I created this so that I can get all the info back in one shot. Using the jruby gem Much nicer than going through all the hoops of clicking around the web console.

I plan on adding more nice little things to get a cool little dashboard with minimal effort.

SystemsController < ApplicationController
  def show 
    system = System.new(params[:host],params[:port])
    render :text => system.query_state
  end
end

class System
   def initialize(host, port)
      @host, @port = host, port
   end

   def query_state
      JMX::MBean.establish_connection(:host=>@host, :port=>@port)
      info = JMX::MBean.find_by_name "jboss.system:type=ServerInfo"
      strings = info.list_thread_cpu_utilization
      report = "Top 15 Thread Utilization "
      report << "#{strings.split(" ")[0..16].join(" ")}"
      report << "Thread Dump #{info.list_thread_dump}"
   end
end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: