Giter VIP home page Giter VIP logo

jmx's People

Contributors

bpardee avatar enebo avatar headius avatar tobias avatar trevmex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jmx's Issues

Extended MBeans don't have parents operations/attributes.

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

MBeans created by another MBean don't have attributes/operations show up

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

Gem doesn't allow specifying a service url

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

MBeanServer#[] crashes in const_defined? when MBean class name contains $

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:ingenerate'
from /home/ses/.rvm/gems/jruby-1.6.7@production-simulator/gems/jmx-0.7/lib/jmx/server.rb:44:in []' from (irb):4:inevaluate'
from org/jruby/RubyKernel.java:1088:in eval' from org/jruby/RubyKernel.java:1410:inloop'
from org/jruby/RubyKernel.java:1197:in catch' from org/jruby/RubyKernel.java:1197:incatch'
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:inconst_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:ineval'
from org/jruby/RubyKernel.java:1410:in loop' from org/jruby/RubyKernel.java:1197:incatch'
from org/jruby/RubyKernel.java:1197:in catch' from /home/ses/.rvm/rubies/jruby-1.6.7/bin/jirb:17:in(root)'

setAttributes is internally using invoke on MBean

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 ?

MBean attributes shouldn't be tied to MBean instance variables.

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?

JMX::MBeans.parent_for unreliable in Jruby 9000

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.