enebo / jmx Goto Github PK
View Code? Open in Web Editor NEWJMX
Home Page: http://www.jruby.org
License: MIT License
JMX
Home Page: http://www.jruby.org
License: MIT License
The example shows what happens when trying to access a logback statistics appender bean
It's class name is:
com.yammer.metrics.reporting.JmxReporter$Meter
and that seems to be the reason for the following crash
jruby-1.6.7 :003 > client = JMX.connect(:port => 8999)
=> #<JMX::MBeanServer:0x32bed1fd @server=#<#Class:0x5b08ea49:0x62bc36ff>>
jruby-1.6.7 :004 > client['ch.qos.logback.core:type=Appender,name=all']
NameError: wrong constant name JmxReporter$Meter
from org/jruby/RubyModule.java:2561:in const_defined?' from /home/ses/.rvm/gems/jruby-1.6.7@production-simulator/gems/jmx-0.7/lib/jmx.rb:107:in
generate'
from /home/ses/.rvm/gems/jruby-1.6.7@production-simulator/gems/jmx-0.7/lib/jmx/server.rb:44:in []' from (irb):4:in
evaluate'
from org/jruby/RubyKernel.java:1088:in eval' from org/jruby/RubyKernel.java:1410:in
loop'
from org/jruby/RubyKernel.java:1197:in catch' from org/jruby/RubyKernel.java:1197:in
catch'
from /home/ses/.rvm/rubies/jruby-1.6.7/bin/jirb:17:in (root)' jruby-1.6.7 :005 > client['ch.qos.logback.core:type=Appender,name=error'] NameError: wrong constant name JmxReporter$Meter from org/jruby/RubyModule.java:2561:in
const_defined?'
from /home/ses/.rvm/gems/jruby-1.6.7@production-simulator/gems/jmx-0.7/lib/jmx.rb:107:in generate' from /home/ses/.rvm/gems/jruby-1.6.7@production-simulator/gems/jmx-0.7/lib/jmx/server.rb:44:in
[]'
from (irb):5:in evaluate' from org/jruby/RubyKernel.java:1088:in
eval'
from org/jruby/RubyKernel.java:1410:in loop' from org/jruby/RubyKernel.java:1197:in
catch'
from org/jruby/RubyKernel.java:1197:in catch' from /home/ses/.rvm/rubies/jruby-1.6.7/bin/jirb:17:in
(root)'
I have the following test program. If I perform a create_mbean, the 2nd mbean shows up in jconsole but it doesn't have any of its attributes or operations.
require 'rubygems'
require 'jmx'
$jmx_server = JMX::MBeanServer.new
$domain = 'MyDomain'
class MyDynamicMBean < RubyDynamicMBean
operation "Doubles a value"
parameter :int, "a", "Value to double"
returns :int
def double(a)
a + a
end
operation "Doubles a string"
parameter :string, "a", "Value to double"
returns :string
def string_double(a)
a + a
end
operation "Creates a new MBean"
returns :string
def create_mbean
bean = MyTrulyDynamicMBean.new($domain, "Created MBean")
puts "Registering created mbean"
$jmx_server.register_mbean(bean, "#{$domain}:type=Test2")
"success"
end
end
class MyTrulyDynamicMBean < RubyDynamicMBean
operation "Give me foo"
returns :string
def foo
"foo"
end
operation "Concatentates a list"
parameter :list, "list", "List to concatenate"
returns :string
def concat(list)
list.inject("") { |memo, element| memo << element.to_s }
end
end
bean = MyDynamicMBean.new($domain, "Initial MBean")
puts "Registering initial mbean"
$jmx_server.register_mbean(bean, "#{$domain}:type=Test")
sleep 1000
If you derive an MBean from another, it doesn't pick up the operations/attributes defined in the parent. Here is a small test program that demonstrates the issue:
require 'rubygems'
require 'jmx'
$jmx_server = JMX::MBeanServer.new
$domain = 'MyDomain'
class MyMBean < RubyDynamicMBean
operation "Doubles a value"
parameter :int, "a", "Value to double"
returns :int
def double(a)
a + a
end
end
class MyExtendedMBean < MyMBean
operation "Triples a value"
parameter :int, "a", "Value to triple"
returns :int
def triple(a)
3 * a
end
end
bean = MyExtendedMBean.new($domain, "Initial MBean")
$jmx_server.register_mbean(bean, "#{$domain}:type=Test")
sleep 1000
There is no option to specify a full service URL in place of a hostname and port. This is useful when accessing JMX through a firewall.
changing the options to something like:
url = opts[:raw_url] || "service:jmx:rmi:///jndi/rmi://#{host}:#{port}#{url_path}"
would allow you to use a service url such as: service:jmx:rmi://:10002/jndi/rmi://:10001/jmxrmi
It seems the DynamicMbean class's method setAttributes is calling the invoke method on the MBean and not the setAttributes method itself.
The problem I am facing is that the server code I work with is written in such a way that only the attributes set through the setAttributes method are persisted in Database,
Is there a way I can bypass this method and directly use the Mbean's setAttributes method ?
test.rb:
require 'jmx'
client = JMX.connect(:host => 'localhost', :port => 9999)
puts client["JMImplementation:type=MBeanServerDelegate"].attributes
Running in JRuby 1.7:
$ rbenv global jruby-1.7.14
$ ruby -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=9999 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false test.rb
MBeanServerId
SpecificationName
SpecificationVersion
SpecificationVendor
ImplementationName
ImplementationVersion
ImplementationVendor
Running in JRuby 9000:
$ rbenv global jruby-9.0.3.0
$ ruby -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=9999 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false test.rb
ArgumentError: Java package `javax' does not have a method `const_set'
method_missing at uri:classloader:/jruby/java/java_package_module_template.rb:13
block in parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:20
each at org/jruby/RubyArray.java:1560
inject at org/jruby/RubyEnumerable.java:895
parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:12
generate at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbean_proxy.rb:30
[] at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/server.rb:46
<top> at test.rb:4
I also have similar problems when the ObjectName's class name is "com.x.y.z". And I can easily force the issue by just calling Java::Com
or Java::Sun
before accessing an ObjectName whose class name path is sun.x.y or com.x.y.
I.e.
require 'jmx'
Java::Sun
client = JMX.connect(:host => 'localhost', :port => 9999)
puts client["java.lang:type=Memory"].attributes
results in
$ rbenv global jruby-9.0.3.0
$ ruby -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=9999 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false test.rb
ArgumentError: Java package `sun' does not have a method `const_set'
method_missing at uri:classloader:/jruby/java/java_package_module_template.rb:13
block in parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:20
each at org/jruby/RubyArray.java:1560
inject at org/jruby/RubyEnumerable.java:895
parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:12
generate at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbean_proxy.rb:30
[] at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/server.rb:46
<top> at test.rb:5
but this doesn't force the problem in JRuby 1.7, it still prints the attributes for that object name.
It would be nice if the attributes checked for accessor methods as well as instance variables as I use my mbean as a proxy into another object that's actually doing the work. I tried to fix this by the following changes to dynamic_mbean which works in simple test cases but I see 'Not Allowed' or something like that in my program.
- javax.management.Attribute.new name, value_proc.call(instance_variable_get('@' + name))
+ javax.management.Attribute.new name, value_proc.call(send name)
- instance_variable_set '@' + name, value_converter.call(value)
+ send name+'=', value_converter.call(value)
I would think that this would work since my understanding is that attr_accessor is just a shortcut which defines the get/set methods for you so if you defined them then it would redefine the methods created by attr_accessor?
It currently calls java_args(args), instead of java_args(signature, args). I would fix it, but I don't know what signature should be in this case.
Which is causing confusion. See: torquebox/backstage#21
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.