Search in sources :

Example 31 with StatsEngineImpl

use of com.newrelic.agent.stats.StatsEngineImpl 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 32 with StatsEngineImpl

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

the class RequestUriConfigTests method runHarvest.

public MockRPMService runHarvest() {
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    return (MockRPMService) ServiceFactory.getRPMService();
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 33 with StatsEngineImpl

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

the class J2EEStatsAttributeTest method addJmxValueJdbcTest.

@Test
public void addJmxValueJdbcTest() throws MalformedObjectNameException {
    JDBCStats count = new JDBCStats() {

        @Override
        public Statistic[] getStatistics() {
            return new Statistic[0];
        }

        @Override
        public String[] getStatisticNames() {
            return null;
        }

        @Override
        public Statistic getStatistic(String statisticName) {
            return null;
        }

        @Override
        public JDBCConnectionStats[] getConnections() {
            return new JDBCConnectionStats[0];
        }

        @Override
        public JDBCConnectionPoolStats[] getConnectionPools() {
            return new JDBCConnectionPoolStats[] { new TestJdbcConnectionPool() };
        }
    };
    Attribute att = new Attribute("stats", count);
    J2EEStatsAttributeProcessor processor = new J2EEStatsAttributeProcessor();
    StatsEngine engine = new StatsEngineImpl();
    processor.process(engine, new ObjectInstance("tezt:type=1", "test"), att, "JMX/Test", new HashMap<String, Float>());
    // check count stats
    Assert.assertEquals(77, engine.getStats("JMX/Test/Create").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Create").getCallCount(), .001);
    Assert.assertEquals(9, engine.getStats("JMX/Test/Close").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Close").getCallCount(), .001);
    // check time stats
    Assert.assertEquals(12, engine.getResponseTimeStats("JMX/Test/WaitTime").getMaxCallTime(), .001);
    Assert.assertEquals(8, engine.getResponseTimeStats("JMX/Test/WaitTime").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/WaitTime").getCallCount(), .001);
    Assert.assertEquals(6, engine.getResponseTimeStats("JMX/Test/UserTime").getMaxCallTime(), .001);
    Assert.assertEquals(4, engine.getResponseTimeStats("JMX/Test/UserTime").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/UserTime").getCallCount(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) JDBCConnectionStats(javax.management.j2ee.statistics.JDBCConnectionStats) ObjectInstance(javax.management.ObjectInstance) JDBCStats(javax.management.j2ee.statistics.JDBCStats) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) TimeStatistic(javax.management.j2ee.statistics.TimeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) BoundaryStatistic(javax.management.j2ee.statistics.BoundaryStatistic) Statistic(javax.management.j2ee.statistics.Statistic) JDBCConnectionPoolStats(javax.management.j2ee.statistics.JDBCConnectionPoolStats) Test(org.junit.Test)

Example 34 with StatsEngineImpl

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

the class J2EEStatsAttributeTest method processStatRangeTest.

@Test
public void processStatRangeTest() {
    RangeStatistic count = new RangeStatistic() {

        @Override
        public String getUnit() {
            return null;
        }

        @Override
        public long getStartTime() {
            return 0;
        }

        @Override
        public String getName() {
            return "LiveCount";
        }

        @Override
        public long getLastSampleTime() {
            return 0;
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public long getLowWaterMark() {
            return 0;
        }

        @Override
        public long getHighWaterMark() {
            return 10;
        }

        @Override
        public long getCurrent() {
            return 9;
        }
    };
    Attribute att = new Attribute("stats.LiveCount", count);
    StatsEngine statsEngine = new StatsEngineImpl();
    J2EEStatsAttributeProcessor.processStatistic(statsEngine, "Jmx/Test", att, count);
    Assert.assertEquals(9, statsEngine.getStats("Jmx/Test/LiveCount").getTotal(), .001);
}
Also used : RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 35 with StatsEngineImpl

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

the class J2EEStatsAttributeTest method addJcaValueJdbcTest.

@Test
public void addJcaValueJdbcTest() throws MalformedObjectNameException {
    JCAStats count = new JCAStats() {

        @Override
        public JCAConnectionStats[] getConnections() {
            return new JCAConnectionStats[0];
        }

        @Override
        public JCAConnectionPoolStats[] getConnectionPools() {
            return new JCAConnectionPoolStats[] { new TestJcaConnectionPool() };
        }

        @Override
        public Statistic getStatistic(String statisticName) {
            return null;
        }

        @Override
        public String[] getStatisticNames() {
            return null;
        }

        @Override
        public Statistic[] getStatistics() {
            return new Statistic[0];
        }
    };
    Attribute att = new Attribute("stats", count);
    J2EEStatsAttributeProcessor processor = new J2EEStatsAttributeProcessor();
    StatsEngine engine = new StatsEngineImpl();
    processor.process(engine, new ObjectInstance("tezt:type=2", "test"), att, "JMX/Test", new HashMap<String, Float>());
    // check count stats
    Assert.assertEquals(6, engine.getStats("JMX/Test/Create").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Create").getCallCount(), .001);
    Assert.assertEquals(99, engine.getStats("JMX/Test/Closed").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Closed").getCallCount(), .001);
    // check time stats
    Assert.assertEquals(10, engine.getResponseTimeStats("JMX/Test/Wait").getMaxCallTime(), .001);
    Assert.assertEquals(5, engine.getResponseTimeStats("JMX/Test/Wait").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/Wait").getCallCount(), .001);
    Assert.assertEquals(6, engine.getResponseTimeStats("JMX/Test/User").getMaxCallTime(), .001);
    Assert.assertEquals(4, engine.getResponseTimeStats("JMX/Test/User").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/User").getCallCount(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) JCAConnectionStats(javax.management.j2ee.statistics.JCAConnectionStats) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) TimeStatistic(javax.management.j2ee.statistics.TimeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) BoundaryStatistic(javax.management.j2ee.statistics.BoundaryStatistic) Statistic(javax.management.j2ee.statistics.Statistic) JCAStats(javax.management.j2ee.statistics.JCAStats) JCAConnectionPoolStats(javax.management.j2ee.statistics.JCAConnectionPoolStats) Test(org.junit.Test)

Aggregations

StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)53 Test (org.junit.Test)46 StatsEngine (com.newrelic.agent.stats.StatsEngine)31 HashMap (java.util.HashMap)30 JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)20 MockRPMService (com.newrelic.agent.MockRPMService)18 MockHarvestService (com.newrelic.agent.MockHarvestService)13 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)12 SqlTracer (com.newrelic.agent.tracers.SqlTracer)12 Tracer (com.newrelic.agent.tracers.Tracer)12 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)12 Map (java.util.Map)9 JSONArray (org.json.simple.JSONArray)6 SqlObfuscator (com.newrelic.agent.database.SqlObfuscator)5 TransactionStats (com.newrelic.agent.stats.TransactionStats)5 ArrayList (java.util.ArrayList)5 MBeanServer (javax.management.MBeanServer)5 TransactionData (com.newrelic.agent.TransactionData)4 TransactionService (com.newrelic.agent.TransactionService)4 Attribute (javax.management.Attribute)4