use of com.newrelic.agent.metric.MetricName 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.metric.MetricName 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.metric.MetricName in project newrelic-java-agent by newrelic.
the class CPUSamplerTest method test.
@Test
public void test() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("host", "localhost");
map.put("port", 3000);
map.put("ssl", false);
map.put("license_key", "bootstrap_newrelic_admin_license_key_000");
createServiceManager(map);
StatsEngine statsEngine = new StatsEngineImpl();
CPUHarvester harvester = new CPUHarvester();
for (int i = 0; i < 10000; i++) {
harvester.recordCPU(statsEngine);
statsEngine.getMetricNames();
}
List<MetricName> harvest = statsEngine.getMetricNames();
CountStats stats = null;
for (MetricName data : harvest) {
if (MetricNames.CPU.equals(data.getName())) {
stats = (CountStats) statsEngine.getStats(data);
break;
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out);
stats.writeJSONString(writer);
writer.close();
System.err.println(out.toString());
}
use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.
the class AgentTest method ttSizeLimitExceeded.
/**
* If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
* transaction trace.
*/
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
TestSizeLimitServlet servlet = new TestSizeLimitServlet();
String path = "/my/word";
AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
Assert.assertEquals(2, stats.getCallCount());
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
Assert.assertEquals(3, tracers.size());
}
use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.
the class SimpleStatsEngine method getMetricData.
/**
* Converts the stats to a list of metric data.
*
* @param metricNormalizer The normalizer.
* @param scope The scope. This should be EMPTY_SCOPE if these are unscoped metrics.
* @return The list of metric data generated from the internal stats object.
*/
public List<MetricData> getMetricData(Normalizer metricNormalizer, String scope) {
// +1 for Java/other
List<MetricData> result = new ArrayList<>(stats.size() + 1);
boolean isTrimStats = ServiceFactory.getConfigService().getDefaultAgentConfig().isTrimStats();
if (isTrimStats && !scope.equals(MetricName.EMPTY_SCOPE)) {
trimStats();
}
for (Entry<String, StatsBase> entry : stats.entrySet()) {
MetricName metricName = MetricName.create(entry.getKey(), scope);
MetricData metricData = createMetricData(metricName, entry.getValue(), metricNormalizer);
if (metricData != null) {
result.add(metricData);
}
}
return result;
}
Aggregations