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