前一陣開發(fā)這個(gè)
基于組件化的監(jiān)控平臺(tái)收到的一些朋友的關(guān)注,在此表示感謝。也抱歉有一段時(shí)間沒有及時(shí)更新了。
此次更新,主要是針對xml配置文件的簡化,很多朋友表示Spring的xml的配置比較麻煩。其實(shí)Spring開發(fā)團(tuán)隊(duì)在這方面也是有考慮到的,
提供了一些方法可以讓用戶去編寫xsd文件簡單配置。這點(diǎn)我們是可以看到Spring開發(fā)團(tuán)隊(duì)的努力,現(xiàn)在Spring2.0以及2.5在配置上面也是
簡化了很多如事務(wù)的配置,Aop配置以及utils工具類的配置等。
源代碼下載:
二進(jìn)制程序
第三方類庫下載,
第三方類庫下載2 放到lib目錄下。
api-docs
源代碼
關(guān)于想學(xué)習(xí)或使用過關(guān)于如何實(shí)現(xiàn)Spring的配置的朋友們,可以留言給我,一起進(jìn)行交流學(xué)習(xí)。這部分的學(xué)習(xí)文檔也是整理得不夠。
言歸正轉(zhuǎn),下面我們先來看一下原來的配置文檔,基于普通的Spring 2.0
beans schema
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 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 xmlns:util="http://www.springframework.org/schema/util"
7 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
8 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
10 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
11
12 <bean class="org.xmatthew.spy2servers.core.CoreComponent">
13 <property name="alertRule" ref="simpleAlertRule"></property>
14 </bean>
15 <bean class="org.xmatthew.spy2servers.jmx.JmxServiceComponent"></bean>
16
17 <bean id="simpleAlertRule" class="org.xmatthew.spy2servers.rule.SimpleAlertRule">
18 <property name="channles">
19 <set>
20 <ref bean="channel1" />
21 </set>
22 </property>
23 </bean>
24
25 <bean id="channel1" class="org.xmatthew.spy2servers.rule.Channel">
26 <property name="from">
27 <set>
28 <value>TomcatJmxSpyComponent</value>
29 </set>
30 </property>
31 <property name="to">
32 <set>
33 <!--<value>PrintScreenAlertComponent</value>-->
34 <value>EmailAlertComponent</value>
35 </set>
36 </property>
37 </bean>
38
39 <bean class="org.xmatthew.spy2servers.component.alert.PrintScreenAlertComponent"></bean>
40
41 <bean class="org.xmatthew.spy2servers.component.spy.jmx.ActiveMQJmxSpyComponent">
42 <property name="host" value="x.x.x.x"></property>
43 <property name="port" value="1099"></property>
44
45 <property name="heapMemorySpy">
46 <bean class="org.xmatthew.spy2servers.component.spy.jmx.MemorySpy">
47 <property name="memoryUsedPercentToAlert" value="5"></property>
48 <property name="alertAfterKeepTimeLive" value="10"></property>
49 </bean>
50 </property>
51 <property name="fileSpy">
52 <bean class="org.xmatthew.spy2servers.component.spy.jmx.FileSpy">
53 <property name="filesOpenedPercentToAlert" value="8"></property>
54 <property name="alertAfterKeepTimeLive" value="2"></property>
55 </bean>
56 </property>
57 <property name="queueSuspendNotifyTime" value="2000"></property>
58 </bean>
59
60 <bean class="org.xmatthew.spy2servers.component.spy.jmx.TomcatJmxSpyComponent">
61 <!-- 監(jiān)控的Jmx服務(wù)IP -->
62 <property name="host" value="x.x.x.x"></property>
63 <!-- 監(jiān)控的Jmx服務(wù)端口 -->
64 <property name="port" value="8060"></property>
65 <!-- 監(jiān)控時(shí)間間隔 單秒是 毫秒 -->
66 <property name="detectInterval" value="5000"></property>
67
68 <property name="heapMemorySpy"> <!-- 堆內(nèi)存 監(jiān)控方案 -->
69 <bean class="org.xmatthew.spy2servers.component.spy.jmx.MemorySpy">
70 <!-- 設(shè)置臨界值 內(nèi)存使用的百分比 使用的內(nèi)存值 / 最大內(nèi)存值。 注如果該值設(shè)置, memoryUsedToAlert自動(dòng)失效-->
71 <property name="memoryUsedPercentToAlert" value="5"></property>
72 <!-- 設(shè)置臨界值 內(nèi)存超過一定值后觸發(fā) 單位 Mb -->
73 <!-- <property name="memoryUsedToAlert" value="100"></property> -->
74 <!-- 設(shè)置臨界值保持多久后,開始報(bào)警 單位秒。 注該值沒有默認(rèn)值,如果不認(rèn)置則不會(huì)觸發(fā)報(bào)警操作 -->
75 <property name="alertAfterKeepTimeLive" value="10"></property>
76 </bean>
77 </property>
78 <property name="nonHeatMemorySpy"><!-- 非堆內(nèi)存 監(jiān)控方案 -->
79 <bean class="org.xmatthew.spy2servers.component.spy.jmx.MemorySpy">
80 <property name="memoryUsedToAlert" value="100"></property>
81 <property name="alertAfterKeepTimeLive" value="10"></property>
82 </bean>
83 </property>
84 <property name="fileSpy">
85 <bean class="org.xmatthew.spy2servers.component.spy.jmx.FileSpy">
86 <!-- 設(shè)置臨界值 文件打開數(shù)百分比 開始的文件數(shù) / 最大的文件數(shù)。 注如果該值設(shè)置, filesOpenedToAlert自動(dòng)失效 -->
87 <property name="filesOpenedPercentToAlert" value="90"></property>
88 <!-- 設(shè)置臨界值 文件打開數(shù) -->
89 <!-- <property name="filesOpenedToAlert" value="1000"></property> -->
90 <!-- 設(shè)置臨界值保持多久后,開始報(bào)警 單位秒。 注該值沒有默認(rèn)值,如果不認(rèn)置則不會(huì)觸發(fā)報(bào)警操作 -->
91 <property name="alertAfterKeepTimeLive" value="2"></property>
92 </bean>
93 </property>
94
95 <property name="dataSourcesSpy"><!-- 文件IO打開數(shù) 監(jiān)控方案 -->
96 <bean class="org.xmatthew.spy2servers.component.spy.jmx.DataSourcesSpy">
97 <property name="dataSourceSpys">
98 <set>
99 <bean class="org.xmatthew.spy2servers.component.spy.jmx.DataSourceSpy">
100 <!-- 設(shè)置臨界值 連接池連接數(shù)占用比例 使用的連接數(shù) / 最大的連接數(shù)。 注如果該值設(shè)置, numActiveToAlert自動(dòng)失效 -->
101 <property name="numActivePercentToAlert" value="90"></property>
102 <!-- 設(shè)置臨界值 連接池連目前使用的連接數(shù) -->
103 <!-- <property name="numActiveToAlert" value="20"></property> -->
104 <property name="dataSourceName" value="jdbc/opendb"></property>
105 </bean>
106 </set>
107 </property>
108 </bean>
109 </property>
110
111 <property name="webModuleSpy"><!-- Web Module 監(jiān)控方案 -->
112 <bean class="org.xmatthew.spy2servers.component.spy.jmx.WebModuleSpy">
113 <property name="webModules"> <!-- 監(jiān)控的web module列表,如果模塊狀態(tài)為stop或undeploy則會(huì)報(bào)觸發(fā)報(bào)警 -->
114 <set>
115 <value>/</value>
116 <value>/jsp-examples</value>
117 <value>/servlets-examples</value>
118 </set>
119 </property>
120 </bean>
121 </property>
122 </bean>
123
124
125 <bean class="org.xmatthew.spy2servers.component.alert.EmailAlertComponent">
126 <property name="emails" ref="emails"/>
127 <property name="emailAccount">
128 <bean class="org.xmatthew.spy2servers.component.alert.EmailAccount">
129 <property name="server" value="smtp.163.com"></property>
130 <property name="serverPort" value="25"></property>
131 <property name="loginName" value="ant_miracle"></property>
132 <property name="loginPwd" value="xxxx"></property>
133 <property name="sender" value="ant_miracle@163.com"></property>
134 <property name="sendNick" value="EmailAlertComponent"></property>
135 </bean>
136 </property>
137 </bean>
138
139 <util:list id="emails">
140 <value>ant_miracle@163.com</value>
141 </util:list>
142
143 <!--
144 <bean class="org.xmatthew.spy2servers.component.spy.jmx.SunJVMJmxSpyComponent">
145 <property name="host" value="x.x.x.x"></property>
146 <property name="port" value="8060"></property>
147
148 <property name="heapMemorySpy">
149 <bean class="org.xmatthew.spy2servers.component.spy.jmx.MemorySpy">
150 <property name="memoryUsedPercentToAlert" value="5"></property>
151 <property name="alertAfterKeepTimeLive" value="10"></property>
152 </bean>
153 </property>
154
155 <property name="fileSpy">
156 <bean class="org.xmatthew.spy2servers.component.spy.jmx.FileSpy">
157 <property name="filesOpenedPercentToAlert" value="8"></property>
158 <property name="alertAfterKeepTimeLive" value="2"></property>
159 </bean>
160 </property>
161 </bean>
162 -->
163 </beans>
164
是感覺很麻煩,下面我們看一下簡化后的配置文檔,功能與上面對應(yīng)。
需要注意的是,現(xiàn)在我們使用的bean schema是xmlns="http://www.xmatthew.org/spy2servers/schema"
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans:beans xmlns="http://www.xmatthew.org/spy2servers/schema"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:beans="http://www.springframework.org/schema/beans"
5 xmlns:context="http://www.springframework.org/schema/context"
6 xmlns:util="http://www.springframework.org/schema/util"
7 xsi:schemaLocation="http://www.springframework.org/schema/beans
8 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
9 http://www.xmatthew.org/spy2servers/schema
10 http://www.xmatthew.org/spy2servers/schema/spy2servers-1.0.xsd
11 http://www.springframework.org/schema/context
12 http://www.springframework.org/schema/context/spring-context-2.0.xsd">
13
14 <core-component>
15 <simple-alertRule>
16 <channel>
17 <from value="ActiveMQJmxSpyComponent"/>
18 <from value="SunJVMJmxSpyComponent"/>
19 <from value="TomcatJmxSpyComponent"/>
20 <to value="PrintScreenAlertComponent"/>
21 <!-- <to value="EmailAlertComponent" /> -->
22 </channel>
23 <!--
24 define more here
25 <channel>
26 </channel>
27 -->
28 </simple-alertRule>
29 </core-component>
30
31 <jmxService-component />
32
33 <beans:bean class="org.xmatthew.spy2servers.component.alert.PrintScreenAlertComponent"></beans:bean>
34
35 <activeMQJmxSpy host="127.0.0.1" port="1099" queueSuspendNotifyTime="2000" >
36 <heapMemorySpy memoryUsedPercentToAlert="90" alertAfterKeepTimeLive="10"/>
37 <noneHeapMemorySpy memoryUsedPercentToAlert="90" alertAfterKeepTimeLive="10"/>
38 <fileSpy filesOpenedPercentToAlert="90" alertAfterKeepTimeLive="10"/>
39 <destinationNamesToWatch>
40 <queue value="Test.Queue" />
41 <queue value="aaa" />
42 </destinationNamesToWatch>
43 <llegalIps>
44 <ip value="127.0.0.1" />
45 <ip value="192.168.0.1" />
46 </llegalIps>
47 </activeMQJmxSpy>
48
49 <tomcatJmxSpy host="127.0.0.1" port="8060">
50 <dataSourcesSpy>
51 <dataSourceSpy numActivePercentToAlert="90" dataSourceName="jdbc/opendb" />
52 </dataSourcesSpy>
53 <webModuleSpy>
54 <module value="/" />
55 <module value="/jsp-examples" />
56 </webModuleSpy>
57 </tomcatJmxSpy>
58
59 <emailAlert>
60 <emails>
61 <email value="ant_miracle@163.com" />
62 </emails>
63 <emailAccount server="smtp.163.com" serverPort="25" loginName="xxxx"
64 loginPwd="xxxx" sender="ant_miracle@163.com" sendNick="EmailAlertComponent"/>
65 </emailAlert>
66
67
68 </beans:beans>
69
是不是簡化的很多吧,配置起來也不這么麻煩了。
最后歡迎大家如果有問題和意見,給我留言。
Good Luck!
Yours Matthew!
posted on 2008-04-21 08:14
x.matthew 閱讀(1928)
評論(4) 編輯 收藏 所屬分類:
Spy2Servers