use of com.newrelic.agent.stats.StatsEngineImpl 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.stats.StatsEngineImpl 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.stats.StatsEngineImpl 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);
}
use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.
the class JmxObjectFactoryTest method verifyYml.
private void verifyYml(List<JmxGet> actual) throws MalformedObjectNameException {
StatsEngine stats = new StatsEngineImpl();
Map<String, Float> values = new HashMap<>();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Assert.assertEquals(4, actual.size());
JmxGet one = actual.get(3);
Assert.assertEquals("solr*:type=queryResultCache,*", one.getObjectName().toString());
Assert.assertTrue(one.getAttributes().contains("lookups"));
// LOOKUPS
values.put("lookups", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("lookups", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// HITS
values.clear();
values.put("hits", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/hits").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("hits", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/hits").getTotal(), .001);
// hitratio
values.clear();
values.put("hitratio", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/hitratio").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("hitratio", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/hitratio").getTotal(), .001);
// size
values.clear();
values.put("size", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("size", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// cumulative_hitratio
values.clear();
values.put("cumulative_hitratio", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("cumulative_hitratio", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
stats = new StatsEngineImpl();
JmxGet two = actual.get(2);
// lookups
values.clear();
values.put("lookups", 1f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("lookups", 4f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// size
values.clear();
values.put("size", 1f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// it should be simple
values.clear();
values.put("size", 4f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(5f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// cumulative_hitratio
values.clear();
values.put("cumulative_hitratio", 1f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
// it should be simple
values.clear();
values.put("cumulative_hitratio", 4f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(5f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
}
use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.
the class SourceLanguageServiceTest method countsResetToZeroAfterHarvest.
@Test
public void countsResetToZeroAfterHarvest() throws Exception {
readClass(this.getClass());
Map<String, Long> sourceCounts = sourceLanguageService.getSourceCounts();
assertTrue(sourceCounts.containsKey(SUPPORTABILITY_METRIC_FOR_CLASS));
assertEquals(1L, sourceCounts.get(SUPPORTABILITY_METRIC_FOR_CLASS).longValue());
for (Map.Entry<String, Long> entry : sourceCounts.entrySet()) {
if (!SUPPORTABILITY_METRIC_FOR_CLASS.equals(entry.getKey())) {
assertEquals(0, entry.getValue().longValue());
}
}
StatsEngineImpl statsEngine = new StatsEngineImpl();
sourceLanguageService.beforeHarvest("Unit Test", statsEngine);
sourceLanguageService.afterHarvest("Unit Test");
assertEquals(1, statsEngine.getResponseTimeStats(SUPPORTABILITY_METRIC_FOR_CLASS).getCallCount());
// all entries in the map should be reset
for (Map.Entry<String, Long> entry : sourceLanguageService.getSourceCounts().entrySet()) {
assertEquals(0, entry.getValue().longValue());
}
}
Aggregations