在WebLogic Server上驯服JMX

让我们先假设几件事:

  1. 我假设您听说过Java的JMX功能并熟悉它的功能(远程公开和管理您的服务)。 您应该知道默认JVM将具有一个可以注册MBean的Platform MBeanServer实例。 您可以使用JDK中的jconsole命令查看它们。
  2. 到目前为止,我认为到目前为止,将应用程序中的任何服务公开给JMX MBeanServer的最简单方法是使用Spring的导出器。 您将执行以下操作:

<bean class="org.springframework.jmx.export.MBeanExporter">
        <property name="assembler">
              <bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
                <property name="managedInterfaces">
                    <list>
                        <!-- Expose any java interface you like to see under JMX as MBean -->
                        <value>myproject.services.Service</value>
                    </list>
                </property>
              </bean>
        </property>
        <property name="beans">
          <map>
            <entry key="myproject.services:name=MyCoolService" value-ref="myCoolService"/>
          </map>
        </property>
    </bean>
    <!-- This service must implements the interface used above -->
    <bean id="myCoolService" class="myproject.services.MyCoolService">
    </bean>

上面应该可以让您启用JMX的独立应用程序。

现在,如果您想在WebLogic Server上执行类似的操作,那么我的一些好东西和说明可能会对您有所帮助。 继续阅读...

WebLogic Server(WLS)的MBeanServer

JConsole技巧

像许多其他EE服务器一样,WLS将拥有自己的MBeanServer。 但是,要查看MBean,您需要使用jconsole做一些额外的工作。 假设您有一个在本地主机上启动的默认配置WLS,则可以像这样连接到它。

jconsole -J-Djava.class.path="$JAVA_HOME/lib/jconsole.jar:$MW_HOME/wlserver/server/lib/wljmxclient.jar" -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote

然后在提示您登录时,输入以下内容:

Remote Process: service:jmx:iiop://localhost:7001/jndi/weblogic.management.mbeanservers.runtime
User: <same userid you used setup WLS to their console app.>
Password: <same password you used setup WLS to their console app.>

现在,您应该看到WLS已经作为EE服务器公开给您的所有MBean。 您可以在此处添加自己的服务。

使用JMX连接进行编程

您可以在独立应用程序内部远程连接到WLS MBeanServer。 这是您需要的典型连接代码

String serviceName = "com.bea:Name=DomainRuntimeService,Type=
weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
        try {
            ObjectName service = new ObjectName(serviceName);
        } catch (MalformedObjectNameException e) {
            throw new RuntimeException("Not able to create JMX ObjectName: " + serviceName);
        }

        String protocol = "t3";
        String jndiroot = "/jndi/";
        String mserver = "weblogic.management.mbeanservers.runtime";
        try {
            JMXServiceURL serviceURL = new JMXServiceURL(protocol, "localhost", 7001, jndiroot + mserver);

            Hashtable h = new Hashtable();
            h.put(Context.SECURITY_PRINCIPAL, username);
            h.put(Context.SECURITY_CREDENTIALS, password);
            h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
                    "weblogic.management.remote");
            h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
            JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
            MBeanServerConnection remoteMBeanServer = connector.getMBeanServerConnection();

            // TODO: Do what you need with remoteMBeanServer here.
        } catch (Exception e) {
            throw new RuntimeException("Not able to initiate MBeanServer protocol= " + protocol +
                    ", jndiroot= " + jndiroot + ", mserver= " + mserver);
        }

只是为了获得远程MBeanServer连接而准备的大量锅炉代码! 幸运的是,还有另一种更简单的方法。 继续阅读...

JNDI技巧

也可以通过JNDI查找来使用WLS MBeanServer服务。 Spring可以再次帮助您进行JNDI查找,您只需要将其注入需要它的其他服务即可。 例如:

<bean id="jmxServerRuntime" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jmx/runtime"/>
    </bean>
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
        <property name="beans">
            <map>
                <entry key="myproject.services:name=MyCoolService" value-ref="myCoolService"/>
            </map>
        </property>
        <property name="server" ref="jmxServerRuntime"/>
    </bean>

请注意,我们已经从WLS JNDI服务中查找了一个“服务器”属性。 如果在WAR应用程序中使用它,并将其部署到WLS实例上,那么,您将可以在WLS JMX上使用公开服务!

注意

仅当您的Spring xml配置是JAR所在的同一服务器中部署的WAR / JAR / EAR的一部分时,以上方法才有效! 如果不是,则需要使用不带“ env”部分的该JNDI名称,例如“ java:comp / env / jmx / runtime”。

有关如何使用JMX和WLS的更多详细信息,请参见此处的文档: http : //docs.oracle.com/cd/E12839_01/web.1111/e13728/accesswls.htm#i1119556

参考:A Programmer's Journal博客上,由我们的JCG合作伙伴 Zemian Deng 驯服WebLogic Server上的JMX

翻译自: https://www.javacodegeeks.com/2013/06/taming-the-jmx-on-weblogic-server.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值