Search in sources :

Example 6 with MetricData

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());
}
Also used : MetricData(com.newrelic.agent.MetricData)

Example 7 with MetricData

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);
}
Also used : CountStats(com.newrelic.agent.stats.CountStats) StatsBase(com.newrelic.agent.stats.StatsBase) MetricData(com.newrelic.agent.MetricData)

Example 8 with MetricData

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()));
        }
    }
}
Also used : MockNormalizer(com.newrelic.agent.MockNormalizer) MetricData(com.newrelic.agent.MetricData)

Example 9 with MetricData

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;
}
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 10 with MetricData

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;
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) ArrayList(java.util.ArrayList) MetricData(com.newrelic.agent.MetricData)

Aggregations

MetricData (com.newrelic.agent.MetricData)19 Test (org.junit.Test)12 MockNormalizer (com.newrelic.agent.MockNormalizer)10 Transaction (com.newrelic.agent.Transaction)4 HashMap (java.util.HashMap)4 CountStats (com.newrelic.agent.stats.CountStats)3 ArrayList (java.util.ArrayList)3 StatsBase (com.newrelic.agent.stats.StatsBase)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintWriter (java.io.PrintWriter)2 AgentConfig (com.newrelic.agent.config.AgentConfig)1 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)1 MetricName (com.newrelic.agent.metric.MetricName)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 Field (java.lang.reflect.Field)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1