Over a million developers have joined DZone.

Thomas Enebo Releases JMX Gem

· Java Zone

Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience, brought to you in partnership with JetBrains

I wrote a JMX client library quite a while back and I finally got around to putting it on jruby-extras. To get the magic you can:
jruby -S gem install jmx

Once you have it you can do things like:
require 'jmx'

server = JMX.simple_server
client = JMX.connect
memory = client["java.lang:type=Memory"]

puts memory.heap_memory_usage.used
memory.gc
puts memory.heap_memory_usage.used

server.stop

Or even construct your own MBean from within Ruby code:

class MyDynamicMBean < RubyDynamicMBean
operation "Doubles a value"
parameter :int, "a", "Value to double"
returns :int
def double(a)
a + a
end
end
[see jmx/test/jmx_server_test.rb for details on how to register]

This library is still a little rough around the edges, but I have used it to great utility for debugging permgen memory issues. Charlie also recently just committed some MBeans for monitoring the JIT statistics (along with a way to flush the JIT cache). This client should be helpful for us to write some nice Ruby-friendly scripts to analyze a running instance.

Have fun and if you have questions come onto our IRC channel (#jruby at irc.freenode.net) or send an email to one of our mailing lists.

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}