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