Search in sources :

Example 16 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxGetTest method testGetRootMetricWithNonExistKey.

@Test
public void testGetRootMetricWithNonExistKey() throws MalformedObjectNameException {
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye", JmxType.MONOTONICALLY_INCREASING));
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*,key2=*", "TheRoot/Wahoo/{type}/{keydoesnotexist}/", metrics, null, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/TheRoot/Wahoo/rara//", root);
}
Also used : ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 17 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxGetTest method testGetRootMetricWithPattern.

@Test
public void testGetRootMetricWithPattern() throws MalformedObjectNameException {
    List<JmxMetric> metrics = new ArrayList<>();
    metrics.add(JmxMetric.create("hello", JmxType.SIMPLE));
    metrics.add(JmxMetric.create("goodbye", JmxType.MONOTONICALLY_INCREASING));
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*,key2=*", "TheRoot/Wahoo/{type}/{key1}", metrics, null, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/TheRoot/Wahoo/rara/value1/", root);
}
Also used : ArrayList(java.util.ArrayList) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 18 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric 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 19 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxGetTest method testNullRootMetricNameMulti.

@Test
public void testNullRootMetricNameMulti() throws MalformedObjectNameException {
    JmxGet object = new JmxMultiMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*,key2=*", null, new ArrayList<JmxMetric>(), null, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:type=rara,key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/ThreadPool/rara/value1/value2/", root);
}
Also used : JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 20 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric 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

JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)32 Test (org.junit.Test)29 HashMap (java.util.HashMap)21 StatsEngine (com.newrelic.agent.stats.StatsEngine)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)20 ObjectName (javax.management.ObjectName)12 ArrayList (java.util.ArrayList)11 MBeanServer (javax.management.MBeanServer)5 Map (java.util.Map)3 BaseJmxValue (com.newrelic.agent.jmx.metrics.BaseJmxValue)1