Search in sources :

Example 1 with StatsEngine

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

the class TransactionProfile method transactionFinished.

public void transactionFinished(TransactionData transactionData) {
    final List<MetricNameTime> cpuTimes = new ArrayList<>();
    for (TransactionActivity activity : transactionData.getTransactionActivities()) {
        ThreadInfo threadInfo = threadMXBean.getThreadInfo(activity.getThreadId(), 0);
        if (null != threadInfo) {
            final List<List<StackTraceElement>> backtraces = new ArrayList<>();
            Map<Tracer, Collection<Tracer>> tracerTree = buildChildren(activity.getTracers(), backtraces);
            String threadName = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo));
            threadActivityProfiles.get(threadName).add(activity, tracerTree);
            if (!backtraces.isEmpty()) {
                ProfileTree tree = threadProfiles.get(threadName);
                for (List<StackTraceElement> stack : backtraces) {
                    stack = DiscoveryProfile.getScrubbedStackTrace(stack);
                    Collections.reverse(stack);
                    tree.addStackTrace(stack, true);
                }
            }
            long cpuTime = activity.getTotalCpuTime();
            if (cpuTime > 0) {
                MetricName name = MetricName.create(transactionData.getBlameMetricName(), threadName);
                cpuTimes.add(new MetricNameTime(name, cpuTime));
            }
        }
    }
    if (!cpuTimes.isEmpty()) {
        ServiceFactory.getStatsService().doStatsWork(new StatsWork() {

            @Override
            public void doWork(StatsEngine statsEngine) {
                for (MetricNameTime time : cpuTimes) {
                    statsEngine.getResponseTimeStats(time.name).recordResponseTime(time.cpuTime, TimeUnit.NANOSECONDS);
                }
            }

            @Override
            public String getAppName() {
                return null;
            }
        }, transactionData.getBlameMetricName());
    }
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) ArrayList(java.util.ArrayList) TransactionActivity(com.newrelic.agent.TransactionActivity) StatsEngine(com.newrelic.agent.stats.StatsEngine) MetricName(com.newrelic.agent.metric.MetricName) ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) StatsWork(com.newrelic.agent.stats.StatsWork) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with StatsEngine

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

the class RPMServiceTest method doTestStatusCodeSupportabilityMetrics.

private void doTestStatusCodeSupportabilityMetrics() throws Exception {
    List<String> appNames = new ArrayList<>(1);
    appNames.add("MyApplication");
    RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
    svc.launch();
    StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest("MyApplication");
    MetricName metricName = MetricName.create("Supportability/Collector/HttpCode/200");
    assertTrue(statsEngine.getMetricNames().contains(metricName));
    svc.shutdown();
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) ArrayList(java.util.ArrayList) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 3 with StatsEngine

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

the class RPMServiceTest method doTestLaunchToSendMetricData.

private void doTestLaunchToSendMetricData() throws Exception {
    List<String> appNames = singletonList("MyApplication");
    RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
    svc.launch();
    StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(null);
    List<MetricData> data = createMetricData(statsEngine, 10);
    assertNotNull(data);
    svc.shutdown();
}
Also used : StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 4 with StatsEngine

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

the class DefaultTracerTest method checkUnknownDatastoreSupportabilityMetrics.

private void checkUnknownDatastoreSupportabilityMetrics(String product, int expectedUnkownHost, int expectedUnknownPort, int expectedUnknownDatabaseName) {
    StatsService statsService = ServiceFactory.getStatsService();
    StatsEngine statsEngine = statsService.getStatsEngineForHarvest("Unit Test");
    String unknownHostMetricName = new StringBuilder(MetricNames.SUPPORTABILITY_DATASTORE_PREFIX).append(product).append(MetricNames.SUPPORTABILITY_DATASTORE_UNKNOWN_HOST).toString();
    Stats unknownHostMetric = statsEngine.getStats(unknownHostMetricName);
    assertEquals(expectedUnkownHost, unknownHostMetric.getCallCount());
    String unknownPortMetricName = new StringBuilder(MetricNames.SUPPORTABILITY_DATASTORE_PREFIX).append(product).append(MetricNames.SUPPORTABILITY_DATASTORE_UNKNOWN_PORT).toString();
    Stats unknownPortMetric = statsEngine.getStats(unknownPortMetricName);
    assertEquals(expectedUnknownPort, unknownPortMetric.getCallCount());
    String unknownDatabaseMetricName = new StringBuilder(MetricNames.SUPPORTABILITY_DATASTORE_PREFIX).append(product).append(MetricNames.SUPPORTABILITY_DATASTORE_UNKNOWN_DATABASE_NAME).toString();
    Stats unknownDatabaseNameMetric = statsEngine.getStats(unknownDatabaseMetricName);
    assertEquals(expectedUnknownDatabaseName, unknownDatabaseNameMetric.getCallCount());
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) TransactionStats(com.newrelic.agent.stats.TransactionStats) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Stats(com.newrelic.agent.stats.Stats) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 5 with StatsEngine

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

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