Search in sources :

Example 11 with JmxMetric

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

the class JmxMetricTest method jmxMetricRecordStatsSimpleForMultiBean.

@Test
public void jmxMetricRecordStatsSimpleForMultiBean() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", 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/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    actual.clear();
    values.put("hello", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(10f, 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 12 with JmxMetric

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

the class JmxMetricTest method jmxMetricRecordStatsSimple.

@Test
public void jmxMetricRecordStatsSimple() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(10f, 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 13 with JmxMetric

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

the class JmxMetricTest method jmxMetricRecordStatsMonotonicallyForMultiBeanAdd.

@Test
public void jmxMetricRecordStatsMonotonicallyForMultiBeanAdd() {
    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);
    values.clear();
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(12f, 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 14 with JmxMetric

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

the class JmxGetTest method testGetRootMetricWithNonExistAllKeys.

@Test
public void testGetRootMetricWithNonExistAllKeys() throws MalformedObjectNameException {
    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/{blabla}/{keydoesnotexist}/", metrics, null, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/TheRoot/Wahoo///", root);
}
Also used : ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 15 with JmxMetric

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

the class JmxGetTest method testGetRootMetricWithPatternMissingEndSlash.

@Test
public void testGetRootMetricWithPatternMissingEndSlash() throws MalformedObjectNameException {
    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/{type}/{key1}", metrics, null, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/TheRoot/Wahoo/rara/value1/", root);
}
Also used : ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) ObjectName(javax.management.ObjectName) 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