Search in sources :

Example 1 with Stats

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

the class RPMServiceTest method createMetricData.

private List<MetricData> createMetricData(StatsEngine statsEngine, int size) {
    ArrayList<MetricData> data = new ArrayList<>();
    for (float i = 0; i < size; i++) {
        String metric = "Metric " + i;
        Stats stats = StatsTest.createStats(statsEngine);
        stats.recordDataPoint(i / (System.currentTimeMillis() % 10000));
        data.add(MetricData.create(MetricName.create(metric), stats));
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Stats(com.newrelic.agent.stats.Stats)

Example 2 with Stats

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

the class DefaultTracerTest method checkUnknownDatastoreSupportabilityMetrics.

private void checkUnknownDatastoreSupportabilityMetrics(String product, int expectedUnkownHost, int expectedUnknownPort, int expectedUnknownDatabaseName) {
    StatsService statsService = ServiceFactory.getStatsService();
    StatsEngine statsEngine = statsService.getStatsEngineForHarvest("Unit Test");
    String unknownHostMetricName = new StringBuilder(MetricNames.SUPPORTABILITY_DATASTORE_PREFIX).append(product).append(MetricNames.SUPPORTABILITY_DATASTORE_UNKNOWN_HOST).toString();
    Stats unknownHostMetric = statsEngine.getStats(unknownHostMetricName);
    assertEquals(expectedUnkownHost, unknownHostMetric.getCallCount());
    String unknownPortMetricName = new StringBuilder(MetricNames.SUPPORTABILITY_DATASTORE_PREFIX).append(product).append(MetricNames.SUPPORTABILITY_DATASTORE_UNKNOWN_PORT).toString();
    Stats unknownPortMetric = statsEngine.getStats(unknownPortMetricName);
    assertEquals(expectedUnknownPort, unknownPortMetric.getCallCount());
    String unknownDatabaseMetricName = new StringBuilder(MetricNames.SUPPORTABILITY_DATASTORE_PREFIX).append(product).append(MetricNames.SUPPORTABILITY_DATASTORE_UNKNOWN_DATABASE_NAME).toString();
    Stats unknownDatabaseNameMetric = statsEngine.getStats(unknownDatabaseMetricName);
    assertEquals(expectedUnknownDatabaseName, unknownDatabaseNameMetric.getCallCount());
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) TransactionStats(com.newrelic.agent.stats.TransactionStats) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Stats(com.newrelic.agent.stats.Stats) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 3 with Stats

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

the class HibernateStatsTest method flushes.

@Trace(dispatcher = true)
@Test
public void flushes() {
    float count = 10;
    for (int i = 0; i < count; i++) {
        Player dude = new Player();
        dude.setId(nextId++);
        session.save(null, dude);
        session.flush();
    }
    runSamplers();
    Stats stats = getTransactionStats().getStats("HibernateStatistics/flushes");
    assertEquals(count, stats.getTotal(), 0);
}
Also used : Stats(com.newrelic.agent.stats.Stats) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

Example 4 with Stats

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

the class HibernateStatsTest method insertsAndLoads.

@Trace(dispatcher = true)
@Test
public void insertsAndLoads() {
    runSamplers();
    getTransactionStats().clear();
    Transaction transaction = session.beginTransaction();
    Player dude = new Player();
    dude.setId(nextId++);
    session.save(null, dude);
    Game game = new Game();
    game.setId(nextId++);
    session.save(null, game);
    session.load(Player.class, dude.getId());
    transaction.commit();
    Session session2 = sessionFactory.openSession();
    Criteria criteria = session2.createCriteria(Player.class);
    assertEquals(1, criteria.list().size());
    // getTransactionStats().clear();
    runSamplers();
    SimpleStatsEngine statsEngine = getTransactionStats();
    Stats stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/loads");
    assertEquals(1f, stats.getTotal(), 0);
    statsEngine.getStats("HibernateStatistics/entityLoads");
    assertEquals(1f, stats.getTotal(), 0);
    stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/inserts");
    assertEquals(1f, stats.getTotal(), 0);
    stats = statsEngine.getStats("HibernateStatistics/entityInserts");
    assertEquals(2f, stats.getTotal(), 0);
    stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/deletes");
    assertEquals(1, stats.getCallCount());
    assertEquals(0f, stats.getTotal(), 0);
    statsEngine = getTransactionStats();
    statsEngine.clear();
    runSamplers();
    stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/inserts");
    assertEquals(1, stats.getCallCount());
    assertEquals(0f, stats.getTotal(), 0);
}
Also used : Transaction(org.hibernate.Transaction) Stats(com.newrelic.agent.stats.Stats) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) Criteria(org.hibernate.Criteria) Session(org.hibernate.classic.Session) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

Example 5 with Stats

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

the class HibernateStatsTest method sessionStats.

@Trace(dispatcher = true)
@Test
public void sessionStats() {
    runSamplers();
    getTransactionStats().clear();
    float count = 10;
    for (int i = 0; i < count; i++) {
        Session openSession = sessionFactory.openSession();
        openSession.close();
    }
    Session openSession = sessionFactory.openSession();
    runSamplers();
    Stats stats = getTransactionStats().getStats("HibernateStatistics/sessionOpens");
    assertEquals(count + 1, stats.getTotal(), 0);
    stats = getTransactionStats().getStats("HibernateStatistics/sessionCloses");
    assertEquals(count, stats.getTotal(), 0);
    openSession.close();
}
Also used : Stats(com.newrelic.agent.stats.Stats) Session(org.hibernate.classic.Session) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

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