use of com.newrelic.agent.stats.Stats in project newrelic-java-agent by newrelic.
the class HibernateStatsTest method transactions.
@Trace(dispatcher = true)
@Test
public void transactions() {
float count = 10;
for (int i = 0; i < count; i++) {
Transaction tx = session.beginTransaction();
tx.commit();
}
runSamplers();
Stats stats = getTransactionStats().getStats("HibernateStatistics/transactions");
assertEquals(count, stats.getTotal(), 0);
}
use of com.newrelic.agent.stats.Stats in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method metricLimit.
@Test
public void metricLimit() throws Exception {
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
environment.setServerPort(null);
final CountDownLatch latch = new CountDownLatch(2);
MyRPMService rpmService = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
latch.countDown();
if (latch.getCount() == 1) {
Assert.assertEquals(MetricIdRegistry.METRIC_LIMIT + 100, statsEngine.getSize());
} else {
Assert.assertEquals(1, statsEngine.getSize());
}
}
};
TestHarvestService harvestService = new TestHarvestService();
harvestService.setReportingPeriod(500L);
harvestService.start();
StatsEngineImpl statsEngine = new StatsEngineImpl();
for (int i = 0; i < MetricIdRegistry.METRIC_LIMIT + 100; i++) {
Stats stats = statsEngine.getStats("Test" + String.valueOf(i));
stats.recordDataPoint(100f);
}
ServiceFactory.getStatsService().doStatsWork(new MergeStatsWork("test", statsEngine), "statsWorkTest");
harvestService.startHarvest(rpmService);
Assert.assertTrue(latch.await(5L, TimeUnit.SECONDS));
harvestService.stop();
}
use of com.newrelic.agent.stats.Stats in project newrelic-java-agent by newrelic.
the class KafkaTest method produceConsumeTest.
@Test
public void produceConsumeTest() throws Exception {
EnvironmentHolderSettingsGenerator envHolderSettings = new EnvironmentHolderSettingsGenerator(CONFIG_FILE, "all_enabled_test", CLASS_LOADER);
EnvironmentHolder holder = new EnvironmentHolder(envHolderSettings);
holder.setupEnvironment();
kafkaUnitRule.getKafkaUnit().createTopic(testTopic, 1);
final KafkaConsumer<String, String> consumer = setupConsumer();
final CountDownLatch latch = new CountDownLatch(1);
final ConcurrentLinkedQueue<TransactionData> finishedTransactions = new ConcurrentLinkedQueue<>();
TransactionListener transactionListener = new TransactionListener() {
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
finishedTransactions.add(transactionData);
latch.countDown();
}
};
ServiceFactory.getTransactionService().addTransactionListener(transactionListener);
try {
produceMessage();
final Future<?> submit = executorService.submit(new Runnable() {
@Override
public void run() {
consumeMessage(consumer);
}
});
submit.get(30, TimeUnit.SECONDS);
latch.await(30, TimeUnit.SECONDS);
Assert.assertEquals(2, finishedTransactions.size());
// Wait for the metrics reporter
Thread.sleep(1000);
// Assert on the kafka metrics that we're expecting
StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName());
Stats messagesConsumed = statsEngine.getStats("MessageBroker/Kafka/Internal/consumer-fetch-manager-metrics/records-consumed-rate");
Assert.assertNotNull(messagesConsumed);
Assert.assertTrue(messagesConsumed.getCallCount() > 1);
Assert.assertTrue(messagesConsumed.getTotal() > 0);
Stats bytesConsumed = statsEngine.getStats("MessageBroker/Kafka/Internal/consumer-metrics/incoming-byte-rate");
Assert.assertNotNull(bytesConsumed);
Assert.assertTrue(bytesConsumed.getCallCount() > 1);
Assert.assertTrue(bytesConsumed.getTotal() > 0);
Stats rebalanceAssignedPartition = statsEngine.getStats("MessageBroker/Kafka/Rebalance/Assigned/" + testTopic + "/0");
Assert.assertNotNull(rebalanceAssignedPartition);
Assert.assertEquals(1, rebalanceAssignedPartition.getCallCount());
Stats serializationByTopic = statsEngine.getStats("MessageBroker/Kafka/Serialization/TestTopic");
Assert.assertNotNull(serializationByTopic);
// One for the key, one for the value
Assert.assertEquals(2, serializationByTopic.getCallCount());
Assert.assertTrue(serializationByTopic.getTotal() > 1);
Stats deserializationByTopic = statsEngine.getStats("MessageBroker/Kafka/Deserialization/TestTopic");
Assert.assertNotNull(deserializationByTopic);
// One for the key, one for the value
Assert.assertEquals(2, deserializationByTopic.getCallCount());
Assert.assertTrue(deserializationByTopic.getTotal() > 1);
// external reporting test
TransactionData prodTxn = finishedTransactions.poll();
Collection<Tracer> tracers = prodTxn.getTracers();
Iterator<Tracer> iterator = tracers.iterator();
Assert.assertTrue(iterator.hasNext());
Tracer tracer = iterator.next();
Assert.assertEquals("MessageBroker/Kafka/Topic/Produce/Named/TestTopic", tracer.getMetricName());
TransactionData conTxn = finishedTransactions.poll();
Tracer rootTracer = conTxn.getRootTracer();
Assert.assertEquals("MessageBroker/Kafka/Topic/Consume/Named/TestTopic", rootTracer.getMetricName());
Assert.assertNotNull(conTxn.getInboundDistributedTracePayload());
} finally {
ServiceFactory.getTransactionService().removeTransactionListener(transactionListener);
consumer.close();
}
}
use of com.newrelic.agent.stats.Stats in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doHarvest.
private void doHarvest() throws Exception {
List<String> appNames = singletonList("MyApplication");
RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
svc.launch();
synchronized (this) {
wait(1000);
}
StatsEngine harvestStatsEngine = new StatsEngineImpl();
try {
for (int i = 0; i < 1000; i++) {
harvestStatsEngine.getResponseTimeStats(MetricNames.EXTERNAL_ALL).recordResponseTime(66, TimeUnit.MILLISECONDS);
}
svc.harvest(harvestStatsEngine);
Stats stats3 = harvestStatsEngine.getStats(MetricNames.AGENT_METRICS_COUNT);
assertEquals(0, stats3.getCallCount());
ResponseTimeStats stats = harvestStatsEngine.getResponseTimeStats(MetricNames.SUPPORTABILITY_METRIC_HARVEST_TRANSMIT);
assertEquals(1, stats.getCallCount());
assertTrue(stats.getTotal() > 0);
Stats stats2 = harvestStatsEngine.getStats(MetricNames.SUPPORTABILITY_METRIC_HARVEST_COUNT);
assertEquals(1, stats2.getCallCount());
} finally {
svc.shutdown();
}
}
use of com.newrelic.agent.stats.Stats in project newrelic-java-agent by newrelic.
the class JSONSerializerTest method buildListOfMetricData.
private List buildListOfMetricData(int size) throws Exception {
List l = new ArrayList();
for (int i = 0; i < size; i++) {
String metricName = "Metric " + Integer.toString(i);
MetricData md = MetricData.create(MetricName.create(metricName), StatsTest.createStats());
Stats s = (Stats) md.getStats();
s.recordDataPoint(i);
Assert.assertEquals(1, s.getCallCount());
Assert.assertEquals(i, (int) s.getMaxCallTime());
Assert.assertEquals(i, (int) s.getTotal());
l.add(md);
JSONArray jsonObject = (JSONArray) AgentHelper.serializeJSON(s);
Assert.assertEquals(6, jsonObject.size());
Assert.assertEquals(1l, jsonObject.get(0));
if (i > 0) {
Assert.assertEquals(i, ((Number) jsonObject.get(1)).intValue());
}
}
return l;
}
Aggregations