Archive for the ‘jmx4r’ Category

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 =[:host],params[:port])
    render :text => system.query_state

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

   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}"