Search in sources :

Example 1 with ApdexStats

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

the class BasicRequestDispatcherTracerTest method apdexNotKeyTransaction.

@Test
public void apdexNotKeyTransaction() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    Transaction tx = Transaction.getTransaction();
    dispatcher.setStatus(200);
    dispatcher.transactionFinished("WebTransaction/Custom/UrlGenerator/ru/betting/Motorsport", tx.getTransactionActivity().getTransactionStats());
    ApdexStats stats1 = tx.getTransactionActivity().getTransactionStats().getUnscopedStats().getApdexStats("Apdex/Custom/UrlGenerator/ru/betting/Motorsport");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(out);
    stats1.writeJSONString(writer);
    writer.close();
    Assert.assertEquals("[1,0,0,0.5,0.5,0]", out.toString());
}
Also used : Transaction(com.newrelic.agent.Transaction) ApdexStats(com.newrelic.agent.stats.ApdexStats) OutputStreamWriter(java.io.OutputStreamWriter) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with ApdexStats

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

the class BasicRequestDispatcherTracerTest method requestXQueueHeaderRecordApdexMetrics.

@Test
public void requestXQueueHeaderRecordApdexMetrics() throws Exception {
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    rpmService.setEverConnected(true);
    Map<String, Object> data = new HashMap<>();
    data.put(AgentConfigImpl.APDEX_T, 6.0d);
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    connectionConfigListener.connected(rpmService, data);
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.getTransaction().getRootTracer().finish(0, null);
    StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(APP_NAME);
    ApdexStats apdexStats = statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX));
    Assert.assertEquals(0, apdexStats.getApdexFrustrating());
    apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
    Assert.assertEquals(0, apdexStats.getApdexFrustrating());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) ApdexStats(com.newrelic.agent.stats.ApdexStats) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 3 with ApdexStats

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

the class WebRequestDispatcher method recordApdexMetrics.

private void recordApdexMetrics(String frontendMetricName, TransactionStats stats) {
    if (frontendMetricName == null || frontendMetricName.length() == 0) {
        return;
    }
    if (!getTransaction().getAgentConfig().isApdexTSet()) {
        return;
    }
    if (isIgnoreApdex()) {
        Agent.LOG.log(Level.FINE, "Ignoring transaction for Apdex {0}", frontendMetricName);
        return;
    }
    String frontendApdexMetricName = getApdexMetricName(frontendMetricName, MetricNames.WEB_TRANSACTION, MetricNames.APDEX);
    if (frontendApdexMetricName == null || frontendApdexMetricName.length() == 0) {
        return;
    }
    long apdexT = getTransaction().getAgentConfig().getApdexTInMillis(frontendMetricName);
    ApdexStats apdexStats = stats.getUnscopedStats().getApdexStats(frontendApdexMetricName);
    ApdexStats overallApdexStats = stats.getUnscopedStats().getApdexStats(MetricNames.APDEX);
    if (isApdexFrustrating()) {
        apdexStats.recordApdexFrustrated();
        overallApdexStats.recordApdexFrustrated();
    } else {
        long responseTimeInMillis = getTransaction().getTransactionTimer().getResponseTimeInMilliseconds() + externalTimeTracker.getExternalTime();
        apdexStats.recordApdexResponseTime(responseTimeInMillis, apdexT);
        overallApdexStats.recordApdexResponseTime(responseTimeInMillis, apdexT);
    }
}
Also used : ApdexStats(com.newrelic.agent.stats.ApdexStats)

Example 4 with ApdexStats

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

the class OtherDispatcher method recordApdexMetrics.

private void recordApdexMetrics(String transactionName, TransactionStats stats) {
    if (transactionName == null || transactionName.length() == 0) {
        return;
    }
    if (!getTransaction().getAgentConfig().isApdexTSet(transactionName)) {
        return;
    }
    if (isIgnoreApdex()) {
        Agent.LOG.log(Level.FINE, "Ignoring transaction for Apdex {0}", transactionName);
        return;
    }
    String apdexMetricName = getApdexMetricName(transactionName, MetricNames.OTHER_TRANSACTION, MetricNames.APDEX_OTHER_TRANSACTION);
    if (apdexMetricName == null || apdexMetricName.length() == 0) {
        return;
    }
    long apdexT = getTransaction().getAgentConfig().getApdexTInMillis(transactionName);
    ApdexStats apdexStats = stats.getUnscopedStats().getApdexStats(apdexMetricName);
    ApdexStats overallApdexStats = stats.getUnscopedStats().getApdexStats(MetricNames.APDEX_OTHER);
    if (isApdexFrustrating()) {
        apdexStats.recordApdexFrustrated();
        overallApdexStats.recordApdexFrustrated();
    } else {
        long responseTimeInMillis = getTransaction().getTransactionTimer().getResponseTimeInMilliseconds();
        apdexStats.recordApdexResponseTime(responseTimeInMillis, apdexT);
        overallApdexStats.recordApdexResponseTime(responseTimeInMillis, apdexT);
    }
}
Also used : ApdexStats(com.newrelic.agent.stats.ApdexStats)

Example 5 with ApdexStats

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

the class BasicRequestDispatcherTracerTest method apdexKeyTransaction.

@Test
public void apdexKeyTransaction() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    Transaction tx = Transaction.getTransaction();
    dispatcher.setStatus(200);
    dispatcher.transactionFinished("WebTransaction/Custom/UrlGenerator/en/betting/Football", stats);
    ApdexStats stats1 = stats.getUnscopedStats().getApdexStats("Apdex/Custom/UrlGenerator/en/betting/Football");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(out);
    stats1.writeJSONString(writer);
    writer.close();
    Assert.assertEquals("[1,0,0,7.0,7.0,0]", out.toString());
}
Also used : Transaction(com.newrelic.agent.Transaction) ApdexStats(com.newrelic.agent.stats.ApdexStats) OutputStreamWriter(java.io.OutputStreamWriter) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ApdexStats (com.newrelic.agent.stats.ApdexStats)6 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)4 Test (org.junit.Test)4 ConnectionConfigListener (com.newrelic.agent.ConnectionConfigListener)2 MockRPMService (com.newrelic.agent.MockRPMService)2 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)2 Transaction (com.newrelic.agent.Transaction)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 HashMap (java.util.HashMap)2