Search in sources :

Example 1 with SimpleStatsEngine

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

the class DistributedTraceServiceImplTest method txnFinishedInboundPayload.

@Test
public void txnFinishedInboundPayload() {
    Map<String, Object> connectInfo = new HashMap<>();
    connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "1acct234");
    connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "67890");
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
    distributedTraceService.connected(null, agentConfig);
    TransactionStats transactionStats = new TransactionStats();
    Map<String, Object> intrinsicAttributes = new HashMap<>();
    long payloadSendTimestamp = 1002000;
    long startTimeInMillis = 1005000;
    long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
    String json = new DistributedTracePayloadBuilder().setTimestamp(payloadSendTimestamp).setHost("datanerd.us.com").setParentType("Browser").setAccountId("123456").setTrustKey("67890").setApplicationId("6789").setTransactionId("badcafe3").setTripId("cattrip").setPriority(0.0f).setDepth(0).setSyntheticsJob(null).setSyntheticsMonitor(null).setSyntheticsResource(null).createJsonPayload();
    DistributedTracePayloadImpl payload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), distributedTraceService, Agent.LOG).parse(null, json);
    TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, payload);
    distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
    SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
    assertEquals(1.35f, unscopedStats.getOrCreateResponseTimeStats("DurationByCaller/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
    assertEquals(3.0f, unscopedStats.getOrCreateResponseTimeStats("TransportDuration/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionStats(com.newrelic.agent.stats.TransactionStats) DistributedTracePayloadBuilder(com.newrelic.agent.DistributedTracePayloadBuilder) HashMap(java.util.HashMap) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 2 with SimpleStatsEngine

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

the class DistributedTraceServiceImplTest method txnFinished.

@Test
public void txnFinished() {
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    TransactionStats transactionStats = new TransactionStats();
    Map<String, Object> intrinsicAttributes = new HashMap<>();
    long startTimeInMillis = System.currentTimeMillis();
    long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
    TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, null);
    distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
    SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
    String responseTime = MessageFormat.format(MetricNames.DURATION_BY_PARENT_UNKNOWN_ALL, "HTTPS");
    String errors = MessageFormat.format(MetricNames.ERRORS_BY_PARENT_UNKNOWN, "HTTPS");
    assertEquals(1.35, unscopedStats.getOrCreateResponseTimeStats(responseTime).getTotal(), 0.01f);
    assertEquals(1, unscopedStats.getStats(errors).getCallCount());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 3 with SimpleStatsEngine

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

the class AsyncTest method verifyCustomUnscopedMetric.

public void verifyCustomUnscopedMetric(String name, int count) {
    verifyUnscopedMetricsPresentIgnoringValues(stats, name);
    SimpleStatsEngine engine = stats.getUnscopedStats();
    Assert.assertNotNull(engine);
    Assert.assertEquals(count, engine.getStats(name).getCallCount());
}
Also used : SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine)

Example 4 with SimpleStatsEngine

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

the class IntrospectorStatsService method getUnscopedMetrics.

public Map<String, TracedMetricData> getUnscopedMetrics() {
    SimpleStatsEngine unscoped = engine.getUnscopedStatsForTesting();
    Map<String, TracedMetricData> unscopedMetricMap = convertToTracedMetric(unscoped);
    // copies of scoped metrics -> unscoped
    List<MetricData> allScopedMetricData = new ArrayList<>();
    for (Entry<String, SimpleStatsEngine> entry : engine.getScopedStatsForTesting().entrySet()) {
        allScopedMetricData.addAll(entry.getValue().getMetricData(metricNormalizer, entry.getKey()));
    }
    List<MetricData> unscopedCopies = StatsEngineImpl.createUnscopedCopies(metricNormalizer, allScopedMetricData);
    for (MetricData unscopedCopy : unscopedCopies) {
        if (unscopedCopy.getStats() instanceof CountStats) {
            String metricName = unscopedCopy.getMetricName().getName();
            TracedMetricData data = TracedMetricImpl.getTracedMetricFromStatsBase(metricName, (CountStats) unscopedCopy.getStats());
            unscopedMetricMap.put(metricName, data);
        }
    }
    return unscopedMetricMap;
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) CountStats(com.newrelic.agent.stats.CountStats) ArrayList(java.util.ArrayList) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) MetricData(com.newrelic.agent.MetricData) TracedMetricData(com.newrelic.agent.introspec.TracedMetricData)

Example 5 with SimpleStatsEngine

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

the class IntrospectorStatsService method getScopedMetrics.

public Map<String, TracedMetricData> getScopedMetrics(String transactionName) {
    Map<String, SimpleStatsEngine> data = engine.getScopedStatsForTesting();
    SimpleStatsEngine txEngine = data.get(transactionName);
    if (txEngine == null) {
        throw new IllegalArgumentException("no such transaction: " + transactionName);
    }
    return convertToTracedMetric(txEngine);
}
Also used : SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine)

Aggregations

SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)12 TransactionStats (com.newrelic.agent.stats.TransactionStats)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Transaction (com.newrelic.agent.Transaction)2 TransactionData (com.newrelic.agent.TransactionData)2 AgentConfig (com.newrelic.agent.config.AgentConfig)2 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)2 DistributedTracePayloadBuilder (com.newrelic.agent.DistributedTracePayloadBuilder)1 MetricData (com.newrelic.agent.MetricData)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)1 CountStats (com.newrelic.agent.stats.CountStats)1 Stats (com.newrelic.agent.stats.Stats)1 StatsBase (com.newrelic.agent.stats.StatsBase)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 TransactionCounts (com.newrelic.agent.transaction.TransactionCounts)1