use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.
the class JmxMetricTest method jmxMetricRecordStatsSubTypeSimple.
@Test
public void jmxMetricRecordStatsSubTypeSimple() {
StatsEngine stats = new StatsEngineImpl();
JmxMetric metric = JmxMetric.create(new String[] { "first", "second" }, "theDiff", JmxAction.SUBTRACT_ALL_FROM_FIRST, JmxType.SIMPLE);
Map<String, Float> values = new HashMap<>();
values.put("first", 10f);
values.put("second", 7f);
metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
Assert.assertEquals(1, stats.getStats("Jmx/Sample/theDiff").getCallCount());
Assert.assertEquals(3f, stats.getStats("Jmx/Sample/theDiff").getTotal(), .001);
values.clear();
values.put("first", 12f);
values.put("second", 6f);
metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
Assert.assertEquals(2, stats.getStats("Jmx/Sample/theDiff").getCallCount());
Assert.assertEquals(9f, stats.getStats("Jmx/Sample/theDiff").getTotal(), .001);
}
use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.
the class JmxMetricTest method jmxMetricRecordStatsSubTypeSimpleMultiAdd.
@Test
public void jmxMetricRecordStatsSubTypeSimpleMultiAdd() {
StatsEngine stats = new StatsEngineImpl();
JmxMetric metric = JmxMetric.create(new String[] { "first", "second" }, "theDiff", JmxAction.SUBTRACT_ALL_FROM_FIRST, JmxType.SIMPLE);
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);
Assert.assertEquals(0, stats.getStats("Jmx/Sample/theDiff").getCallCount());
values.clear();
values.put("first", 12f);
values.put("second", 6f);
metric.applySingleMBean("Jmx/Sample/", values, actual);
metric.recordMultMBeanStats(stats, actual);
Assert.assertEquals(1, stats.getStats("Jmx/Sample/theDiff").getCallCount());
Assert.assertEquals(9f, stats.getStats("Jmx/Sample/theDiff").getTotal(), .001);
}
use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.
the class JmxGetTest method testNullRootMetricName.
@Test
public void testNullRootMetricName() throws MalformedObjectNameException {
JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*,key2=*", null, new ArrayList<JmxMetric>(), null, null);
String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
Assert.assertEquals("JMX/ThreadPool/rara/value1/value2/", root);
}
use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.
the class JmxGetTest method testGetRootMetricNoPattern.
@Test
public void testGetRootMetricNoPattern() 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/", metrics, null, null);
String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
Assert.assertEquals("JMX/TheRoot/Wahoo/", root);
}
use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.
the class JmxGetTest method testGetRootMetricNoPatternMissingEndSlash.
@Test
public void testGetRootMetricNoPatternMissingEndSlash() 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", metrics, null, null);
String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
Assert.assertEquals("JMX/TheRoot/Wahoo/", root);
}
Aggregations