使用JMX产品jolokia对Mule esb进行监控

jolokia 1.0.6:http://www.jolokia.org/agent/mule.html

Mule esb 3.3.0:http://www.mulesoft.org


现在越来越多的集成平台使用了Mule企业服务总线中间件,Mule企业版的监控程序是收费的,不过Mule大佬还算有点良心,实现了很多MBEAN接口,提供了很JMX接口,这使得自定义监控界面得以实现。

 

准备实现的结构图如下:

 

 

在Mule里面添加JMX代理,新建一个flow,代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:management="http://www.mulesoft.org/schema/mule/management"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xsi:schemaLocation="
       http://www.mulesoft.org/schema/mule/core 
             http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
       http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
       http://www.mulesoft.org/schema/mule/management 
             http://www.mulesoft.org/schema/mule/management/3.1/mule-management.xsd">

   <!-- jmx配置 -->
   <custom-agent name="jolokia-agent" class="org.jolokia.mule.JolokiaMuleAgent">
      <spring:property name="port" value="8099"/>
   </custom-agent>
   <management:jmx-server>
   	<management:connector-server url="service:jmx:rmi:///jndi/rmi://localhost:7099/mule" rebind="true" />
   </management:jmx-server>
</mule>

附:需要把Mule-Agent的包: jolokia-mule-1.0.6-agent.jar添加到类目录
参考:http://www.jolokia.org/agent/mule.html

 

运行结果:

打印出如下信息表示添加JMX成功啦。

 

 

这样打开: http://casking-soa-PC:8099/jolokia 这个就可以查看版本了。

内存情况及回收操作:
http://127.0.0.1:8099/jolokia/read/java.lang:type=Memory
http://127.0.0.1:8099/jolokia/exec/java.lang:type=Memory/gc
 
操作系统信息
http://127.0.0.1:8099/jolokia/read/java.lang:type=OperatingSystem
 
运行环境
http://127.0.0.1:8099/jolokia/read/java.lang:type=Runtime
 
线程总体情况
http://127.0.0.1:8099/jolokia/read/java.lang:type=Threading
 
类加载情况
http://127.0.0.1:8099/jolokia/read/java.lang:type=ClassLoading
 

更多用法可以参见:http://www.jolokia.org/reference/html/protocol.html

 

有了API,你们就可以自己写自定义的界面了。

 

看我们的结构图,绿色部分有说提供标准的JMX API,我们来测试使用JConsole测试一下

此工具JDK自带的

使用JMX产品jolokia对Mule esb进行监控_第1张图片

 

双击打开,并填入RIM地址

 

使用JMX产品jolokia对Mule esb进行监控_第2张图片

 

 

除了上面系统自带的Mbean,我们还可以在Mule里面添加自己的Mbean,这样可以自由发挥啦

新建一个flow,代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
 xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    
    <spring:beans>
    	 <!-- 配置MBean自动注册 -->
		<context:mbean-export default-domain="mule-csip-custom" registration="replaceExisting" />
        <spring:bean class="cn.com.casking.csip.jmx.Test"/>
    </spring:beans>
</mule>


Test.java类对应的代码:

package cn.com.casking.csip.jmx;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;

@ManagedResource(objectName = Test.MBEAN_NAME, description = "测试的Mbean")
public class Test {

	public static final String MBEAN_NAME = "mule-csip-custom:name=test";

	@ManagedAttribute(description = "属性测试")
	public int getAttr() {
			System.out.println("属性测试!!!");
			return 0;
	}


	@ManagedOperation(description = "方法测试")
	public void execOperation(String name) {
		System.out.println("方法测试!!!="+name);
	}

}


 

使用Jconsole可以查看

 

当然也可以使用jolokia的API来打开:

1.获取属性:

http://127.0.0.1:8099/jolokia/read/mule-csip-custom:name=test/Attr  

{"timestamp":1362052249,"status":200,"request":{"mbean":"mule-csip-custom:name=test","attribute":"Attr","type":"read"},"value":0}


 

2.执行方法:

http://127.0.0.1:8099/jolokia/exec/mule-csip-custom:name=test/execOperation/yangcai

返回结果:

{"timestamp":1362052156,"status":200,"request":{"operation":"execOperation","mbean":"mule-csip-custom:name=test","arguments":["yangcai"],"type":"exec"},"value":null}


 

 

 

 

 

 

你可能感兴趣的:(监控,SOA,mule,jolokia)