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);
}
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);
}
Aggregations