Skip to main content

Administration and Monitoring of Ruby applications on GlassFish v3

Posted by vivekp on December 10, 2009 at 9:37 AM PST

GlassFish v3 final has monitoring and administration support for Ruby on Rails or any Ruby Rack based application. Here is how you would go about administering and monitoring your Ruby on Rails application on GlassFish v3:


GlassFish v3

First you need to install GlassFish v3. Get it from here. After the download simply unzip it to the directory of your choice.


Install JRuby 1.4.0 using updatetool

$ /tools/glassfishv3/bin/updatetool

Select JRuby 1.4.0 and click install. JRuby along with Rails 2.3.5, Merb, MySQL JDBC adapters will be installed inside glasfishv3/GlassFish/jruby. Now add it to your path.

$ export JRUBY_HOME=/tools/glasfishv3/GlassFish/jruby

Install JRuby 1.4.0 from

Alternatively you can install JRuby form You would also need to install any gem that your application will depend on, such as Rails, Merb, Sinatra or simply Rack incase you are writing your own Rack based framework. You would setup JRUBY_HOME and PATH accordingly.


Before you begin, first start GlassFish v3 server

$ glassfishv3/bin/asadmin start-domain


In case you are using your own JRuby installation then you need to tell GlassFish where to find it. There are 2 ways you can do it. Using asadmin CLI or using Admin console.

asadmin CLI

$asadmin configure-jruby-container --jruby-home=/tools/jruby-1.4.0

Admin console

In your browser type: http://localhost:4848, then select Configure=>Ruby container and then enter JRuby instalation in JRuby Home field and click Ok.

Ruby Container configuration

JRuby Runtime Pool

You can also setup JRuby runtime pool if you chose to run Rails or any other Ruby framework in non-threadsafe mode. This setting is recommended to be used only for production and for most optimal performance its advised to keep the initial, min and max values same. Basically freeze the pool so that it does not auto adjust between min and max values. Creation of JRuby runtime is a very expensive process, both in terms of time and resources, so you want to be careful with that specially in production uses. You can use the same screen where you setup JRuby Home to configure the runtime pool settings.

Here is how you can  configure JRuby runtime pool using asadmin CLI

$ asadmin configure-jruby-container --jruby-runtime=2 --jruby-runtime-min=2 --jruby-runtime-max=2


GlassFish v3 monitoring infrasutructure lets each of the container define their own set of probes and expose these as dTrace or view the stats using container exposed statistics or you can write javscript code and use the monitoring REST based services to collect the stats of your choice. For details on GlassFish v3 monitoring see Prashant's excellent blog.

asadmin CLI

Here is how you can configuring monitoring for Ruby applications using asadmin CLI

$ asadmin configure-jruby-container --monitoring=true

Setting --monitoring to false will simply disable it.

Admin console

Ruby monitoring configuration

Develop a Ruby application

Now that you have installed GlassFish v3 and JRuby and configured the JRuby container, runtime pool etc. Its time to develop a Ruby web application. To keep this blog simple, I would go for an extremely simple Rackup script

class HelloWorld
  def call(env)
    [200, {"Content-Type" =>"text/plain"}, ["Hello world!"]]

In the above code HelloWorld class is a Rack application. A Rack application is the one that responds to call and returns array of HTTP status code, HTTP headers and the content. HelloWorld simply returns "HelloWorld!" as the content body.

Now lets deploy it.


Assuming you are in the directory where file is located. Do the following to deploy on GlassFish:

$ asadmin deploy .

If you want to deploy using some other version of JRuby, lets say you have JRuby and want to deploy using this version of JRuby, this is what you would do:

$ asadmin deploy --property jruby.home=/tools/ .

If you don't like doing it using asadmin CLI, you can use admin console as well. Simply login to http://locahost:4848/ and chose applications node and on deployment screen chose applicaton type as Ruby Application. See the image below

Ruby Deployment

Now Run...

Now access the application at http://localhost:8080/rack/


monitoring stats

In earlier step we have already enabled monitoring so now you can use JConsol or Admin console or use asadmin CLI to monitor the stats. You can also use dTrace as well. Let see how you would use Admin console to monitor your stats. Go to http://localhost:4848/ and select Enterprise Server and then Monitor tab. You should see different stats such as JRuby Runtme Pool, HTTP and JRuby container stats.

Monitoring 1

Go get GlassFish v3 and start running, monitoring your Ruby on Rails or Merb or Sinatra or any Rack application. Send us your comments at

Related Topics >>