use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class InstrumentTestUtils method printData.
private static void printData(List<MetricData> data) {
StringBuilder sb = new StringBuilder("Current Metrics: ");
for (MetricData each : data) {
sb.append(" ");
sb.append(each.getMetricName());
}
System.out.println(sb.toString());
}
use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class InstrumentTestUtils method verifyMetricCount.
public static void verifyMetricCount(String name, int count, List<MetricData> data) {
boolean foundName = false;
for (MetricData current : data) {
if (current.getMetricName().getName().equals(name)) {
foundName = true;
StatsBase stats = current.getStats();
if (stats instanceof CountStats) {
Assert.assertEquals(name, count, ((CountStats) stats).getCallCount());
}
}
}
printData(data);
Assert.assertTrue("Was not able to find metric name " + name, foundName);
}
use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class InstrumentTestUtils method verifyCountMetric.
public static void verifyCountMetric(Map<String, Integer> expected, StatsEngine engine) {
List<MetricData> data = engine.getMetricData(new MockNormalizer());
for (Entry<String, Integer> current : expected.entrySet()) {
if (current.getValue() != null) {
verifyMetricCount(current.getKey(), current.getValue(), data);
} else {
printData(data);
Assert.fail(MessageFormat.format("The expected count for {0} should not be null", current.getKey()));
}
}
}
use of com.newrelic.agent.MetricData 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;
}
use of com.newrelic.agent.MetricData 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