use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class DataSenderImplTest method testDataUsageSupportability.
@Test
public void testDataUsageSupportability() throws Exception {
AgentConfig config = AgentConfigImpl.createAgentConfig(configMap());
HttpClientWrapper wrapperEmptyReturn = getHttpClientWrapper(ReadResult.create(HttpResponseCode.OK, "", null));
DataSenderImpl target = new DataSenderImpl(config, wrapperEmptyReturn, null, logger, ServiceFactory.getConfigService());
target.setAgentRunId("agent run id");
List<MetricData> metricData = createMetricData(5);
target.sendMetricData(System.currentTimeMillis() - 5000, System.currentTimeMillis(), metricData);
// Expected payload sent after adding 5 metrics and agent metadata
final String expectedSentPayload = "[\"agent run id\",1644424673,1644424678," + "[[0,[1,1.0,1.0,1.0,1.0,1.0]]," + "[1,[1,1.0,1.0,1.0,1.0,1.0]]," + "[2,[1,1.0,1.0,1.0,1.0,1.0]]," + "[3,[1,1.0,1.0,1.0,1.0,1.0]]," + "[4,[1,1.0,1.0,1.0,1.0,1.0]]]]";
int expectedSentPayloadSizeInBytes = expectedSentPayload.getBytes().length;
// Expected payload received is empty
final String expectedReceivedPayload = "";
int expectedReceivedPayloadSizeInBytes = expectedReceivedPayload.getBytes().length;
String collectorOutputBytesMetric = MessageFormat.format(MetricNames.SUPPORTABILITY_DATA_USAGE_DESTINATION_OUTPUT_BYTES, "Collector");
String collectorEndpointOutputBytesMetric = MessageFormat.format(MetricNames.SUPPORTABILITY_DATA_USAGE_DESTINATION_ENDPOINT_OUTPUT_BYTES, "Collector", "metric_data");
assertMetricWasRecorded(MessageFormat.format(MetricNames.SUPPORTABILITY_HTTP_CODE, HttpResponseCode.OK));
assertMetricWasRecorded(collectorOutputBytesMetric);
assertMetricWasRecorded(collectorEndpointOutputBytesMetric);
assertDataUsageMetricValues(collectorOutputBytesMetric, expectedSentPayloadSizeInBytes, expectedReceivedPayloadSizeInBytes);
assertDataUsageMetricValues(collectorEndpointOutputBytesMetric, expectedSentPayloadSizeInBytes, expectedReceivedPayloadSizeInBytes);
}
use of com.newrelic.agent.MetricData 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;
}
use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class StatsEngineImpl method createUnscopedCopies.
public static List<MetricData> createUnscopedCopies(Normalizer metricNormalizer, final List<MetricData> scopedMetrics) {
// we do not want to fill up more than 75 percent of the hash map
// add two to ensure that we are under 75 percent
int size = (int) (scopedMetrics.size() / 0.75) + 2;
Map<String, MetricData> allUnscopedMetrics = new HashMap<>(size);
List<MetricData> results = new ArrayList<>(scopedMetrics.size());
// iterate through the metrics
for (MetricData scoped : scopedMetrics) {
String theMetricName = scoped.getMetricName().getName();
MetricData unscopedMetric = getUnscopedCloneOfData(metricNormalizer, theMetricName, scoped.getStats());
if (unscopedMetric != null) {
// see if we have already seen a metric with this name
MetricData mapUnscoped = allUnscopedMetrics.get(theMetricName);
if (mapUnscoped == null) {
// add to the results to send out and add to unscoped map to merge additional
allUnscopedMetrics.put(theMetricName, unscopedMetric);
results.add(unscopedMetric);
} else {
// just add it to the unscoped metric with the same metric name
mapUnscoped.getStats().merge(unscopedMetric.getStats());
}
}
}
return results;
}
use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class MetricDataTest method bad.
@Test
public void bad() throws IOException {
ResponseTimeStatsImpl stats = new ResponseTimeStatsImpl();
MetricData data = MetricData.create(MetricName.create(MetricNames.EXTERNAL_ALL), stats);
stats = new ResponseTimeStatsImpl();
MetricData data2 = MetricData.create(MetricName.create(MetricNames.DISPATCHER), stats);
stats.setCallCount(-2);
PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
JSONArray.writeJSONString(Arrays.asList(data, data2), writer);
writer.close();
}
use of com.newrelic.agent.MetricData in project newrelic-java-agent by newrelic.
the class MetricDataTest method valid.
@Test
public void valid() throws IOException {
ResponseTimeStatsImpl stats = new ResponseTimeStatsImpl();
MetricData data = MetricData.create(MetricName.create(MetricNames.EXTERNAL_ALL), stats);
PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
data.writeJSONString(writer);
writer.close();
}
Aggregations