Search in sources :

Example 71 with ObjectInstance

use of javax.management.ObjectInstance in project lucene-solr by apache.

the class SolrJmxReporterTest method testEnabled.

@Test
public void testEnabled() throws Exception {
    String root1 = TestUtil.randomSimpleString(random(), 5, 10);
    PluginInfo pluginInfo1 = createReporterPluginInfo(root1, true);
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo1, coreMetricManager.getTag());
    String root2 = TestUtil.randomSimpleString(random(), 5, 10);
    assertFalse(root2.equals(root1));
    PluginInfo pluginInfo2 = createReporterPluginInfo(root2, false);
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo2, coreMetricManager.getTag());
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
    assertTrue(reporters.containsKey(pluginInfo1.name + "@" + coreMetricManager.getTag()));
    assertTrue(reporters.containsKey(pluginInfo2.name + "@" + coreMetricManager.getTag()));
    String scope = SolrMetricTestUtils.getRandomScope(random(), true);
    SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random(), true);
    Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random(), true);
    SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
    coreMetricManager.registerMetricProducer(scope, producer);
    Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
    assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root1.equals(o.getObjectName().getDomain())).count());
    assertEquals(0, objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root2.equals(o.getObjectName().getDomain())).count());
}
Also used : Counter(com.codahale.metrics.Counter) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 72 with ObjectInstance

use of javax.management.ObjectInstance in project lucene-solr by apache.

the class SolrJmxReporterTest method testReloadCore.

@Test
public void testReloadCore() throws Exception {
    Random random = random();
    String scope = SolrMetricTestUtils.getRandomScope(random, true);
    SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random, true);
    Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random, true);
    SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
    coreMetricManager.registerMetricProducer(scope, producer);
    Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
    assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && o.getObjectName().getDomain().equals(rootName)).count());
    h.getCoreContainer().reload(h.getCore().getName());
    PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
    coreMetricManager.registerMetricProducer(scope, producer);
    objects = mBeanServer.queryMBeans(null, null);
    assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && rootName.equals(o.getObjectName().getDomain())).count());
}
Also used : Counter(com.codahale.metrics.Counter) Random(java.util.Random) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) Test(org.junit.Test)

Example 73 with ObjectInstance

use of javax.management.ObjectInstance in project lucene-solr by apache.

the class TestJmxIntegration method testJmxRegistration.

@Test
public void testJmxRegistration() throws Exception {
    assertTrue("No MBeans found in server", mbeanServer.getMBeanCount() > 0);
    Set<ObjectInstance> objects = mbeanServer.queryMBeans(null, null);
    assertFalse("No objects found in mbean server", objects.isEmpty());
    int numDynamicMbeans = 0;
    for (ObjectInstance o : objects) {
        ObjectName name = o.getObjectName();
        assertNotNull("Null name on: " + o.toString(), name);
        MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(name);
        if (name.getDomain().equals("solr")) {
            numDynamicMbeans++;
            MBeanAttributeInfo[] attrs = mbeanInfo.getAttributes();
            if (name.getKeyProperty("name").equals("fetcher")) {
                // no attributes without active replication
                continue;
            }
            assertTrue("No Attributes found for mbean: " + o.getObjectName() + ", " + mbeanInfo, 0 < attrs.length);
            for (MBeanAttributeInfo attr : attrs) {
                // ensure every advertised attribute is gettable
                try {
                    Object trash = mbeanServer.getAttribute(o.getObjectName(), attr.getName());
                } catch (javax.management.AttributeNotFoundException e) {
                    throw new RuntimeException("Unable to featch attribute for " + o.getObjectName() + ": " + attr.getName(), e);
                }
            }
        }
    }
    assertTrue("No MBeans found", 0 < numDynamicMbeans);
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) ObjectInstance(javax.management.ObjectInstance) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 74 with ObjectInstance

use of javax.management.ObjectInstance in project lucene-solr by apache.

the class TestJmxIntegration method testJmxOnCoreReload.

@Test
@Ignore("timing problem? https://issues.apache.org/jira/browse/SOLR-2715")
public void testJmxOnCoreReload() throws Exception {
    String coreName = h.getCore().getName();
    Set<ObjectInstance> oldBeans = mbeanServer.queryMBeans(null, null);
    int oldNumberOfObjects = 0;
    for (ObjectInstance bean : oldBeans) {
        try {
            if (String.valueOf(h.getCore().hashCode()).equals(mbeanServer.getAttribute(bean.getObjectName(), "coreHashCode"))) {
                oldNumberOfObjects++;
            }
        } catch (AttributeNotFoundException e) {
        // expected
        }
    }
    log.info("Before Reload: Size of infoRegistry: " + h.getCore().getInfoRegistry().size() + " MBeans: " + oldNumberOfObjects);
    assertEquals("Number of registered MBeans is not the same as info registry size", h.getCore().getInfoRegistry().size(), oldNumberOfObjects);
    h.getCoreContainer().reload(coreName);
    Set<ObjectInstance> newBeans = mbeanServer.queryMBeans(null, null);
    int newNumberOfObjects = 0;
    int registrySize = 0;
    try (SolrCore core = h.getCoreContainer().getCore(coreName)) {
        registrySize = core.getInfoRegistry().size();
        for (ObjectInstance bean : newBeans) {
            try {
                if (String.valueOf(core.hashCode()).equals(mbeanServer.getAttribute(bean.getObjectName(), "coreHashCode"))) {
                    newNumberOfObjects++;
                }
            } catch (AttributeNotFoundException e) {
            // expected
            }
        }
    }
    log.info("After Reload: Size of infoRegistry: " + registrySize + " MBeans: " + newNumberOfObjects);
    assertEquals("Number of registered MBeans is not the same as info registry size", registrySize, newNumberOfObjects);
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) ObjectInstance(javax.management.ObjectInstance) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 75 with ObjectInstance

use of javax.management.ObjectInstance in project tomee by apache.

the class CxfUtilTest method checkMonitoring.

@Test
public void checkMonitoring() throws IOException, MalformedObjectNameException {
    // need a call to get something
    IO.slurp(new URL(root.toExternalForm() + "test/monitoring/cxf"));
    final Set<ObjectInstance> mbeans = ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("*:*,type=Performance.Counter.Server"), null);
    assertNotNull(mbeans);
    assertEquals(2, mbeans.size());
}
Also used : ObjectInstance(javax.management.ObjectInstance) URL(java.net.URL) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

ObjectInstance (javax.management.ObjectInstance)75 ObjectName (javax.management.ObjectName)36 Test (org.junit.Test)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 MBeanServer (javax.management.MBeanServer)12 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)10 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)9 Result (com.googlecode.jmxtrans.model.Result)9 HashSet (java.util.HashSet)7 Attribute (javax.management.Attribute)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 HashMap (java.util.HashMap)4 AttributeList (javax.management.AttributeList)4 MBeanException (javax.management.MBeanException)4 MBeanServerConnection (javax.management.MBeanServerConnection)4 ReflectionException (javax.management.ReflectionException)4