Search in sources :

Example 11 with StatsEngineImpl

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

the class JmxServiceTest method process.

@Test
public void process() {
    String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
    StatsEngine statsEngine = new StatsEngineImpl();
    JmxService jmxService = ServiceFactory.getJmxService();
    jmxService.beforeHarvest(appName, statsEngine);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) JmxService(com.newrelic.agent.jmx.JmxService) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 12 with StatsEngineImpl

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

the class JmxServiceTest method testAddingToConfig.

@Test
public void testAddingToConfig() {
    JmxService jmxService = ServiceFactory.getJmxService();
    List<JmxGet> configurations = jmxService.getConfigurations();
    int startupsize = configurations.size();
    TomcatJmxValues tomcat = new TomcatJmxValues();
    ResinJmxValues resin = new ResinJmxValues();
    jmxService.addJmxFrameworkValues(tomcat);
    jmxService.addJmxFrameworkValues(resin);
    String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
    StatsEngine statsEngine = new StatsEngineImpl();
    jmxService.beforeHarvest(appName, statsEngine);
    int expectedSize = startupsize + tomcat.getFrameworkMetrics().size() + resin.getFrameworkMetrics().size();
    Assert.assertEquals("Failed on initial check: " + configurations.toString(), expectedSize, configurations.size());
    GlassfishJmxValues glassfish = new GlassfishJmxValues();
    jmxService.addJmxFrameworkValues(glassfish);
    jmxService.beforeHarvest(appName, statsEngine);
    int newExpectedSize = expectedSize + glassfish.getFrameworkMetrics().size();
    Assert.assertEquals("Failed on second check: " + configurations.toString(), newExpectedSize, configurations.size());
    JettyJmxMetrics jetty = new JettyJmxMetrics();
    jmxService.addJmxFrameworkValues(jetty);
    jmxService.beforeHarvest(appName, statsEngine);
    int thirdExpectedSize = newExpectedSize + jetty.getFrameworkMetrics().size();
    Assert.assertEquals("Failed on third check: " + configurations.toString(), thirdExpectedSize, configurations.size());
}
Also used : TomcatJmxValues(com.newrelic.agent.jmx.values.TomcatJmxValues) ResinJmxValues(com.newrelic.agent.jmx.values.ResinJmxValues) JettyJmxMetrics(com.newrelic.agent.jmx.values.JettyJmxMetrics) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) JmxService(com.newrelic.agent.jmx.JmxService) GlassfishJmxValues(com.newrelic.agent.jmx.values.GlassfishJmxValues) StatsEngine(com.newrelic.agent.stats.StatsEngine) JmxGet(com.newrelic.agent.jmx.create.JmxGet) Test(org.junit.Test)

Example 13 with StatsEngineImpl

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

the class J2EEStatsAttributeTest method processStatisticCountTest.

@Test
public void processStatisticCountTest() {
    CountStatistic count = new CountStatistic() {

        @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 getCount() {
            return 55;
        }
    };
    Attribute att = new Attribute("stats.LiveCount", count);
    StatsEngine statsEngine = new StatsEngineImpl();
    J2EEStatsAttributeProcessor.processStatistic(statsEngine, "Jmx/Test", att, count);
    Assert.assertEquals(55, statsEngine.getStats("Jmx/Test/LiveCount").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) Test(org.junit.Test)

Example 14 with StatsEngineImpl

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

the class JmxMetricTest method jmxMetricRecordStatsChangeNameMono.

@Test
public void jmxMetricRecordStatsChangeNameMono() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", "theHello", JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/theHello").getTotal(), 0);
    values.clear();
    values.put("hello", 7f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(7f, stats.getStats("Jmx/Sample/theHello").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 15 with StatsEngineImpl

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

the class JmxMetricTest method jmxMetricRecordStatsSubTypeMonoMultiAdd.

@Test
public void jmxMetricRecordStatsSubTypeMonoMultiAdd() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create(new String[] { "first", "second" }, "theDiffe", JmxAction.SUBTRACT_ALL_FROM_FIRST, JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("first", 10f);
    values.put("second", 7f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    Assert.assertEquals(0, stats.getStats("Jmx/Sample/theDiffe").getCallCount());
    values.clear();
    values.put("first", 12f);
    values.put("second", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theDiffe").getCallCount());
    Assert.assertEquals(10f, stats.getStats("Jmx/Sample/theDiffe").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) 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