Monitoring Weblogic 9.2 with JMX and JRuby
17 April, 2008 – 11:23 amAfter getting nowhere with lack luster HP support, I turned to the power of the Open Source community and got a very simple script up and running to remotely monitor Weblogic JVM Performance and JMS queues using JMX and JRuby.
Despite having some initial issues with the code, the author of the jmx4r module turned around a fix inside 24 hours so that I could connect to a Weblogic 9.2 server and look at its domainruntime MBeans. SiteScope can’t handle domainruntimes of these size (short of being told to ‘add more memory’ to a 3GB+ machine!). So exit stage left Mercury, enter stage right JRuby…
This script will enumerate JVM performance and also JMS queue depths in around 65 lines of code and spits those results into a MySQL database using the mysqlimport CLI.
I’ve formatted the output so I can still input the data into LoadRunner Analysis.
1 2 3 4 5 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | require 'rubygems' require 'jmx4r' groupid = "mycluster" JMX::MBean.establish_connection :url => "service:jmx:rmi:///jndi/iiop://hostname:7001/weblogic.management.mbeanservers.domainruntime", :username => "username", :password => "password" open( 'D:\perf_jvm.csv', 'a') do |file| runtime_mbeans = JMX::MBean.find_all_by_name "com.bea:Type=JRockitRuntime,*" runtime_mbeans.each do | mbean | now = Time.now date = "#{now.year}-#{now.month}-#{now.day}" time = "#{now.hour}:#{now.min}:#{now.sec}" data = [] if(mbean.object_name.get_key_property("Name") =~ /server/) then data << "" data << date data << time data << groupid data << mbean.object_name.get_key_property("Name") data << mbean.used_physical_memory data << mbean.heap_size_max data << mbean.free_physical_memory data << mbean.total_garbage_collection_time data << mbean.total_garbage_collection_count data << mbean.total_nursery_size data << mbean.heap_free_percent file.puts data.compact.join(", ") end end end cmd = 'D:\\wamp\\bin\\mysql\\mysql5.0.51a\\bin\\mysqlimport -h localhost -P 3390 -s -u root --fields-optionally-enclosed-by=""" --fields-terminated-by=, --lines-terminated-by="\n" --local sensis D:\perf_jvm.csv' puts %x{#{cmd}} cmd = 'cat D:\perf_jvm.csv >> D:\perf_jvm_archive.csv' puts %x{#{cmd}} File.delete 'D:\perf_jvm.csv' open( 'D:\perf_queues.csv', 'a') do |file| runtime_mbeans = JMX::MBean.find_all_by_name "com.bea:Type=JMSDestinationRuntime,*" runtime_mbeans.each do | mbean | now = Time.now date = "#{now.year}-#{now.month}-#{now.day}" time = "#{now.hour}:#{now.min}:#{now.sec}" data = [] if(mbean.object_name.get_key_property("Name") =~ /Module/) then data << "" data << date data << time data << groupid data << mbean.object_name.get_key_property("Name") data << mbean.messages_received_count data << mbean.messages_high_count file.puts data.compact.join(", ") end end end cmd = 'D:\\wamp\\bin\\mysql\\mysql5.0.51a\\bin\\mysqlimport -h localhost -P 3390 -s -u root --fields-optionally-enclosed-by=""" --fields-terminated-by=, --lines-terminated-by="\n" --local sensis D:\perf_queues.csv' puts %x{#{cmd}} cmd = 'cat D:\perf_queues.csv >> D:\perf_queues_archive.csv' puts %x{#{cmd}} sleep 10 File.delete 'D:\perf_queues.csv' |








