Search in sources :

Example 6 with Stats

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);
}
Also used : Transaction(org.hibernate.Transaction) Stats(com.newrelic.agent.stats.Stats) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

Example 7 with Stats

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();
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Stats(com.newrelic.agent.stats.Stats) Environment(com.newrelic.agent.environment.Environment) CountDownLatch(java.util.concurrent.CountDownLatch) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test) AgentConfigFactoryTest(com.newrelic.agent.config.AgentConfigFactoryTest)

Example 8 with Stats

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();
    }
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) EnvironmentHolderSettingsGenerator(test.newrelic.EnvironmentHolderSettingsGenerator) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Tracer(com.newrelic.agent.tracers.Tracer) CountDownLatch(java.util.concurrent.CountDownLatch) StatsEngine(com.newrelic.agent.stats.StatsEngine) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) Stats(com.newrelic.agent.stats.Stats) TransactionData(com.newrelic.agent.TransactionData) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 9 with Stats

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();
    }
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Stats(com.newrelic.agent.stats.Stats) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 10 with Stats

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;
}
Also used : ArrayList(java.util.ArrayList) AbstractStats(com.newrelic.agent.stats.AbstractStats) Stats(com.newrelic.agent.stats.Stats) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Stats (com.newrelic.agent.stats.Stats)11 Test (org.junit.Test)6 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)4 StatsEngine (com.newrelic.agent.stats.StatsEngine)4 Trace (com.newrelic.api.agent.Trace)4 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 ArrayList (java.util.ArrayList)3 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Transaction (org.hibernate.Transaction)2 Session (org.hibernate.classic.Session)2 TransactionData (com.newrelic.agent.TransactionData)1 TransactionListener (com.newrelic.agent.TransactionListener)1 AgentConfigFactoryTest (com.newrelic.agent.config.AgentConfigFactoryTest)1 Environment (com.newrelic.agent.environment.Environment)1 AbstractStats (com.newrelic.agent.stats.AbstractStats)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 StatsService (com.newrelic.agent.stats.StatsService)1 Tracer (com.newrelic.agent.tracers.Tracer)1 List (java.util.List)1