Search in sources :

Example 21 with StatsEngine

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

the class JmxGetTest method testJmxGetStatsSingleSimilar.

@Test
public void testJmxGetStatsSingleSimilar() throws MalformedObjectNameException {
    StatsEngine stats = new StatsEngineImpl();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello3", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye3", JmxType.SIMPLE));
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*", "JmxBuiltIn/ThreadPool/{key1}", metrics, null, null);
    Map<ObjectName, Map<String, Float>> data = new HashMap<>();
    Map<String, Float> values1 = new HashMap<>();
    values1.put("hello3", 2f);
    values1.put("goodbye3", 3f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=b"), values1);
    Map<String, Float> values2 = new HashMap<>();
    values2.put("hello3", 4f);
    values2.put("goodbye3", 5f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=c"), values2);
    Map<String, Float> values3 = new HashMap<>();
    values3.put("hello3", 5f);
    values3.put("goodbye3", 7f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=d"), values3);
    object.recordStats(stats, data, server);
    Assert.assertEquals(3, stats.getStats("JmxBuiltIn/ThreadPool/a/hello3").getCallCount());
    Assert.assertEquals(3, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye3").getCallCount());
    Assert.assertEquals(11f, stats.getStats("JmxBuiltIn/ThreadPool/a/hello3").getTotal(), .001);
    Assert.assertEquals(15f, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye3").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatsEngine(com.newrelic.agent.stats.StatsEngine) ObjectName(javax.management.ObjectName) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 22 with StatsEngine

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

the class JmxGetTest method testJmxGetStatsMultiSimilar.

@Test
public void testJmxGetStatsMultiSimilar() throws MalformedObjectNameException {
    StatsEngine stats = new StatsEngineImpl();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello2", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye2", JmxType.MONOTONICALLY_INCREASING));
    JmxGet object = new JmxMultiMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*", "JmxBuiltIn/ThreadPool/{key1}", metrics, null, null);
    Map<ObjectName, Map<String, Float>> data = new HashMap<>();
    Map<String, Float> values1 = new HashMap<>();
    values1.put("hello2", 2f);
    values1.put("goodbye2", 4f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=b"), values1);
    Map<String, Float> values2 = new HashMap<>();
    values2.put("hello2", 4f);
    values2.put("goodbye2", 5f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=c"), values2);
    Map<String, Float> values3 = new HashMap<>();
    values3.put("hello2", 5f);
    values3.put("goodbye2", 7f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=d"), values3);
    object.recordStats(stats, data, server);
    Assert.assertEquals(11f, stats.getStats("JmxBuiltIn/ThreadPool/a/hello2").getTotal(), .001);
    Assert.assertEquals(16f, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye2").getTotal(), .001);
    Assert.assertEquals(1, stats.getStats("JmxBuiltIn/ThreadPool/a/hello2").getCallCount());
    Assert.assertEquals(1, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye2").getCallCount());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatsEngine(com.newrelic.agent.stats.StatsEngine) ObjectName(javax.management.ObjectName) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 23 with StatsEngine

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

the class CPUSamplerTest method test.

@Test
public void test() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("host", "localhost");
    map.put("port", 3000);
    map.put("ssl", false);
    map.put("license_key", "bootstrap_newrelic_admin_license_key_000");
    createServiceManager(map);
    StatsEngine statsEngine = new StatsEngineImpl();
    CPUHarvester harvester = new CPUHarvester();
    for (int i = 0; i < 10000; i++) {
        harvester.recordCPU(statsEngine);
        statsEngine.getMetricNames();
    }
    List<MetricName> harvest = statsEngine.getMetricNames();
    CountStats stats = null;
    for (MetricName data : harvest) {
        if (MetricNames.CPU.equals(data.getName())) {
            stats = (CountStats) statsEngine.getStats(data);
            break;
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(out);
    stats.writeJSONString(writer);
    writer.close();
    System.err.println(out.toString());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) CountStats(com.newrelic.agent.stats.CountStats) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StatsEngine(com.newrelic.agent.stats.StatsEngine) MetricName(com.newrelic.agent.metric.MetricName) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 24 with StatsEngine

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

the class AgentTest method ttSizeLimitExceeded.

/**
 * If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
 * transaction trace.
 */
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    TestSizeLimitServlet servlet = new TestSizeLimitServlet();
    String path = "/my/word";
    AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
    StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
    MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
    ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
    Assert.assertEquals(2, stats.getCallCount());
    Assert.assertEquals(2, txs.size());
    TransactionData transactionData = txs.get(1);
    Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
    Assert.assertEquals(3, tracers.size());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) MetricName(com.newrelic.agent.metric.MetricName) TransactionDataList(com.newrelic.agent.TransactionDataList) Tracer(com.newrelic.agent.tracers.Tracer) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 25 with StatsEngine

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

the class ExpectedErrorsTest method expectedClassMessagesFallbackOverride.

@Test
public void expectedClassMessagesFallbackOverride() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("expected_class_messages_fallback_test");
    try {
        try {
            // Doesn't matter what the message is, it will be expected
            throwException(new ExpectedError("blah"));
            fail("The expected exception was not thrown");
        } catch (Throwable t) {
        }
        // Verify the transaction was created and finished
        TransactionDataList transactionList = holder.getTransactionList();
        ServiceFactory.getHarvestService().harvestNow();
        assertEquals(1, transactionList.size());
        TransactionData td = transactionList.get(0);
        assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.ExpectedErrorsTest/throwException", td.getPriorityTransactionName().getName());
        StatsEngine statsEngine = holder.getStatsEngine();
        assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
        verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 2);
        verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 1);
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) 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