注册到mbean服务器的mbean没有出现在jconsole中。

时间:2022-02-19 04:19:51

I create a mbean server using MBeanServerFactory.createMBeanServer and register mbeans with it. I can find the mbean server in jconsole but when I connect to it I do not see registered mbeans. Here is the code:

我使用MBeanServerFactory创建一个mbean服务器。createMBeanServer并使用它注册mbean。我可以在jconsole中找到mbean服务器,但是当我连接到它时,我看不到注册的mbean。这是代码:

public static void main(String[] args) throws Exception
{
    MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer("example");
    ObjectName objectName = new ObjectName("example:type=simpleMbean");
    Simple simple = new Simple (1, 0);
    mbeanServer.registerMBean(simple, objectName);
    while (true)
    {
    }
}

Instead of creating a mbean server, if I using the platformMBeanServer and register my mbean to it, I can see the mbean in jconsole. Any idea what else do I need to do while doing createMBeanServer?

如果我使用platformMBeanServer并将mbean注册到它,我可以在jconsole中看到mbean,而不是创建一个mbean服务器。在做createMBeanServer时,我还需要做什么?

4 个解决方案

#1


2  

I came accross this issue yesterday but managed to sort that one out. I spend some time doing that so I thought this post would be helpfull to save someone else's time.

我昨天碰到这个问题,但还是设法解决了这个问题。我花了一些时间来做这件事,所以我认为这篇文章可以帮助别人节省时间。

First you can register you beans in the java code as stated in your post in the main method. But I think it is much more simpler if you use Spring.

首先,您可以在main方法中所述的java代码中为您注册bean。但是我认为如果你用弹簧的话会更简单。

Check this link out for more information; http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html

查看此链接以获得更多信息;http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html

There are some loop holes you need to avoid. Don't start two MBeans servers in your application.

你需要避免一些环孔。在应用程序中不要启动两个mbean服务器。

I used this config file:

我使用了这个配置文件:

<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="beans">
<map>
<entry key="bean:name=beanName" value-ref="dataSource"/>
</map>
</property>
  <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
</bean>

Use this configuration to attach a bean name to MBeanExporter. Make sure 'lazy-init' is set to false. Please note I am using this configuration in a webapplication. Web application is deployed inside tomcat. So tomcat already has MBean server. So you don't need to provide one explicitly. If you are running it in a standalone mode you need to start a MBean server and configure it accordingly.

使用此配置将bean名称附加到mbeanexport。确保“lazy-init”设置为false。请注意,我在webapplication中使用了这个配置。Web应用程序部署在tomcat内部。所以tomcat已经有了MBean服务器。所以你不需要明确地提供一个。如果您以独立模式运行它,您需要启动一个MBean服务器并相应地配置它。

Please also note you need add following properties inside tomcat's catalina.bat file. set CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8088 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.hostname="localhost"

请注意,您需要在tomcat的catalina中添加以下属性。bat文件。设置CATALINA_OPTS = -Dcom.sun.management。现在-Dcom.sun.management.jmxremote。= 8088 -Dcom.sun.management.jmxremote港。ssl = false -Dcom.sun.management.jmxremote。验证= false -Dcom.sun.management.jmxremote.hostname = " localhost "

Jmx connector port in this case is 8088 and hostname is 'localhost' Once you have started tomcat you need to start jconsole(I am not going to tell how to start it here) Then click on 'RemoteProcess' and type 'localhost:8088' and connect to the tomcat's MBean server. Then go to MBean tab in jconsole and you should see your MBean there.

在本例中,Jmx连接器端口是8088,主机名是“localhost”,一旦您启动tomcat,就需要启动jconsole(我不打算告诉您如何在这里启动它),然后单击“RemoteProcess”和type“localhost:8088”,并连接到tomcat的MBean服务器。然后到jconsole中的MBean选项卡,您应该在那里看到您的MBean。

#2


1  

The easiest solution is to use the Platform MBean Server configured via system properties.

最简单的解决方案是使用通过系统属性配置的平台MBean服务器。

So you need to the MBeanServer instance with

所以需要使用MBeanServer实例。

MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

and set the following system properties when launching your application:

在启动应用程序时设置以下系统属性:

-Dcom.sun.management.jmxremote.port=1919
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

#3


0  

If you want to see your MBeans in the JConsole, you will have to use RMI. Basically, do the following

如果希望在JConsole中看到mbean,则必须使用RMI。基本上,执行以下操作

Registry registry = LocateRegistry.createRegistry(RMI_REGISTRY_PORT);
//... create your MBean Server here and add your MBeans...
Map<String, Object> env = new HashMap<String, Object>(); //Add authenticators and stuff to the environment.    

//Create a URL from which your beans will be accessible.    
JMXServiceURL jmxServiceURL = new JMXServiceURL("rmi", 
                                                "localhost", 
                                                CONNECTOR_SERVER_PORT, 
                                                "/jndi/rmi://localhost:" + RMI_REGISTRY_PORT + "myApp");

//Start the connector server
JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, env, server);
System.out.println(jmxServiceURL); //Use this URL to connect through JConsole, instead of selecting Local Process, just select the Remote process

#4


0  

You need use PlatformMBeanServer

你需要使用PlatformMBeanServer

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

ps http://www.javalobby.org/java/forums/t49130.html

ps http://www.javalobby.org/java/forums/t49130.html

#1


2  

I came accross this issue yesterday but managed to sort that one out. I spend some time doing that so I thought this post would be helpfull to save someone else's time.

我昨天碰到这个问题,但还是设法解决了这个问题。我花了一些时间来做这件事,所以我认为这篇文章可以帮助别人节省时间。

First you can register you beans in the java code as stated in your post in the main method. But I think it is much more simpler if you use Spring.

首先,您可以在main方法中所述的java代码中为您注册bean。但是我认为如果你用弹簧的话会更简单。

Check this link out for more information; http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html

查看此链接以获得更多信息;http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html

There are some loop holes you need to avoid. Don't start two MBeans servers in your application.

你需要避免一些环孔。在应用程序中不要启动两个mbean服务器。

I used this config file:

我使用了这个配置文件:

<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="beans">
<map>
<entry key="bean:name=beanName" value-ref="dataSource"/>
</map>
</property>
  <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
</bean>

Use this configuration to attach a bean name to MBeanExporter. Make sure 'lazy-init' is set to false. Please note I am using this configuration in a webapplication. Web application is deployed inside tomcat. So tomcat already has MBean server. So you don't need to provide one explicitly. If you are running it in a standalone mode you need to start a MBean server and configure it accordingly.

使用此配置将bean名称附加到mbeanexport。确保“lazy-init”设置为false。请注意,我在webapplication中使用了这个配置。Web应用程序部署在tomcat内部。所以tomcat已经有了MBean服务器。所以你不需要明确地提供一个。如果您以独立模式运行它,您需要启动一个MBean服务器并相应地配置它。

Please also note you need add following properties inside tomcat's catalina.bat file. set CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8088 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.hostname="localhost"

请注意,您需要在tomcat的catalina中添加以下属性。bat文件。设置CATALINA_OPTS = -Dcom.sun.management。现在-Dcom.sun.management.jmxremote。= 8088 -Dcom.sun.management.jmxremote港。ssl = false -Dcom.sun.management.jmxremote。验证= false -Dcom.sun.management.jmxremote.hostname = " localhost "

Jmx connector port in this case is 8088 and hostname is 'localhost' Once you have started tomcat you need to start jconsole(I am not going to tell how to start it here) Then click on 'RemoteProcess' and type 'localhost:8088' and connect to the tomcat's MBean server. Then go to MBean tab in jconsole and you should see your MBean there.

在本例中,Jmx连接器端口是8088,主机名是“localhost”,一旦您启动tomcat,就需要启动jconsole(我不打算告诉您如何在这里启动它),然后单击“RemoteProcess”和type“localhost:8088”,并连接到tomcat的MBean服务器。然后到jconsole中的MBean选项卡,您应该在那里看到您的MBean。

#2


1  

The easiest solution is to use the Platform MBean Server configured via system properties.

最简单的解决方案是使用通过系统属性配置的平台MBean服务器。

So you need to the MBeanServer instance with

所以需要使用MBeanServer实例。

MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

and set the following system properties when launching your application:

在启动应用程序时设置以下系统属性:

-Dcom.sun.management.jmxremote.port=1919
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

#3


0  

If you want to see your MBeans in the JConsole, you will have to use RMI. Basically, do the following

如果希望在JConsole中看到mbean,则必须使用RMI。基本上,执行以下操作

Registry registry = LocateRegistry.createRegistry(RMI_REGISTRY_PORT);
//... create your MBean Server here and add your MBeans...
Map<String, Object> env = new HashMap<String, Object>(); //Add authenticators and stuff to the environment.    

//Create a URL from which your beans will be accessible.    
JMXServiceURL jmxServiceURL = new JMXServiceURL("rmi", 
                                                "localhost", 
                                                CONNECTOR_SERVER_PORT, 
                                                "/jndi/rmi://localhost:" + RMI_REGISTRY_PORT + "myApp");

//Start the connector server
JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, env, server);
System.out.println(jmxServiceURL); //Use this URL to connect through JConsole, instead of selecting Local Process, just select the Remote process

#4


0  

You need use PlatformMBeanServer

你需要使用PlatformMBeanServer

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

ps http://www.javalobby.org/java/forums/t49130.html

ps http://www.javalobby.org/java/forums/t49130.html