通过MBean server监控weblogic应用

因为最近自己一直在做一个weblogic项目监控的web工程,而苦于网上关于weblogic监控可获取属性的信息少之又少,所以自己对此做了一点小小的总结,希望看到的人能少走一些弯路。

首先,从建立Mbean server的连接说起,

public class MonitorWeblogic {  

public static final Logger LOG = Logger.getLogger(MonitorWeblogic.class);

    private static MBeanServerConnection connection;  

  

    private static JMXConnector connector;  

  

    private static final ObjectName service

  

    // 实例化 DomainRuntimeServiceMBean 对象名   

    // 这样可以通过类使用此对象名。   

    static {  

        try {  

        

            service = new ObjectName(  

                    "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");  

            

        } catch (MalformedObjectNameException e) {  

            throw new AssertionError(e.getMessage());  

        }  

    }  

    

    /**实例化与 Domain Runtime MBean Server的连接 */ 

 

 public static void initConnection(String protocol,String hostname, String portString,  

            String username, String password) throws IOException,  

            MalformedURLException {  

        Integer portInteger = Integer.valueOf(portString);  

        int port = portInteger.intValue();  

        String jndiroot = "/jndi/";  

        String mserver = "weblogic.management.mbeanservers.domainruntime";  

        JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,  

                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");  

        connector = JMXConnectorFactory.connect(serviceURL, h);  

        connection = connector.getMBeanServerConnection();  

}  

}

这里建立的是一个Domain Runtimes MBean Server的连接,initConnection方法以用户名、密码以及监控地址和端口为参数,在实例化类时传递参数。对于weblogic,还包括一下MBean的服务器类型。Runtime MBean Server 和 Edit MBean Server。对应MBean服务器的功能如下:

Edit MBean Server: 修改域的配置,监视配置MBean待定层次结构的更改

Runtime MBean Server: 仅监视活动的配置MBean,而不监视运行时MBean

Domain Runtime MBean Server: 对多个服务器监视运行时MBean(在本次的实践中,采用的就是Domain Runtime MBean Server)

初始化连接后,就要开始获取weblogic上各种属性的值了,这个地方正是本文的重点。很多人可能知道通过getServerRuntimes()方法来获取运行服务器属性的值,通过getAttribute(ObjectName name,String attribute)获取监控属性的值。但大部分人应该会和我一样,因为不了解MBean中 attribute对象有哪些内容而苦恼。不过还好,MBean给我们提供了一个getMbeanInfo(ObjectName name)方法,让我们可以获取Mbean的大部分attributes和操作信息。由于这段信息过于冗长,没法完整的贴出,我在此截取一小段:javax.management.modelmbean.ModelMBeanInfoSupport[description=<p>An application represents a J2EE Enterprise application packaged in an EAR file or EAR exploded directory. The EAR file or directory contains a set of components such as WAR, EJB, and RAR connector components, each of which can be deployed on one or more targets. 

......

......

(连起来可以绕地球一圈,看得眼睛都花了)

相信大部分人没有耐心把这么长一段信息完整的看完,所以我对它做了个总结,说明一下MBeanInfo中主要的内容有哪些

1. Modules in application can have one of the following states

   UNPREPARED  应用中所有组件都未准备就绪或活跃状态

   PREPARED   应用中所有组件都已准备就绪或活跃状态

   ACTIVATED  应用中至少有一个组件是活跃的

他们的具体信息可能在register mbean 时出现了点差错,我已经予以改正

2. MBean中 一些Interface的介绍和操作,然而这些对我们获取监控属性值并没有什么用

3. ModelMBeanAttributeInfo: MBean 可获得的应用属性名称和属性具体内容,我挑选了一些可能用到的:

WseeRuntimes

ApplicationName

Parent

EAR

ApplicationVersion

Type

WseeV2Runtimes

LibraryRuntimes

ClassRedefinitionRuntime

WorkManagerRuntimes

MinThreadsConstraintRuntimes

HealthState

Name

ActiveVersionState

ComponentRuntimes

QueryCacheRuntimes

   WseeRuntimes   :

Descriptionthe list of Web Service runtime instances that are contained in this Enterprise application

通过 getWseeV2Runtimes获取,

接口为Lweblogic.management.runtime.WseeRuntimeMBean

Type ObjectName

 

 ApplicationName:

DescriptionThe name of the Enterprise application.

type  Attribute 

 

   Parent:

Descriptionthe immediate parent for this MBean。

type  ObjectName

接口weblogic.management.WebLogicMBean

 

 

   ApplicationVersion:

DescriptionThe Enterprise application's version identifier

 

   Type:

DescriptionReturns the type of the MBean

 

   WseeV2Runtimes

DescriptionReturns the list of Web Service runtime instances that are contained at the application scope of this Enterprise application

接口Lweblogic.management.runtime.WseeV2RuntimeMBean

 

   LibraryRuntimes:

DescriptionReturns the list of library runtime instances for each J2EE library that is contained in this Enterprise application

接口Lweblogic.management.runtime.LibraryRuntimeMBean

 

   ClassRedefinitionRuntime:

DescriptionIf class fast-swap feature is enabled for the application, return the runtime mbean to monitor and control the class fast-swap within the application

接口com.bea.wls.redef.runtime.ClassRedefinitionRuntimeMBean

 

   WorkManagerRuntimes:

DescriptionReturns the list of work manager runtime instances for each application-scoped work manager that is associated with this Enterprise application

接口

Lweblogic.management.runtime.WorkManagerRuntimeMBean;, 

 

   MinThreadsConstraintRuntimes:

DescriptionGet the runtime mbeans for all MinThreadsConstraints defined at the app-level

接口Lweblogic.management.runtime.MinThreadsConstraintRuntimeMBean

 

   HealthState

DescriptionThe HealthState mbean for the application

Types: weblogic.health.HealthState

Name:

The name of this configuration

 

   ActiveVersionState:

DescriptionSpecifies whether this application version is the currently active version

 

   OptionalPackageRuntimes:

DescriptionReturns the list of optional package runtime instances for each J2EE optional package that is contained in this Enterprise application

接口:Lweblogic.management.runtime.LibraryRuntimeMBean

 

   RequestClassRuntimes:

DescriptionGet the runtime mbeans for all request classes defined at the app-level

接口

Lweblogic.management.runtime.RequestClassRuntimeMBean;, 

 

   ComponentRuntimes:

DescriptionReturns the list of component runtime instances for each J2EE component (such as an EJB or a Web application) that is contained in this Enterprise application

接口Lweblogic.management.runtime.ComponentRuntimeMBean

 

    QueryCacheRuntimes:

DescriptionReturns a list of QueryCacheRuntimeMBeans configured for this application.

接口Lweblogic.management.runtime.QueryCacheRuntimeMBean

 

   MaxThreadsConstraintRuntimes:

DescriptionGet the runtime mbeans for all MaxThreadsConstraints defined at the app-level

TypeLjavax.management.ObjectName

接口Lweblogic.management.runtime.MaxThreadsConstraintRuntimeMBean

 

 

4.ModelMBeanOperationInfo:(主要是Mbean的一些操作,实际使用的概率不大)

lookupWseeV2Runtime:

Returns a named Web Service runtime instance that is contained at application scope of this Enterprise application

接口weblogic.management.runtime.WseeV2RuntimeMBean

lookupWorkManagerRuntime:

Lookup the WorkManagerRuntimeMBean given the component name and work manager name. If the component name is null then the WorkManagerRuntime is retrieved from the application itself

接口weblogic.management.runtime.WorkManagerRuntimeMBean

lookupQueryCacheRuntime:

Returns a QueryCacheRuntimeMBean for the app-scoped query-cache with name 'cacheName'

lookupMinThreadsConstraintRuntime:

lookup MinThreadsConstraintRuntime given its name

hasApplicationCache :

Returns True if the application has an (EJB) Application Level Cache 

 

虽然整理了这么多mbean 的属性和操作信息,但大部分都是针对服务器和应用运行状态以及线程的,可能还是不能完整的获取应用的具体信息。因此又对从ComponentRuntimes中取出来的内容进行了分析和整理

这是其中的两条:

com.bea:ServerRuntime=AdminServer,Name=AdminServer_/monitor-webapp,Location=AdminServer,Type=WebAppComponentRuntime,ApplicationRuntime=sg-i6000-monitor-webapp

 

com.bea:ServerRuntime=AdminServer,Name=DataSource-ws,Location=AdminServer,Type=JDBCDataSourceRuntime

 

从中可以获得应用所在服务器以及应用类型的信息分别存在ComponentRuntimesLocation Type属性中,这样就能针对应用类型和所在服务器对在weblogic部署的应用和数据源进行区分了!

对于Edit MBean Server, 下次再详述。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值