Search in sources :

Example 21 with StatsEngineImpl

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

the class JmxMetricTest method jmxMetricRecordStatsSimpleForMultiBean.

@Test
public void jmxMetricRecordStatsSimpleForMultiBean() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    actual.clear();
    values.put("hello", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(10f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
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 22 with StatsEngineImpl

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

the class JmxMetricTest method jmxMetricRecordStatsSimple.

@Test
public void jmxMetricRecordStatsSimple() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.SIMPLE);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
    values.clear();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(10f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
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 23 with StatsEngineImpl

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

the class JmxMetricTest method jmxMetricRecordStatsMonotonicallyForMultiBeanAdd.

@Test
public void jmxMetricRecordStatsMonotonicallyForMultiBeanAdd() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    values.clear();
    values.put("hello", 7f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/hello").getCallCount());
    Assert.assertEquals(12f, stats.getStats("Jmx/Sample/hello").getTotal(), 0);
}
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 24 with StatsEngineImpl

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

the class JmxGetTest method testJmxGetStatsSingleSimilar.

@Test
public void testJmxGetStatsSingleSimilar() throws MalformedObjectNameException {
    StatsEngine stats = new StatsEngineImpl();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello3", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye3", JmxType.SIMPLE));
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*", "JmxBuiltIn/ThreadPool/{key1}", metrics, null, null);
    Map<ObjectName, Map<String, Float>> data = new HashMap<>();
    Map<String, Float> values1 = new HashMap<>();
    values1.put("hello3", 2f);
    values1.put("goodbye3", 3f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=b"), values1);
    Map<String, Float> values2 = new HashMap<>();
    values2.put("hello3", 4f);
    values2.put("goodbye3", 5f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=c"), values2);
    Map<String, Float> values3 = new HashMap<>();
    values3.put("hello3", 5f);
    values3.put("goodbye3", 7f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=d"), values3);
    object.recordStats(stats, data, server);
    Assert.assertEquals(3, stats.getStats("JmxBuiltIn/ThreadPool/a/hello3").getCallCount());
    Assert.assertEquals(3, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye3").getCallCount());
    Assert.assertEquals(11f, stats.getStats("JmxBuiltIn/ThreadPool/a/hello3").getTotal(), .001);
    Assert.assertEquals(15f, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye3").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatsEngine(com.newrelic.agent.stats.StatsEngine) ObjectName(javax.management.ObjectName) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 25 with StatsEngineImpl

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

the class JmxGetTest method testJmxGetStatsMultiSimilar.

@Test
public void testJmxGetStatsMultiSimilar() throws MalformedObjectNameException {
    StatsEngine stats = new StatsEngineImpl();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello2", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye2", JmxType.MONOTONICALLY_INCREASING));
    JmxGet object = new JmxMultiMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*", "JmxBuiltIn/ThreadPool/{key1}", metrics, null, null);
    Map<ObjectName, Map<String, Float>> data = new HashMap<>();
    Map<String, Float> values1 = new HashMap<>();
    values1.put("hello2", 2f);
    values1.put("goodbye2", 4f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=b"), values1);
    Map<String, Float> values2 = new HashMap<>();
    values2.put("hello2", 4f);
    values2.put("goodbye2", 5f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=c"), values2);
    Map<String, Float> values3 = new HashMap<>();
    values3.put("hello2", 5f);
    values3.put("goodbye2", 7f);
    data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=d"), values3);
    object.recordStats(stats, data, server);
    Assert.assertEquals(11f, stats.getStats("JmxBuiltIn/ThreadPool/a/hello2").getTotal(), .001);
    Assert.assertEquals(16f, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye2").getTotal(), .001);
    Assert.assertEquals(1, stats.getStats("JmxBuiltIn/ThreadPool/a/hello2").getCallCount());
    Assert.assertEquals(1, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye2").getCallCount());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatsEngine(com.newrelic.agent.stats.StatsEngine) ObjectName(javax.management.ObjectName) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServer(javax.management.MBeanServer) 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