Search in sources :

Example 31 with JmxMetric

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

the class JmxGetTest method testJmxGetStats.

@Test
public void testJmxGetStats() throws MalformedObjectNameException {
    StatsEngine stats = new StatsEngineImpl();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    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=*", "ThreadPool:type=rara,key1=*", null, metrics, null, null);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    values.put("goodbye", 4f);
    object.recordStats(stats, createMap("ThreadPool:type=rara,key1=a", values), server);
    Assert.assertEquals(5f, stats.getStats("JMX/ThreadPool/rara/a/hello").getTotal(), .001);
    Assert.assertEquals(4f, stats.getStats("JMX/ThreadPool/rara/a/goodbye").getTotal(), .001);
    values.clear();
    values.put("hello", 6f);
    values.put("goodbye", 7f);
    object.recordStats(stats, createMap("ThreadPool:type=rara,key1=a", values), server);
    Assert.assertEquals(11f, stats.getStats("JMX/ThreadPool/rara/a/hello").getTotal(), .001);
    Assert.assertEquals(7f, stats.getStats("JMX/ThreadPool/rara/a/goodbye").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 32 with JmxMetric

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

the class JmxGetTest method testJmxGetStatsMulti.

@Test
public void testJmxGetStatsMulti() throws MalformedObjectNameException {
    StatsEngine stats = new StatsEngineImpl();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello1", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye1", JmxType.MONOTONICALLY_INCREASING));
    JmxGet object = new JmxMultiMBeanGet("ThreadPool:type=rara,key1=*", "ThreadPool:type=rara,key1=*", null, metrics, null, null);
    Map<String, Float> values = new HashMap<>();
    values.put("hello1", 5f);
    values.put("goodbye1", 4f);
    object.recordStats(stats, createMap("ThreadPool:type=rara,key1=a", values), server);
    Assert.assertEquals(5f, stats.getStats("JMX/ThreadPool/rara/a/hello1").getTotal(), .001);
    Assert.assertEquals(4f, stats.getStats("JMX/ThreadPool/rara/a/goodbye1").getTotal(), .001);
    values.clear();
    values.put("hello1", 6f);
    values.put("goodbye1", 7f);
    object.recordStats(stats, createMap("ThreadPool:type=rara,key1=a", values), server);
    Assert.assertEquals(11f, stats.getStats("JMX/ThreadPool/rara/a/hello1").getTotal(), .001);
    Assert.assertEquals(7f, stats.getStats("JMX/ThreadPool/rara/a/goodbye1").getTotal(), .001);
    Assert.assertEquals(2f, stats.getStats("JMX/ThreadPool/rara/a/hello1").getCallCount(), .001);
    Assert.assertEquals(2f, stats.getStats("JMX/ThreadPool/rara/a/goodbye1").getCallCount(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) MBeanServer(javax.management.MBeanServer) 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