Miles to go …

January 7, 2009

TOTD #61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?

Filed under: totd, web2.0 — arungupta @ 5:00 am

GlassFish Gem can easily run both Rails and Merb application. Using JRuby, as opposed to MRI, allows you to use standard Java monitoring framework and tools. Java Management Extensions (JMX) is a standard management and monitoring solution for Java platform. This Tip Of The Day shows how to apply JMX techniques to monitor Rails/Merb applications.

The blog uses a trivial Rails/Merb application to demonstrate monitoring but the techniques can be applied to any Rails or Merb application. FYI TOTD #52 shows to create a simple Merb application and TOTD #28 shows how to create a simple Rails scaffold.

This blog will focus on local monitoring, i.e. monitor a Rails/Merb application running on the same machine as monitoring tool. A subsequent blog will demonstrate remote monitoring, i.e. monitor a Rails/Merb application from a different machine.

There is no extra configuration required to enable monitoring if your Rails/Merb application is running on GlassFish gem. You just need to launch an additional tool to monitor the already running application.

jconsole is a CLI bundled with JDK and launches a graphical tool to monitor and manage Java applications on a local or remote machine. jconsole can be used to monitor local application (those running on the same systems as jconsole) and remote applications (systems other than running jconsole).

Invoke “jconsole” in a shell as:


It shows the following window:

The window shows different Java process that can be managed/monitored by jconsole. “org.jruby.Main -S glassfish” is the process corresponding to our Rails/Merb application running using GlassFish Gem. Click on that process (6179 in this case) and click “Connect”.

The jconsole interface explains the different tabs and meaning of information displayed on each tab. Here is a snapshot of different tabs captured for a trivial Rails application.

It shows heap memory usage, threads, classes loaded, and CPU usage over a period of time. The “Memory” tab tracks different GC pools and shows their dynamic growth. Clicking on “Perform GC” on top-right corner performs a garbage collection (more on this later).

The “Threads” tab shows the highest number of threads since JVM started and current number of live daemon and non-daemon threads. Clicking on a particular thread shows it’s current state and stack trace if it’s waiting.

MBeans tab shows different managed beans registered with the platform MBean server, i.e. MBean server available in the JDK. As you can see there are several standard MBeans displayed on the left-hand side from java.lang and java.util.logging domains.

JRuby runtime also exposes 4 different MBeans – ClassCache, Config, JITCompiler and ParserStats – all in “org.jruby” domain. Clicking on each MBean shows detailed information collected by that MBean as shown below:

Clicking on “Attributes” node shows the current snapshot of all the attributes exposed by the MBean as shown below:

Clicking on “Refresh” button will read the fresh values from the MBean.

Some MBeans expose functions as well. Such MBeans have “Operations” node and clicking on them show the functions exposed as shown below:

These functions can be invoked by clicking on the button in right-hand panel.

These snapshots are captured without even a single invocation of the application. Accessing “http://localhost:3000/” in a browser updates heap usage screenshot as shown below:

And permgen is increased because new classes are JITed by JRuby as shown below:

After a Garbage Collection is performed (by clicking on “Perform GC” button in “Memory” tab), the updated screenshot looks like:

As the snapshot indicates the “Heap Memory Usage” is back to normal (which indicates no memory leak) and there is a spike in “CPU Usage” because CPU cycles are used to perform GC.

Monitoring a Merb application is no different at all. The “Overview” tab for a trivial Merb app looks like:

The wide range of JMX-compatible tools is another advantage of using JRuby over MRI :)

Some other alternatives are using a combination of jps and jstat.

The JMX Home Page provides all details about JMX framework.  Subsequent blogs in this series will discuss:

  • How to remotely manage your Rails/Merb applications using JMX API ?
  • How to publish your own metrics that can be managed using JMX API ?
  • How to use VisualVM to get more information about the underlying VM ?
  • How to use NewRelic/FiveRuns to manage/monitor an application ?

How do you monitor your Rails or Merb applications ?

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all tips is available here.

Technorati: totd glassfish jruby rubyonrails merb jmx manage monitor

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #62: How to remotely manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX API ?
  2. TOTD #63: jmx4r gem – How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
  3. TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows
  4. TOTD #11: Setup Mongrel cluster for JRuby-on-Rails applications on Unix
  5. TOTD #105: GlassFish v3 Monitoring – How to monitor a Rails app using asadmin, JavaScript, jConsole, REST ?


  1. Thanks for this, I had no idea how to get started with JMX!

    Comment by Martijn — January 7, 2009 @ 10:05 am

  2. [Trackback] TOTD #61 showed how to manage/monitor a Rails/Merb application running using JRuby/GlassFish using standard Java tools. Both the application and the management tools are running on the same machine. But that’s never the case in a production environmen…

    Comment by Arun Gupta's Blog — January 8, 2009 @ 10:21 am

  3. [Trackback] TOTD #61 and TOTD #62 shows how to use JMX APIs to locally/remotely manage/monitor your Rails/Merb applications. This Tip Of The Day extends TOTD #62 and shows how remote management can be done using jmx4r gem. This gem provides…

    Comment by Arun Gupta's Blog — January 13, 2009 @ 10:54 am

  4. [Trackback] Here is a blog entry that was sitting in my Drafts folder for a long time (just because I didn’t realize :) . Anyway, it shows how to install Open Solaris 2008/11 on Virtual Box. The original install was done using…

    Comment by Arun Gupta's Blog — January 13, 2009 @ 10:56 am

  5. thnx u arun gupta.

    Comment by sinema izle — March 7, 2009 @ 3:46 pm

  6. i love to play all day on my gamecube. ;,”

    Comment by Andrea Watson — June 30, 2010 @ 1:14 am

  7. I like both the Gamecube and Xbox, we have them in our home office and also in our living room.”*~

    Comment by Julian Cooper — July 20, 2010 @ 12:01 pm

  8. i love to play on gamecubes and on psp machines, so addicting *

    Comment by Blake Rogers — September 1, 2010 @ 1:48 am

  9. i love both the gamecube and the nintendo DS, two of the best stuff you can get:.’

    Comment by UPVC Windows ` — October 11, 2010 @ 9:18 am

  10. wether it is gamecumbe or nintendo wii, what matters is great graphics and ergonomics:,`

    Comment by Surge Protectors : — October 23, 2010 @ 6:03 am

  11. i am addicted to computer games that is why i bought a gamecube for me and my brother ;”:

    Comment by Thermostatic Shower — December 13, 2010 @ 9:29 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress