pthulasiram / jmxetric

Automatically exported from code.google.com/p/jmxetric
MIT License
0 stars 0 forks source link

Attributes with composite values are not published correctly #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
- What steps will reproduce the problem?

1. Configure JMXetric via the usual XML file with at least one MBean
attribute that has a composite value, e.g.
java.lang:type=Memory.HeapMemoryUsage 

2. Make sure you configure JMXetric to publish more than one of the
composite's sub-attributes, e.g. init, committed, max and used in the case
of HeapMemoryUsage

3. Monitor the metrics published by JMXetric 

- What is the expected output? 

There should be a metric published at every sample interval for each
attribute, including each sub-attribute of all composites

- What do you see instead?

For each composite attribute, only the first sub-attribute in the config
file is published, the rest are missing

- What version of the product are you using? On what operating system?

jmxetric 0.0.3 on Linux

- Please provide any additional information below.

The example config in the project README file will produce this result;
only HeapMemoryUsage.init & NonHeapMemoryUsage.init are published. 

The cause seems to be that the equals() & hashCode() methods of the
MBeanAttribute class use attribute name, rather than canonical name, as the
identifier for an attribute. Since all composite attributes share the same
attribute name (e.g. HeapMemoryUsage), and they are stored in a HashSet in
the MBeanHolder class, only the first composite sub-attribute is
successfully stored. The call to attributes.add() in
MBeanHolder.addAttribute() (line 239 of MBeanSampler) only returns true for
the first composite sub-attribute. JMXetric subsequently only queries the
corresponding MBean for this sole attribute at publish time.

I think the fix is to change MBeanAttribute.hashCode() &
MBeanAttribute.equals() so the canonical name becomes the identifier for
all attributes, thus making it safe for composite and standard attributes
alike. I have attached amended versions of MBeanSamplerTest & MBeanSampler;
the modified sampleComposite() unit test of MBeanSamplerTest fails without
the changes to MBeanSampler.

Original issue reported on code.google.com by mickyfi...@googlemail.com on 11 Mar 2010 at 5:56

Attachments:

GoogleCodeExporter commented 8 years ago
Fixed on trunk as per your patch.  Thanks for the contribution!

Original comment by jasper...@gmail.com on 11 Mar 2010 at 8:06

GoogleCodeExporter commented 8 years ago
Issue 14 has been merged into this issue.

Original comment by jasper...@gmail.com on 1 Aug 2010 at 8:06