java 组件化_(原创)搭建一个组件化的监控平台
最近看到一位同事正在開發一個監控軟件,要求就是通過針對服務器現有的一些接口,通過這些接口返回的數據進行分析,如果監控的值到達預先設定的范圍則通過短信的方式發送給管理員。
從整個開發的功能上來看是一個比較單一也很明確的功能,所開發的系統對所其所監控的軟件的依賴性也非常大,主要是監控的數據分析行為和監控信息的服務報警行為這塊。既然這兩塊很難做成一個通用的功能模塊,那就搭建一個監控平臺,可以讓這些功能模塊通過組件的方式自由的注冊和銷毀。
所有我構思了這個監控平臺,它對外有三個接口,分別是監控接口,報警接口和監控消息監控接口。由平臺統一管理這些組件的生命周期,每個組件都過單獨的線程運行。提供一個核心組件CoreComponent調度所有監控數據的流轉。平臺本身還使用基于jmx管理服務技術提供對所有當前使用的組件運行情況的監控,也包括動態的啟動和停止組件的運行狀態。
下載地址
二進制程序第三方類庫下載,第三方類庫下載2 放到lib目錄下。
api-docs
源代碼
下面是部分設計圖:
AlertComponent設計圖
SpyComponent設計圖:
MessageAlertChannelActiveAwareComponent設計圖
下面我利用該平臺開發一個監控ActiveMQ狀態的組件ActiveMQJmxSpyComponent,該組件實現對AMQ運行狀態的監控(監聽失敗或失敗后重新連接成功)??梢酝ㄟ^指定Queue名稱列表來指定要監控Queue隊列的消費者是否為0(通常表示對方可能因為網絡或服務中斷而失去監控)或是隊列消息都由0變為大于0表示消費者重新監聽上服務。
1
publicclassActiveMQJmxSpyComponentextendsAbstractSpyComponent{2
/**?*//**3?????*?Logger?for?this?class4*/5privatestaticfinalLogger?LOGGER=Logger.getLogger(ActiveMQJmxSpyComponent.class);6//AMQ?jmx?serverUrl?to?spy7privateString?serverUrl;8//detect?interval(unit?is?ms)9privateintdetectInterval=5000;10//the?Queue?name?list?to?spy11privateSetdestinationNamesToWatch;12//if?queue's?consumer?suspends?after?then?certain?time?then?to?notify.?default?is?3?minutes13privateintqueueSuspendNotifyTime=3*60*1000;
下面是一個報警組件的實現:只是簡單的把監控消息打印在屏幕上PrintScreenAlertComponent
1
publicclassPrintScreenAlertComponentextendsAbstractAlertComponent{23
/**//*(non-Javadoc)4?????*?@see?org.xmatthew.spy2servers.core.Component#getName()5*/6
publicString?getName(){7return"PrintScreenAlertComponent";8????}910
/**//*(non-Javadoc)11?????*?@see?org.xmatthew.spy2servers.core.Component#startup()12*/13
publicvoidstartup(){14????????setStatusRun();1516????}1718
/**//*(non-Javadoc)19?????*?@see?org.xmatthew.spy2servers.core.Component#stop()20*/21
publicvoidstop(){22????????setStatusStop();2324????}2526????@Override27
protectedvoidonAlert(Message?message){28????????System.out.println(message);2930????}3132}33
下面該組件的注冊。${CUR_PATH}/conf/spy2servers.xml
1
<?xml ?version="1.0"?encoding="UTF-8"?>2????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"4????xmlns:aop="http://www.springframework.org/schema/aop"5????xmlns:tx="http://www.springframework.org/schema/tx"6????xsi:schemaLocation="http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans-2.0.xsd7???????????http://www.springframework.org/schema/aop?http://www.springframework.org/schema/aop/spring-aop-2.0.xsd8???????????http://www.springframework.org/schema/tx?http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">910111213141516171819Matthew.Queue20Rocket.Queue21222324252627
ok,現在ActiveMQJmxSpyComponent監控到的消息能會被PrintScreenAlertComponent打印到屏幕上。
現在啟動程序,我們看到ActiveMQJmxSpyComponent和PrintScreenAlertComponent組件已經啟動了。
使用Jconsole進行監控
如果此時需要建立一個消息報警的規則,只要實現以下接口,并注入到CoreComponent的alertRule屬性中即可。
1
publicinterfaceAlertRule{23booleanisAlertAllow(MessageAlertChannel?channel);4}
應用這個平臺開發監控的組件就這么簡單。
備注:因為開發時間比較緊,如果有什么Bug也希望大家反饋給我,我會改進。
Yours Matthew!
posted on 2008-03-12 13:41 x.matthew 閱讀(1953) 評論(7) ?編輯 ?收藏
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java 组件化_(原创)搭建一个组件化的监控平台的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 行转列分级输出_MySQL如
- 下一篇: admiration音标是什么_英语ad