使用JMX產品jolokia對Mule esb進行監控

來源:互聯網
上載者:User

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/corehttp://www.mulesoft.org/schema/mule/core/3.1/mule.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://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內建的

 

雙擊開啟,並填入RIM地址

 

 

 

除了上面系統內建的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}

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.