Spring JMX + Hyperic

Zei7i

Grünschnabel
Hi Guys,

ich versuche eine Spring-Bean zu einer Mbean zu exportieren (Ich bin recht neu in Spring JMX)

Im Folgenden sind ein paar einfache Codeschnipsel zu sehen

ApplicationContext.xml:

<context:mbean-export/>

Die Spring-Bean welche ich zu einer Mbean exportieren möchte:

Code:
@Component
@Scope(value = "prototype")
@ManagedResource(objectName = "mymbean:name=AnyMBean", description = "anyMBean", log = true, logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200, persistLocation = "foo", persistName = "status")
public class ExampleClass implements IJmxExampleClassMbean {

  
  private int age=28;
  
  @ManagedOperation(description = "Add two numbers")
  @ManagedOperationParameters( { @ManagedOperationParameter(name = "x", description = "The first number"),
	  @ManagedOperationParameter(name = "y", description = "The second number") })
  public int add(final int x, final int y) {
	return x + y;
  }

  @ManagedAttribute(description = "The Age Attribute", currencyTimeLimit = 15)
  // @ManagedMetric(category = "age-category", displayName = "age", description = "How old are you", metricType = MetricType.GAUGE, unit =
  // "years", currencyTimeLimit = 1000, persistPolicy = "OnUpdate", persistPeriod = 200)
  public int getAge() {

	LOG.info("REQUEST: HOW OLD ARE YOU?");
	ArrayList<MBeanServer> findMBeanServer = MBeanServerFactory.findMBeanServer(null);
	Integer mBeanCount = findMBeanServer.get(0).getMBeanCount();
	ObjectInstance objectInstance;
	Object attribute;

	try {
	  objectInstance = findMBeanServer.get(0).getObjectInstance(ObjectName.getInstance("mymbean:name=GribFileJobMBean"));
	  attribute = findMBeanServer.get(0).getAttribute(objectInstance.getObjectName(), "age");
	} catch (InstanceNotFoundException e) {
	   e.printStackTrace();
	} catch (MalformedObjectNameException e) {
	   e.printStackTrace();
	} catch (NullPointerException e) {
	   e.printStackTrace();
	} catch (AttributeNotFoundException e) {
	  e.printStackTrace();
	} catch (MBeanException e) {
	  e.printStackTrace();
	} catch (ReflectionException e) {
	  e.printStackTrace();
	}
	return age;
  }
}

In der JConsole kann ich das Mbean sehen, allerdings schmeisst er bei dem Code:
findMBeanServer.get(0).getAttribute(objectInstance.getObjectName(), "age");

Das schmeisst:
javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for age.


Hyperic sagt das gleiche, wenn ich versuche das age Attribut als Metric darzustellen:
javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for age

Hat jemand Erfahrung damit ?

MfG
 

Neue Beiträge

Zurück