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());
}
}
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();
}
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();
}
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());
}
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());
}
Aggregations