Search in sources :

Example 21 with ResponseTimeStats

use of com.newrelic.agent.stats.ResponseTimeStats 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 22 with ResponseTimeStats

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

the class RPMServiceTest method doHarvest.

private void doHarvest() throws Exception {
    List<String> appNames = singletonList("MyApplication");
    RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
    svc.launch();
    synchronized (this) {
        wait(1000);
    }
    StatsEngine harvestStatsEngine = new StatsEngineImpl();
    try {
        for (int i = 0; i < 1000; i++) {
            harvestStatsEngine.getResponseTimeStats(MetricNames.EXTERNAL_ALL).recordResponseTime(66, TimeUnit.MILLISECONDS);
        }
        svc.harvest(harvestStatsEngine);
        Stats stats3 = harvestStatsEngine.getStats(MetricNames.AGENT_METRICS_COUNT);
        assertEquals(0, stats3.getCallCount());
        ResponseTimeStats stats = harvestStatsEngine.getResponseTimeStats(MetricNames.SUPPORTABILITY_METRIC_HARVEST_TRANSMIT);
        assertEquals(1, stats.getCallCount());
        assertTrue(stats.getTotal() > 0);
        Stats stats2 = harvestStatsEngine.getStats(MetricNames.SUPPORTABILITY_METRIC_HARVEST_COUNT);
        assertEquals(1, stats2.getCallCount());
    } finally {
        svc.shutdown();
    }
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Stats(com.newrelic.agent.stats.Stats) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 23 with ResponseTimeStats

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

the class SegmentTest method testMetricMigration.

@Test
public void testMetricMigration() throws InterruptedException {
    Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
    segment.getTracedMethod().addRollupMetricName("rollupMetric");
    segment.getTracedMethod().addExclusiveRollupMetricName("exclusiveRollupMetric");
    segment.end();
    root.finish(Opcodes.ARETURN, null);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    ResponseTimeStats rollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric");
    assertTrue(rollupMetric.getCallCount() == 1);
    ResponseTimeStats exclusiveRollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("exclusiveRollupMetric");
    assertTrue(exclusiveRollupMetric.getCallCount() == 1);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 24 with ResponseTimeStats

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

the class TransactionDataList method getMetricCounts.

public Map<String, Integer> getMetricCounts(Set<MetricName> responseTimeMetricNames) {
    Map<String, Integer> metricNameToCounts = new HashMap<>();
    synchronized (statsEngine) {
        for (MetricName responseTimeMetricName : responseTimeMetricNames) {
            ResponseTimeStats responseTimeStats = statsEngine.getResponseTimeStats(responseTimeMetricName);
            metricNameToCounts.put(responseTimeMetricName.getName(), responseTimeStats.getCallCount());
        }
    }
    return metricNameToCounts;
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) MetricName(com.newrelic.agent.metric.MetricName) HashMap(java.util.HashMap)

Example 25 with ResponseTimeStats

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

the class DefaultTracer method recordMetrics.

/**
 * Record response time metrics.
 */
protected void recordMetrics(TransactionStats transactionStats) {
    try {
        recordExternalMetrics();
    } catch (Throwable t) {
        String msg = MessageFormat.format("An error occurred recording external metrics for class {0} : {1}", classMethodSignature.getClassName(), t.toString());
        Agent.LOG.severe(msg);
        Agent.LOG.log(Level.FINER, msg, t);
    }
    if (getTransaction() == null || getTransaction().isIgnore()) {
        return;
    }
    if (isMetricProducer()) {
        String metricName = getMetricName();
        if (metricName != null) {
            // record the scoped metrics
            ResponseTimeStats stats = transactionStats.getScopedStats().getOrCreateResponseTimeStats(metricName);
            stats.recordResponseTimeInNanos(getDuration(), getExclusiveDuration());
        // there is now an unscoped metric for every scoped metric
        // the unscoped metric is created in the StatsEngineImpl
        }
        if (getRollupMetricNames() != null) {
            for (String name : getRollupMetricNames()) {
                ResponseTimeStats stats = transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(name);
                stats.recordResponseTimeInNanos(getDuration(), getExclusiveDuration());
            }
        }
        if (getExclusiveRollupMetricNames() != null) {
            for (String name : getExclusiveRollupMetricNames()) {
                ResponseTimeStats stats = transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(name);
                stats.recordResponseTimeInNanos(getExclusiveDuration(), getExclusiveDuration());
            }
        }
        doRecordMetrics(transactionStats);
    }
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats)

Aggregations

ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)28 Test (org.junit.Test)20 Transaction (com.newrelic.agent.Transaction)9 StatsBase (com.newrelic.agent.stats.StatsBase)9 Tracer (com.newrelic.agent.tracers.Tracer)9 TokenImpl (com.newrelic.agent.TokenImpl)6 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)6 TransactionStats (com.newrelic.agent.stats.TransactionStats)6 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)4 StatsEngine (com.newrelic.agent.stats.StatsEngine)3 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 TransactionDataList (com.newrelic.agent.TransactionDataList)2 ExitTracer (com.newrelic.agent.bridge.ExitTracer)2 MetricName (com.newrelic.agent.metric.MetricName)2 Stats (com.newrelic.agent.stats.Stats)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)2 Trace (com.newrelic.api.agent.Trace)2 MockServiceManager (com.newrelic.agent.MockServiceManager)1