Search in sources :

Example 81 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine 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);
}
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 82 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine 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);
}
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 83 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class TransactionEventsServiceTest method checkForEvent.

private void checkForEvent() {
    assertEquals(1, ((MockRPMService) ServiceFactory.getRPMService()).getEvents().size());
    StatsEngine statsEngineForHarvest = ServiceFactory.getStatsService().getStatsEngineForHarvest(EventTestHelper.APP_NAME);
    assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_TRANSACTION_EVENT_SERVICE_TRANSACTION_EVENT_SEEN)).hasData());
    assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_TRANSACTION_EVENT_SERVICE_TRANSACTION_EVENT_SENT)).hasData());
    ((MockRPMService) ServiceFactory.getRPMService()).clearEvents();
}
Also used : StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService)

Example 84 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.

the class InsightsServiceImplTest method checkForEvent.

public void checkForEvent() {
    StatsEngine statsEngineForHarvest = ServiceFactory.getStatsService().getStatsEngineForHarvest(EventTestHelper.APP_NAME);
    assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_INSIGHTS_SERVICE_CUSTOMER_SEEN)).hasData());
    assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_INSIGHTS_SERVICE_CUSTOMER_SENT)).hasData());
    assertEquals(1, ((MockRPMService) ServiceFactory.getRPMService()).getEvents().size());
    CustomInsightsEvent customEvent = (CustomInsightsEvent) Iterables.get(((MockRPMService) ServiceFactory.getRPMService()).getEvents(), 0);
    assertEquals("CustomEvent", customEvent.getType());
}
Also used : StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) CustomInsightsEvent(com.newrelic.agent.model.CustomInsightsEvent)

Example 85 with StatsEngine

use of com.newrelic.agent.stats.StatsEngine 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)

Aggregations

StatsEngine (com.newrelic.agent.stats.StatsEngine)96 Test (org.junit.Test)78 TransactionDataList (com.newrelic.agent.TransactionDataList)36 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)31 TransactionData (com.newrelic.agent.TransactionData)29 HashMap (java.util.HashMap)25 JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)20 StatsWork (com.newrelic.agent.stats.StatsWork)8 MockRPMService (com.newrelic.agent.MockRPMService)7 ArrayList (java.util.ArrayList)6 AgentConfigFactoryTest (com.newrelic.agent.config.AgentConfigFactoryTest)5 Environment (com.newrelic.agent.environment.Environment)5 MetricName (com.newrelic.agent.metric.MetricName)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Attribute (javax.management.Attribute)5 MBeanServer (javax.management.MBeanServer)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)4 Stats (com.newrelic.agent.stats.Stats)4 HttpError (com.newrelic.agent.transport.HttpError)4 CountStatistic (javax.management.j2ee.statistics.CountStatistic)4