Skip to content

Ramblings

Musings of Matt Williams
  • Blog
  • About
  • Chibi
  • Ruby Blender
  • Archives
  • Log in
 
Less
More
Trim
Untrim
« Older
Home
Loading
Newer »
Archive for the 'monitoring' Category
22Sep08 JRuby + jmx4r + rrd4j == Easy reporting on app servers (part I)
howto jruby monitoring programming
2 Comments

This is a how-to for using jmx and rrd4j, a java implementation of rrdtool, to report on app server statistics.

Thanks to Jeff Mesnil(author of jmx4r), Werner Schuster (JMX the Ruby way with jmx4r), sishen (JRobin sucks), and the rrd4j team.

You’ll need the following:

  1. JVM 1.5 or higher — JRE is not enough, you also need the JDK. Remember to set your JAVA_HOME — JRuby needs it.
  2. JRuby — I’m using 1.1.4. Note: You need to be sure to set the JRUBY_HOME and make sure that ${JRUBY_HOME}/bin comes in $PATH prior to any other ruby installation. Otherwise, your results will be indeterminate.
  3. jmx4r — this is a gem and can be installed by
    jruby -S gem install jmx4r
  4. rrd4j — in order to get this, you need to create an account on java.net. Once you’ve done that, you can download the library via subversion:
    svn co https://rrd4j.dev.java.net/svn/rrd4j/trunk rrd4j --username <em>username</em>

    Replace username with your java.net username. You’ll need ant to build it:

    cd rrd4j/rrd4j; ant

    Or you can download the jars: rrd4j jars

  5. An application which responds to jmx queries — this example is using jconsole since it is a standard part of the java distribution in 1.5 and after.

Before we do much else, let’s verify that jconsole is working:

jconsole -J-Dcom.sun.management.jmxremote.port=64850 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false

Choose for the port some large nuimber…  Your screen will look something like this for 1.5 (ignore the cutoff bits, I’m writing this on chibi):

Portion of a JConsole screen

Portion of a JConsole screen

Ok, now that we’ve got that going, let’s attempt connecting via jmx4r…

$ jruby -S jirb
irb(main):001:0&gt; require 'rubygems'
=&gt; true
irb(main):002:0&gt; require 'jmx4r'
=&gt; true
irb(main):003:0&gt; require 'java'
=&gt; false
irb(main):004:0&gt; JMX::MBean.establish_connection :host =&gt; "localhost", :port =&gt; 64850
=&gt; #&lt;#:0x1bd06a0 @java_object=javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection@12f9ee1&gt;
irb(main):005:0&gt; memory =JMX::MBean.find_by_name "java.lang:type=Memory"
=&gt; #"NonHeapMemoryUsage", "verbose"=&gt;"Verbose", "object_pending_finalization_count"=&gt;"ObjectPendingFinalizationCount", "heap_memory_usage"=&gt;"HeapMemoryUsage"}, @mbsc=#&lt;#:0x1bd06a0 @java_object=javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection@12f9ee1&gt;, @operations={"gc"=&gt;["gc", []]}, @object_name=#&gt;
irb(main):006:0&gt; memory.heap_memory_usage
=&gt; #
irb(main):012:0&gt; memory.heap_memory_usage.keys
=&gt; #&lt;#:0x129dcc0 @java_object=[committed, init, max, used]&gt;
irb(main):015:0&gt; memory.heap_memory_usage.to_s
=&gt; "javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=7569408, init=0, max=66650112, used=3952968})"
irb(main):020:0&gt; memory.heap_memory_usage["committed"]
=&gt; 7569408
irb(main):021:0&gt; #trigger a gc
irb(main):022:0* memory.gc
=&gt; nil
irb(main):023:0&gt; memory =JMX::MBean.find_by_name "java.lang:type=Memory"
=&gt; #"NonHeapMemoryUsage", "verbose"=&gt;"Verbose", "object_pending_finalization_count"=&gt;"ObjectPendingFinalizationCount", "heap_memory_usage"=&gt;"HeapMemoryUsage"}, @mbsc=#&lt;#:0x1bd06a0 @java_object=javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection@12f9ee1&gt;, @operations={"gc"=&gt;["gc", []]}, @object_name=#&gt;
irb(main):024:0&gt; memory.heap_memory_usage["committed"]
=&gt; 7569408
irb(main):026:0&gt; memory.heap_memory_usage["max"]
=&gt; 66650112
irb(main):027:0&gt; memory.heap_memory_usage["used"]
=&gt; 4210824
irb(main):028:0&gt; exit
$

Cool! now we’re making progress!

 
Browse Archives »
  • administrivia (6)
  • books (1)
  • Computers (2)
  • css (3)
  • eating crow (1)
  • games (1)
  • glassfish (1)
  • gotchas (16)
  • howto (2)
  • idiocy (3)
  • javascript (4)
  • jboss (4)
  • jruby (6)
  • Just Enough Programming (7)
  • life hacking (2)
  • mini sagas (1)
  • miscellany (1)
  • monitoring (1)
  • mysql (1)
  • philosophy (4)
  • php (1)
  • programming (17)
  • rails (6)
  • rants (2)
  • refactoring (1)
  • ruby (14)
  • tips (9)
  • tools (2)
  • Uncategorized (9)
  • utilities (3)
  • web (5)
  • web design (3)
 

Latest

  • Rails & JRuby in a Jar
  • Fractal Terrain Generation
  • Quick thought on programming and distractions
  • Using jnp as a JBoss heartbeat
  • z-index and events
  • JBoss port confusion
  • SSL Joys
  • After long silence
  • New Ruby Blog
  • Javascript with CSS Sprites Animation

Flickr

layout_newm3headerTerrain Testa

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Search

Browse by Category

  • administrivia (6)
  • books (1)
  • Computers (2)
  • css (3)
  • eating crow (1)
  • games (1)
  • glassfish (1)
  • gotchas (16)
  • howto (2)
  • idiocy (3)
  • javascript (4)
  • jboss (4)
  • jruby (6)
  • Just Enough Programming (7)
  • life hacking (2)
  • mini sagas (1)
  • miscellany (1)
  • monitoring (1)
  • mysql (1)
  • philosophy (4)
  • php (1)
  • programming (17)
  • rails (6)
  • rants (2)
  • refactoring (1)
  • ruby (14)
  • tips (9)
  • tools (2)
  • Uncategorized (9)
  • utilities (3)
  • web (5)
  • web design (3)

Browse by Tag

  • 1.2.6
  • 2.1
  • administrivia
  • autotest
  • books
  • controller
  • css
  • feed-normalizer
  • feeds
  • gotchas
  • idiocy
  • irb
  • Java
  • javascript
  • jboss
  • jruby
  • just enough programming
  • mini sagas
  • open-uri
  • philosophy
  • php
  • pragmatism
  • programming
  • quotations
  • rails
  • rants
  • reading
  • restful_authentication
  • rspec
  • rss
  • ruby
  • rubygems
  • scriptaculous
  • setup
  • simplicity
  • sprites
  • statemachine
  • tips
  • treetop
  • utilities
  • web
  • web design
  • websense
  • yaml
  • zentest

Browse by Month

  • March 2010 (1)
  • September 2009 (1)
  • August 2009 (2)
  • July 2009 (2)
  • May 2009 (1)
  • April 2009 (1)
  • February 2009 (4)
  • January 2009 (2)
  • December 2008 (2)
  • November 2008 (5)
  • October 2008 (3)
  • September 2008 (12)
  • August 2008 (28)
 
 
  • Blog
  • About
  • Chibi
  • Ruby Blender
  • Archives
  • Log in
 


Theme Design by Jay Kwong | Powered by WordPress and K2

 

Home Top Archives Entries FeedComments Feed