Search in sources :

Example 1 with CountStats

use of com.newrelic.agent.stats.CountStats 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 2 with CountStats

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

the class IntrospectorStatsService method convertToTracedMetric.

private Map<String, TracedMetricData> convertToTracedMetric(SimpleStatsEngine currentEngine) {
    Map<String, TracedMetricData> output = Maps.newHashMapWithExpectedSize(currentEngine.getSize());
    for (Entry<String, StatsBase> current : currentEngine.getStatsMap().entrySet()) {
        if (current.getValue() instanceof CountStats) {
            TracedMetricData data = TracedMetricImpl.getTracedMetricFromStatsBase(current.getKey(), (CountStats) current.getValue());
            output.put(current.getKey(), data);
        }
    }
    return output;
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) CountStats(com.newrelic.agent.stats.CountStats) StatsBase(com.newrelic.agent.stats.StatsBase)

Example 3 with CountStats

use of com.newrelic.agent.stats.CountStats 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 4 with CountStats

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

the class CPUSamplerTest method test.

@Test
public void test() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("host", "localhost");
    map.put("port", 3000);
    map.put("ssl", false);
    map.put("license_key", "bootstrap_newrelic_admin_license_key_000");
    createServiceManager(map);
    StatsEngine statsEngine = new StatsEngineImpl();
    CPUHarvester harvester = new CPUHarvester();
    for (int i = 0; i < 10000; i++) {
        harvester.recordCPU(statsEngine);
        statsEngine.getMetricNames();
    }
    List<MetricName> harvest = statsEngine.getMetricNames();
    CountStats stats = null;
    for (MetricName data : harvest) {
        if (MetricNames.CPU.equals(data.getName())) {
            stats = (CountStats) statsEngine.getStats(data);
            break;
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(out);
    stats.writeJSONString(writer);
    writer.close();
    System.err.println(out.toString());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) CountStats(com.newrelic.agent.stats.CountStats) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StatsEngine(com.newrelic.agent.stats.StatsEngine) MetricName(com.newrelic.agent.metric.MetricName) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 5 with CountStats

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

the class InstrumentTestUtils method getAndClearMetricData.

public static Map<String, Integer> getAndClearMetricData() {
    StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
    List<MetricData> data = statsEngine.getMetricData(new MockNormalizer());
    Map<String, Integer> dataMap = new HashMap<>();
    for (MetricData metricData : data) {
        StatsBase stats = metricData.getStats();
        if (stats instanceof CountStats) {
            dataMap.put(metricData.getMetricName().getName(), ((CountStats) stats).getCallCount());
        } else {
            dataMap.put(metricData.getMetricName().getName(), 0);
        }
    }
    return dataMap;
}
Also used : HashMap(java.util.HashMap) CountStats(com.newrelic.agent.stats.CountStats) StatsBase(com.newrelic.agent.stats.StatsBase) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockNormalizer(com.newrelic.agent.MockNormalizer) MetricData(com.newrelic.agent.MetricData)

Aggregations

CountStats (com.newrelic.agent.stats.CountStats)5 MetricData (com.newrelic.agent.MetricData)3 StatsBase (com.newrelic.agent.stats.StatsBase)3 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 HashMap (java.util.HashMap)2 MockNormalizer (com.newrelic.agent.MockNormalizer)1 MetricName (com.newrelic.agent.metric.MetricName)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1