Friday January 09, 2009
TOTD #63: jmx4r gem - How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
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 a clean mapping between JMX APIs and Ruby. It allows
to write pure Ruby code to manage/monitor any Rails application. As a
result it removes all dependency on the Java code used in TOTD
#62.
Lets first install the gem!
| ~ >gem
install jmx4r JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed jmx4r-0.0.6 1 gem installed Installing ri documentation for jmx4r-0.0.6... Installing RDoc documentation for jmx4r-0.0.6... |
| require 'rubygems' require 'jmx4r' JMX::MBean.establish_connection :host => "129.145.133.163", :port => 8686 beans = JMX::MBean.find_all_by_name "org.jruby:*" beans.each { |bean| service = bean.object_name["service"] case service when "ClassCache" @cc_mbean = bean when "Config" @c_mbean = bean end } # clear the cache if it's full if @cc_mbean.full printf "JIT Max: %d, JIT Threshold: %d, Class load count: %d\n", @c_mbean.jit_max, @c_mbean.jit_threshold, @cc_mbean.class_load_count @cc_mbean.flush else puts "Class Cache is not full" printf "Loaded: %d, Reused: %d, Live: %d\n", @cc_mbean.class_load_count, @cc_mbean.class_reuse_count, @cc_mbean.live_class_count end |
| jruby main.rb |
| Class Cache is not full Loaded: 76, Reused: 0, Live: 76 |
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Thursday January 08, 2009
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 environment. Instead remote
management of an application is required when running in production
mode. Fortunately, similar set of tools can be used for remote
management as well.
However the underlying Java Virtual Machine needs to be configured to
enable remote monitoring. This is achieved by setting JAVA_OPTS
environment variables as shown below:
Set up the following envinronment variable before running the
Rails/Merb application:
| export JAVA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8686
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false" |
| service:jmx:rmi:///jndi/rmi://192.168.124.1:8686/jmxrmi |
| jconsole |



| include Java import java.io.IOException import java.util.HashSet import java.util.Set import javax.management.JMRuntimeException import javax.management.MBeanServerConnection import javax.management.MalformedObjectNameException import javax.management.ObjectName import javax.management.JMX import javax.management.remote.JMXConnector import javax.management.remote.JMXConnectorFactory import javax.management.remote.JMXServiceURL import org.jruby.management.ClassCacheMBean import org.jruby.management.ConfigMBean url = JMXServiceURL.new "service:jmx:rmi:///jndi/rmi://192.168.124.1:8686/jmxrmi" mbsc = JMXConnectorFactory.connect(url, nil).get_mbean_server_connection names = HashSet.new(mbsc.query_names(ObjectName.new("org.jruby:*"), nil)) names.each { |name| service = name.get_key_property "service" if service == "ClassCache" @cc_mbean = JMX.new_mbean_proxy(mbsc, name, Java::org.jruby.management.ClassCacheMBean.java_class) elsif service == "Config" @c_mbean = JMX.newMBeanProxy(mbsc, name, Java::org.jruby.management.ConfigMBean.java_class) end } # clear the cache if it's full if @cc_mbean.is_full puts @c_mbean.get_jit_max puts @c_mbean.get_jit_threshold puts @cc_mbean.get_class_load_count @cc_mbean.flush else puts "Class Cache is not full" printf "Loaded: %d, Reused: %d, Live: %d\n", @cc_mbean.get_class_load_count, @cc_mbean.get_class_reuse_count, @cc_mbean.get_live_class_count end |
Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Wednesday January 07, 2009
TOTD #61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?
![]() |
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. |
| jconsole |












Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Today's Page Hits: 2926
Total # blog entries: 1001
| « November 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 4 | 6 | 7 | ||
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
| Today | ||||||