Search in sources :

Example 81 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadSingleBooleanValue.

@Test
public void canReadSingleBooleanValue() throws MalformedObjectNameException, InstanceNotFoundException {
    Attribute booleanAttribute = new Attribute("BootClassPathSupported", true);
    ObjectInstance runtime = getRuntime();
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, ImmutableList.of(booleanAttribute), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getAttributeName()).isEqualTo("BootClassPathSupported");
    assertThat(result.getValues()).hasSize(1);
    Object objectValue = result.getValues().get("BootClassPathSupported");
    assertThat(objectValue).isInstanceOf(Boolean.class);
    Boolean booleanValue = (Boolean) objectValue;
    assertThat(booleanValue).isEqualTo(TRUE);
}
Also used : Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 82 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method doesNotReorderTypeNames.

@Test
public void doesNotReorderTypeNames() throws MalformedObjectNameException {
    String className = "java.lang.SomeClass";
    String propertiesOutOfOrder = "z-key=z-value,a-key=a-value,k-key=k-value";
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), new ObjectInstance(className + ":" + propertiesOutOfOrder, className), ImmutableList.of(new Attribute("SomeAttribute", 1)), className, TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result integerResult = results.get(0);
    assertThat(integerResult.getTypeName()).isEqualTo(propertiesOutOfOrder);
}
Also used : Attribute(javax.management.Attribute) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) ObjectInstance(javax.management.ObjectInstance) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 83 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadSingleIntegerValue.

@Test
public void canReadSingleIntegerValue() throws MalformedObjectNameException, InstanceNotFoundException {
    Attribute integerAttribute = new Attribute("CollectionCount", 51L);
    ObjectInstance runtime = getRuntime();
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, ImmutableList.of(integerAttribute), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result integerResult = results.get(0);
    assertThat(integerResult.getAttributeName()).isEqualTo("CollectionCount");
    assertThat(integerResult.getValues()).hasSize(1);
    Object objectValue = integerResult.getValues().get("CollectionCount");
    assertThat(objectValue).isInstanceOf(Long.class);
    Long integerValue = (Long) objectValue;
    assertThat(integerValue).isEqualTo(51L);
}
Also used : Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 84 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canCreateBasicResultData.

@Test
public void canCreateBasicResultData() throws MalformedObjectNameException, InstanceNotFoundException {
    Attribute integerAttribute = new Attribute("StartTime", 51L);
    ObjectInstance runtime = getRuntime();
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, ImmutableList.of(integerAttribute), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result integerResult = results.get(0);
    assertThat(integerResult.getAttributeName()).isEqualTo("StartTime");
    assertThat(integerResult.getClassName()).isEqualTo("sun.management.RuntimeImpl");
    assertThat(integerResult.getKeyAlias()).isEqualTo("resultAlias");
    assertThat(integerResult.getTypeName()).isEqualTo("type=Runtime");
    assertThat(integerResult.getValues()).hasSize(1);
}
Also used : Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 85 with Attribute

use of javax.management.Attribute in project hadoop by apache.

the class MetricsSourceAdapter method setAttrCacheMetric.

private void setAttrCacheMetric(AbstractMetric metric, int recNo) {
    String key = metricName(metric.name(), recNo);
    attrCache.put(key, new Attribute(key, metric.value()));
}
Also used : Attribute(javax.management.Attribute)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9