Search in sources :

Example 1 with JmxGet

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

the class JmxServiceStartTest method testStartConfig.

@Test
public void testStartConfig() {
    JmxService jmxService = ServiceFactory.getJmxService();
    List<JmxGet> configurations = jmxService.getConfigurations();
    JavaLangJmxMetrics metrics = new JavaLangJmxMetrics();
    int extCountInJmxYml = 3;
    Assert.assertEquals(configurations.toString(), configurations.size(), metrics.getFrameworkMetrics().size() + extCountInJmxYml);
    // verify two of the java lang object names are present
    boolean isObjectNameIndex0 = false;
    boolean isObjectNameIndex1 = false;
    for (JmxGet current : configurations) {
        if (metrics.getFrameworkMetrics().get(0).getObjectNameString().equals(current.getObjectNameString())) {
            isObjectNameIndex0 = true;
        } else if (metrics.getFrameworkMetrics().get(1).getObjectNameString().equals(current.getObjectNameString())) {
            isObjectNameIndex1 = true;
        }
    }
    Assert.assertTrue("Some of the java lang metrics are missing from the start up.", isObjectNameIndex0);
    Assert.assertTrue("Some of the java lang metrics are missing from the start up.", isObjectNameIndex1);
}
Also used : JavaLangJmxMetrics(com.newrelic.agent.jmx.values.JavaLangJmxMetrics) JmxService(com.newrelic.agent.jmx.JmxService) JmxGet(com.newrelic.agent.jmx.create.JmxGet) Test(org.junit.Test)

Example 2 with JmxGet

use of com.newrelic.agent.jmx.create.JmxGet 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 3 with JmxGet

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

the class JmxServiceTest method testEachExtensionAddedOnlyOnce.

@Test
public void testEachExtensionAddedOnlyOnce() {
    JmxService jmxService = ServiceFactory.getJmxService();
    List<JmxGet> configs = jmxService.getConfigurations();
    Assert.assertTrue(configs.size() > 0);
    // this checks to see if we have already seen the object name
    // really we should check attributes too, but this should be good enough
    // I just want to make sure the same extension is not loaded more than once
    Set<String> alreadySeen = new HashSet<>();
    for (JmxGet current : configs) {
        Assert.assertTrue("It looks like an extension file was loaded more than once.", !alreadySeen.contains(current.getObjectNameString()));
        alreadySeen.add(current.getObjectNameString());
    }
}
Also used : JmxService(com.newrelic.agent.jmx.JmxService) JmxGet(com.newrelic.agent.jmx.create.JmxGet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with JmxGet

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

the class JmxService method process.

private void process(StatsEngine statsEngine) {
    Collection<MBeanServer> srvrList = getServers();
    addNewFrameworks();
    runThroughAndRemoveInvokes(srvrList);
    for (JmxGet object : jmxGets) {
        process(statsEngine, srvrList, object);
    }
}
Also used : MBeanServer(javax.management.MBeanServer) JmxGet(com.newrelic.agent.jmx.create.JmxGet)

Aggregations

JmxGet (com.newrelic.agent.jmx.create.JmxGet)4 JmxService (com.newrelic.agent.jmx.JmxService)3 Test (org.junit.Test)3 GlassfishJmxValues (com.newrelic.agent.jmx.values.GlassfishJmxValues)1 JavaLangJmxMetrics (com.newrelic.agent.jmx.values.JavaLangJmxMetrics)1 JettyJmxMetrics (com.newrelic.agent.jmx.values.JettyJmxMetrics)1 ResinJmxValues (com.newrelic.agent.jmx.values.ResinJmxValues)1 TomcatJmxValues (com.newrelic.agent.jmx.values.TomcatJmxValues)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 HashSet (java.util.HashSet)1 MBeanServer (javax.management.MBeanServer)1