Search in sources :

Example 6 with MetricName

use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.

the class SimpleStatsEngine method createMetricData.

protected static MetricData createMetricData(MetricName metricName, StatsBase statsBase, Normalizer metricNormalizer) {
    if (!statsBase.hasData()) {
        return null;
    }
    String normalized = metricNormalizer.normalize(metricName.getName());
    if (normalized == null) {
        return null;
    }
    if (normalized.equals(metricName.getName())) {
        return MetricData.create(metricName, statsBase);
    }
    MetricName normalizedMetricName = MetricName.create(normalized, metricName.getScope());
    return MetricData.create(normalizedMetricName, statsBase);
}
Also used : MetricName(com.newrelic.agent.metric.MetricName)

Example 7 with MetricName

use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.

the class AgentHelper method getMetrics.

/**
 * Consider using {@link TransactionDataList} instead of this.
 */
public static Set<String> getMetrics(StatsEngine statsEngine, boolean includeScoped) {
    Set<String> result = new HashSet<>();
    List<MetricName> metricNames = statsEngine.getMetricNames();
    for (MetricName metricName : metricNames) {
        if (includeScoped || !metricName.isScoped()) {
            result.add(metricName.getName());
        }
    }
    return result;
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet)

Example 8 with MetricName

use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.

the class JSONSerializerTest method serializeMetricData.

@Test
public void serializeMetricData() throws Exception {
    MetricName name = MetricName.create("test");
    MetricData data = MetricData.create(name, AbstractStats.EMPTY_STATS);
    Assert.assertEquals("[{\"name\":\"test\"},[0,0,0,0,0,0]]", AgentHelper.serializeJSON(data).toString());
    data = MetricData.create(name, 666, AbstractStats.EMPTY_STATS);
    String res = AgentHelper.serializeJSON(data).toString();
    Assert.assertEquals("[666,[0,0,0,0,0,0]]", AgentHelper.serializeJSON(data).toString());
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) Test(org.junit.Test) StatsTest(com.newrelic.agent.stats.StatsTest)

Example 9 with MetricName

use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.

the class JSONSerializerTest method serializeMetricName.

@Test
public void serializeMetricName() throws Exception {
    MetricName name = MetricName.create("test");
    Assert.assertEquals("{\"name\":\"test\"}", AgentHelper.serializeJSON(name).toString());
    name = MetricName.create("test", "scope");
    Assert.assertEquals("{\"scope\":\"scope\",\"name\":\"test\"}", AgentHelper.serializeJSON(name).toString());
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) Test(org.junit.Test) StatsTest(com.newrelic.agent.stats.StatsTest)

Example 10 with MetricName

use of com.newrelic.agent.metric.MetricName in project newrelic-java-agent by newrelic.

the class TraceAnnotationTest method testDispatcher.

@Test
public void testDispatcher() throws Exception {
    new Simple().dispatch();
    List<MetricName> metrics = AgentHelper.getDefaultStatsEngine().getMetricNames();
    MetricName dispatcherMetricName = MetricName.create(MessageFormat.format("{0}/{1}/dispatch", MetricNames.OTHER_TRANSACTION_CUSTOM, Simple.class.getName()));
    Assert.assertTrue(metrics.contains(dispatcherMetricName));
    MetricName child = MetricName.create("Custom/Testing", dispatcherMetricName.getName());
    Assert.assertTrue(metrics.contains(child));
    Assert.assertTrue(metrics.contains(MetricName.create(MetricNames.OTHER_TRANSACTION_ALL)));
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) Test(org.junit.Test)

Aggregations

MetricName (com.newrelic.agent.metric.MetricName)14 Test (org.junit.Test)6 StatsEngine (com.newrelic.agent.stats.StatsEngine)5 ArrayList (java.util.ArrayList)3 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)2 StatsTest (com.newrelic.agent.stats.StatsTest)2 StatsWork (com.newrelic.agent.stats.StatsWork)2 Tracer (com.newrelic.agent.tracers.Tracer)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 MetricData (com.newrelic.agent.MetricData)1 TransactionActivity (com.newrelic.agent.TransactionActivity)1 TransactionData (com.newrelic.agent.TransactionData)1 TransactionDataList (com.newrelic.agent.TransactionDataList)1 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)1 CountStats (com.newrelic.agent.stats.CountStats)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 BasicThreadInfo (com.newrelic.agent.threads.BasicThreadInfo)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1