ganglia / jmxetric

Java JVM instrumentation to Ganglia
MIT License
76 stars 38 forks source link

Use of patterns in mbean parameter name doesn't work #3

Open ghost opened 11 years ago

ghost commented 11 years ago

Hello according to http://docs.oracle.com/javase/7/docs/api/javax/management/ObjectName.html it is possible to use patterns in the objectName. If I use a pattern in the mbean parameter. f.i. name="org.eclipse.jetty.server:type=connectorstatistics,*" Then Jmxetric doesn't collect the counters

dpocock commented 10 years ago

Confirmed

a) the code needs to be patched to detect when a pattern has been supplied

b) it also needs to detect when attributes come and go dynamically at runtime

ngzhian commented 10 years ago

When a pattern is specified in the configuration file, for example <mbean name="*:type=Memory" pname="Memory">, which should match any domains, e.g. java.lang, or org.apache.karaf, how should we interpret this? This seems to be logical: only the specified attributes of this mbean, which can be of ANY domain with type=Memory, for example:

<mbean name="*:type=Memory" pname="Memory">
  <attribute name="HeapMemoryUsage">
  <composite name="init" pname="Heap_init" type="int32" units="bytes"/>
  <composite name="committed" pname="Heap_committed" type="int32" units="bytes"/>
  <composite name="used" pname="Heap_used" type="int32" units="bytes" />
  <composite name="max" pname="Heap_max" type="int32" units="bytes" />
</attribute>
</mbean>

will match the attribute HeapMemoryUsage of ANY domain with type=Memory.

ngzhian commented 10 years ago

Object o = mbs.getAttribute(new ObjectName("*:type=Threading"), "ThreadCount"); just results in a InstanceNotFoundException being thrown. The way that JMXetric currently retrieves the values of MBeans is the same way,

Object o = mbs.getAttribute(objectName, attributeName);

This means that we cannot naively use the pattern ObjectName.

One way to do this is to list all MBeans using queryMBeans passing in null arguments, as described here, and doing a check if the names matches using the apply method

dpocock commented 10 years ago

There is one further aspect to this - we probably need to support regex "groups" in the pattern and then extract the string in the group and use it to create the metric names sent to Ganglia.

ngzhian commented 10 years ago

One way of doing so is (in pseudo code)

if ObjectName contains pattern
  loop through all available mbeans
    if mbean matches this ObjectName
      add to the MBeanSampler with specific MBean name (no patterns)
else
  add to MBeanSampler
ngzhian commented 10 years ago

There are two possible places we can translate the patterns to actual object names, when reading in the XML configuration (1), or just before publishing (2).

(1) will mean that the reading of XML depends on a MBeanServer. If we do this, we can make use of this dependency to discard bad configurations, e.g. MBeans that we cannot access, or do not exist

(2) will require us to do the checking of pattern names and testing the patterns again all available MBeans in the publish method, which seems to be beyond the responsibility of MBeanAttribute.

I will make a new branch to pursue (1) and see how it fares.