Search in sources :

Example 21 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxGetTest method testGetRootMetricWithAttributePattern.

@Test
public void testGetRootMetricWithAttributePattern() throws MalformedObjectNameException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye", JmxType.MONOTONICALLY_INCREASING));
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*,key2=*", "TheRoot/Wahoo/{:attr1:}/", metrics, null, null);
    ObjectName objectName = new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2");
    MBeanServer server = getServer();
    Mockito.when(server.getAttribute(objectName, "attr1")).thenReturn("dude");
    String root = object.getRootMetricName(objectName, server);
    Assert.assertEquals("JMX/TheRoot/Wahoo/dude/", root);
}
Also used : ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 22 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsSubTypeMonoMulti.

@Test
public void jmxMetricRecordStatsSubTypeMonoMulti() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create(new String[] { "first", "second" }, "theDiff", JmxAction.SUBTRACT_ALL_FROM_FIRST, JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("first", 10f);
    values.put("second", 7f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theDiff").getCallCount());
    Assert.assertEquals(3f, stats.getStats("Jmx/Sample/theDiff").getTotal(), .001);
    values.clear();
    actual.clear();
    values.put("first", 12f);
    values.put("second", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/theDiff").getCallCount());
    Assert.assertEquals(7f, stats.getStats("Jmx/Sample/theDiff").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 23 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsMonotonicallyForMultiBean.

@Test
public void jmxMetricRecordStatsMonotonicallyForMultiBean() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    actual.clear();
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(7f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 24 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsChangeNameSimpleMultiAdd.

@Test
public void jmxMetricRecordStatsChangeNameSimpleMultiAdd() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", "theHello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    Assert.assertEquals(0, stats.getStats("Jmx/Sample/theHello").getCallCount());
    values.clear();
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/theHello").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 25 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsChangeNameSimpleMulti.

@Test
public void jmxMetricRecordStatsChangeNameSimpleMulti() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", "theHello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/theHello").getTotal(), 0);
    values.clear();
    values.put("hello", 7f);
    actual.clear();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/theHello").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Aggregations

JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)32 Test (org.junit.Test)29 HashMap (java.util.HashMap)21 StatsEngine (com.newrelic.agent.stats.StatsEngine)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)20 ObjectName (javax.management.ObjectName)12 ArrayList (java.util.ArrayList)11 MBeanServer (javax.management.MBeanServer)5 Map (java.util.Map)3 BaseJmxValue (com.newrelic.agent.jmx.metrics.BaseJmxValue)1