Search in sources :

Example 1 with JmxType

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

the class JmxGetTest method testGetRootMetricNoTypeMulti.

@Test
public void testGetRootMetricNoTypeMulti() throws MalformedObjectNameException {
    Map<JmxType, List<String>> mapping = new HashMap<>();
    List<String> atts = new ArrayList<>();
    atts.add("Name");
    atts.add("Date");
    atts.add("Time");
    mapping.put(JmxType.SIMPLE, atts);
    JmxGet object = new JmxMultiMBeanGet("ThreadPool:key1=*,key2=*", null, "ThreadPool:type=rara,key1=*,key2=*", mapping, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/ThreadPool/null/value2/value1/", root);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JmxType(com.newrelic.agent.jmx.JmxType) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 2 with JmxType

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

the class JmxGetTest method testGetRootMetricNoType.

@Test
public void testGetRootMetricNoType() throws MalformedObjectNameException {
    Map<JmxType, List<String>> mapping = new HashMap<>();
    List<String> atts = new ArrayList<>();
    atts.add("Name");
    atts.add("Date");
    atts.add("Time");
    mapping.put(JmxType.SIMPLE, atts);
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:key1=*,key2=*", null, "ThreadPool:type=rara,key1=*,key2=*", mapping, null);
    String root = object.getRootMetricName(new ObjectName("ThreadPool:key1=value1,key2=value2"), getServer());
    Assert.assertEquals("JMX/ThreadPool/null/value2/value1/", root);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JmxType(com.newrelic.agent.jmx.JmxType) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 3 with JmxType

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

the class JmxYmlParserTest method testFileWithInvalidMetricAttributes.

@Test
public void testFileWithInvalidMetricAttributes() throws Exception {
    File theFile = getFile(INVALID_METRICS_TEST_PATH);
    Config input = readYml(theFile);
    Object jmx = input.getProperty("jmx");
    Assert.assertNotNull(jmx);
    List<Map> jmxConfigs = (List<Map>) jmx;
    Map jmxConfig = jmxConfigs.get(0);
    JmxYmlParser parser = new JmxYmlParser(jmxConfig);
    Map<JmxType, List<String>> attrs = parser.getAttrs();
    Assert.assertNull(attrs);
}
Also used : BaseConfig(com.newrelic.agent.config.BaseConfig) Config(com.newrelic.agent.config.Config) List(java.util.List) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Map(java.util.Map) JmxType(com.newrelic.agent.jmx.JmxType) Test(org.junit.Test)

Example 4 with JmxType

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

the class JmxYmlParserTest method testSampleSolrFile.

@Test
public void testSampleSolrFile() throws Exception {
    File theFile = getFile(SOLR_TEST_PATH);
    Config input = readYml(theFile);
    Object jmx = input.getProperty("jmx");
    Assert.assertNotNull(jmx);
    List<Map> jmxConfigs = (List<Map>) jmx;
    Assert.assertEquals(7, jmxConfigs.size());
    /*
         * - object_name: solr*:type=queryResultCache,* metrics: - attributes: lookups, hits, inserts, evictions,
         * cumulative_lookups, cumulative_hits, cumulative_inserts, cumulative_evictions type: monotonically_increasing
         * - attributes: hitratio, size, cumulative_hitratio
         */
    Map jmxConfig = jmxConfigs.get(0);
    JmxYmlParser parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(true, parser.getEnabled());
    Assert.assertEquals("solr*:type=queryResultCache,*", parser.getObjectName());
    Map<JmxType, List<String>> attrs = parser.getAttrs();
    Assert.assertNotNull(attrs);
    List<String> simpleAtts = attrs.get(JmxType.SIMPLE);
    Assert.assertNull(simpleAtts);
    List<String> monoAtts = attrs.get(JmxType.MONOTONICALLY_INCREASING);
    Assert.assertNotNull(monoAtts);
    Assert.assertEquals(11, monoAtts.size());
    Assert.assertTrue(monoAtts.contains("lookups"));
    Assert.assertTrue(monoAtts.contains("hits"));
    Assert.assertTrue(monoAtts.contains("inserts"));
    Assert.assertTrue(monoAtts.contains("cumulative_inserts"));
    Assert.assertTrue(monoAtts.contains("cumulative_evictions"));
    Assert.assertTrue(monoAtts.contains("hitratio"));
    Assert.assertTrue(monoAtts.contains("size"));
    Assert.assertTrue(monoAtts.contains("cumulative_hitratio"));
    /*
         * - object_name: solr*:type=filterCache,* metrics: - attributes: lookups, hits, inserts, evictions,
         * cumulative_lookups, cumulative_hits, cumulative_inserts, cumulative_evictions - attributes: hitratio, size,
         * cumulative_hitratio type: simple
         */
    jmxConfig = jmxConfigs.get(1);
    parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(true, parser.getEnabled());
    Assert.assertEquals("solr*:type=filterCache,*", parser.getObjectName());
    attrs = parser.getAttrs();
    Assert.assertNotNull(attrs);
    simpleAtts = attrs.get(JmxType.SIMPLE);
    Assert.assertNotNull(simpleAtts);
    Assert.assertEquals(3, simpleAtts.size());
    Assert.assertTrue(simpleAtts.contains("hitratio"));
    Assert.assertTrue(simpleAtts.contains("size"));
    Assert.assertTrue(simpleAtts.contains("cumulative_hitratio"));
    monoAtts = attrs.get(JmxType.MONOTONICALLY_INCREASING);
    Assert.assertNotNull(monoAtts);
    Assert.assertEquals(8, monoAtts.size());
    Assert.assertTrue(monoAtts.contains("lookups"));
    Assert.assertTrue(monoAtts.contains("hits"));
    Assert.assertTrue(monoAtts.contains("inserts"));
    Assert.assertTrue(monoAtts.contains("evictions"));
    Assert.assertTrue(monoAtts.contains("cumulative_lookups"));
    /*
         * - object_name: solr*:type=documentCache,* metrics:
         */
    jmxConfig = jmxConfigs.get(2);
    parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(true, parser.getEnabled());
    Assert.assertEquals("solr*:type=documentCache,*", parser.getObjectName());
    attrs = parser.getAttrs();
    Assert.assertNull(attrs);
    /*
         * - object_name: solr*:type==empty,*
         */
    jmxConfig = jmxConfigs.get(3);
    parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(true, parser.getEnabled());
    Assert.assertEquals("solr*:type==empty,*", parser.getObjectName());
    attrs = parser.getAttrs();
    Assert.assertNull(attrs);
    /*
         * - object_name: solr*:type=updateHandler,* metrics: - attribute: docsPending type: simple - attributes:
         * expungeDeletes, rollbacks, optimizes, autocommits, commits, errors, adds, deletesById, deletesByQuery -
         * attributes: cumulative_adds, cumulative_deletesById, cumulative_deletesByQuery, cumulative_errors
         */
    jmxConfig = jmxConfigs.get(4);
    parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(true, parser.getEnabled());
    Assert.assertEquals("solr*:type=updateHandler,*", parser.getObjectName());
    attrs = parser.getAttrs();
    Assert.assertNotNull(attrs);
    simpleAtts = attrs.get(JmxType.SIMPLE);
    Assert.assertNotNull(simpleAtts);
    Assert.assertEquals(1, simpleAtts.size());
    monoAtts = attrs.get(JmxType.MONOTONICALLY_INCREASING);
    Assert.assertNotNull(monoAtts);
    Assert.assertEquals(13, monoAtts.size());
    Assert.assertTrue(monoAtts.contains("expungeDeletes"));
    Assert.assertTrue(monoAtts.contains("rollbacks"));
    Assert.assertTrue(monoAtts.contains("optimizes"));
    Assert.assertTrue(monoAtts.contains("autocommits"));
    Assert.assertTrue(monoAtts.contains("commits"));
    Assert.assertTrue(monoAtts.contains("errors"));
    Assert.assertTrue(monoAtts.contains("adds"));
    Assert.assertTrue(monoAtts.contains("deletesById"));
    Assert.assertTrue(monoAtts.contains("deletesByQuery"));
    Assert.assertTrue(monoAtts.contains("cumulative_adds"));
    Assert.assertTrue(monoAtts.contains("cumulative_deletesByQuery"));
    Assert.assertTrue(monoAtts.contains("cumulative_deletesById"));
    Assert.assertTrue(monoAtts.contains("cumulative_errors"));
    jmxConfig = jmxConfigs.get(5);
    parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(false, parser.getEnabled());
    Assert.assertEquals("solr*:type=yay", parser.getObjectName());
    jmxConfig = jmxConfigs.get(6);
    parser = new JmxYmlParser(jmxConfig);
    Assert.assertEquals(true, parser.getEnabled());
    Assert.assertEquals("solr*:type=rara", parser.getObjectName());
}
Also used : BaseConfig(com.newrelic.agent.config.BaseConfig) Config(com.newrelic.agent.config.Config) List(java.util.List) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Map(java.util.Map) JmxType(com.newrelic.agent.jmx.JmxType) Test(org.junit.Test)

Example 5 with JmxType

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

the class JmxGetTest method testGetRootMetricDefault.

@Test
public void testGetRootMetricDefault() throws MalformedObjectNameException {
    Map<JmxType, List<String>> mapping = new HashMap<>();
    List<String> atts = new ArrayList<>();
    atts.add("Name");
    atts.add("Date");
    atts.add("Time");
    mapping.put(JmxType.SIMPLE, atts);
    JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", null, "ThreadPool:type=rara,key1=*,key2=*", mapping, 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 : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JmxType(com.newrelic.agent.jmx.JmxType) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

JmxType (com.newrelic.agent.jmx.JmxType)5 List (java.util.List)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ObjectName (javax.management.ObjectName)3 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)2 BaseConfig (com.newrelic.agent.config.BaseConfig)2 Config (com.newrelic.agent.config.Config)2 File (java.io.File)2 Map (java.util.Map)2