Search in sources :

Example 16 with StatsBase

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

the class TransactionAsyncRootLastTest method verifyDataTwo.

private void verifyDataTwo(StartAndThenLink activity, Transaction tx, TokenImpl token) {
    waitForTransaction();
    TransactionAsyncUtility.basicDataVerify(data, stats, activity, 2);
    Map<String, StatsBase> scoped = stats.getScopedStats().getStatsMap();
    ResponseTimeStats data1 = (ResponseTimeStats) scoped.get("RequestDispatcher");
    ResponseTimeStats data2 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token.toString());
    Assert.assertNotNull(data1);
    Assert.assertNotNull(data2);
    Assert.assertEquals(1, data1.getCallCount());
    Assert.assertEquals(1, data2.getCallCount());
    Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
    Assert.assertEquals(((ResponseTimeStats) unscoped.get("WebTransactionTotalTime")).getTotal(), data1.getTotal() + data2.getTotal(), .001);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) StatsBase(com.newrelic.agent.stats.StatsBase)

Example 17 with StatsBase

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

the class InstrumentTestUtils method getAndClearMetricData.

public static Map<String, Integer> getAndClearMetricData() {
    StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
    List<MetricData> data = statsEngine.getMetricData(new MockNormalizer());
    Map<String, Integer> dataMap = new HashMap<>();
    for (MetricData metricData : data) {
        StatsBase stats = metricData.getStats();
        if (stats instanceof CountStats) {
            dataMap.put(metricData.getMetricName().getName(), ((CountStats) stats).getCallCount());
        } else {
            dataMap.put(metricData.getMetricName().getName(), 0);
        }
    }
    return dataMap;
}
Also used : HashMap(java.util.HashMap) CountStats(com.newrelic.agent.stats.CountStats) StatsBase(com.newrelic.agent.stats.StatsBase) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockNormalizer(com.newrelic.agent.MockNormalizer) MetricData(com.newrelic.agent.MetricData)

Example 18 with StatsBase

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

the class ExternalsForTransaction method checkExternals.

protected static Collection<ExternalRequestImpl> checkExternals(boolean isWeb, TransactionStats stats, Collection<Tracer> tracers) {
    int totalCount = 0;
    // External/all
    // External/allWeb or External/allOther
    Multimap<String, ExternalRequestImpl> currentExternalsByHost = HashMultimap.create();
    Map<String, StatsBase> theStats = stats.getScopedStats().getStatsMap();
    String segment;
    String metric;
    for (Tracer current : tracers) {
        segment = current.getTransactionSegmentName();
        metric = current.getMetricName();
        if (metric.startsWith("External") && theStats.get(metric) != null) {
            ExternalRequestImpl impl = ExternalRequestImpl.checkAndMakeExternal(current);
            if (impl != null) {
                currentExternalsByHost.put(impl.getHostname(), impl);
                totalCount++;
            }
        }
    }
    return currentExternalsByHost.values();
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) StatsBase(com.newrelic.agent.stats.StatsBase)

Example 19 with StatsBase

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

the class TransactionAsyncEdgeCaseTest method testLinkSameThreadAfterWorkFinishes.

@Test
public void testLinkSameThreadAfterWorkFinishes() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "outer-hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod1");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    defaultTracer.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    Transaction.clearTransaction();
    TransactionActivity.clear();
    TransactionActivity.create(null, 0);
    rootTracer = TransactionAsyncUtility.createOtherTracer("inner-hi");
    TransactionActivity.get().tracerStarted(rootTracer);
    Assert.assertTrue(Transaction.linkTxOnThread(token));
    defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod2");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    token.expire();
    defaultTracer.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(2, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(4, tracers.size() + 1);
    Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
    Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
    ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod1");
    Assert.assertEquals(1, sb.getCallCount());
    sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod2");
    Assert.assertEquals(1, sb.getCallCount());
    sb = (ResponseTimeStatsImpl) metrics.get("Java/java.lang.Object/inner-hi");
    Assert.assertEquals(1, sb.getCallCount());
    sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
    Assert.assertEquals(1, sb.getCallCount());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) StatsBase(com.newrelic.agent.stats.StatsBase) ResponseTimeStatsImpl(com.newrelic.agent.stats.ResponseTimeStatsImpl) Test(org.junit.Test)

Aggregations

StatsBase (com.newrelic.agent.stats.StatsBase)19 Tracer (com.newrelic.agent.tracers.Tracer)10 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)9 Test (org.junit.Test)9 TokenImpl (com.newrelic.agent.TokenImpl)6 Transaction (com.newrelic.agent.Transaction)6 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)6 ResponseTimeStatsImpl (com.newrelic.agent.stats.ResponseTimeStatsImpl)4 CountStats (com.newrelic.agent.stats.CountStats)3 MetricData (com.newrelic.agent.MetricData)2 MockNormalizer (com.newrelic.agent.MockNormalizer)1 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1