做网站找哪家好要钱吗,安吉网站建设公司,模板的种类,解决网站兼容性问题最近看到一位同事正在开发一个监控软件#xff0c;要求就是通过针对服务器现有的一些接口#xff0c;通过这些接口返回的数据进行分析#xff0c;如果监控的值到达预先设定的范围则通过短信的方式发送给管理员。从整个开发的功能上来看是一个比较单一也很明确的功能#xf…最近看到一位同事正在开发一个监控软件要求就是通过针对服务器现有的一些接口通过这些接口返回的数据进行分析如果监控的值到达预先设定的范围则通过短信的方式发送给管理员。从整个开发的功能上来看是一个比较单一也很明确的功能所开发的系统对所其所监控的软件的依赖性也非常大主要是监控的数据分析行为和监控信息的服务报警行为这块。既然这两块很难做成一个通用的功能模块那就搭建一个监控平台可以让这些功能模块通过组件的方式自由的注册和销毁。所有我构思了这个监控平台它对外有三个接口分别是监控接口报警接口和监控消息监控接口。由平台统一管理这些组件的生命周期每个组件都过单独的线程运行。提供一个核心组件CoreComponent调度所有监控数据的流转。平台本身还使用基于jmx管理服务技术提供对所有当前使用的组件运行情况的监控也包括动态的启动和停止组件的运行状态。下载地址二进制程序第三方类库下载,第三方类库下载2 放到lib目录下。api-docs源代码下面是部分设计图:AlertComponent设计图SpyComponent设计图MessageAlertChannelActiveAwareComponent设计图下面我利用该平台开发一个监控ActiveMQ状态的组件ActiveMQJmxSpyComponent,该组件实现对AMQ运行状态的监控(监听失败或失败后重新连接成功)。可以通过指定Queue名称列表来指定要监控Queue队列的消费者是否为0(通常表示对方可能因为网络或服务中断而失去监控)或是队列消息都由0变为大于0表示消费者重新监听上服务。1publicclassActiveMQJmxSpyComponentextendsAbstractSpyComponent{2/** *//**3 * Logger for this class4*/5privatestaticfinalLogger LOGGERLogger.getLogger(ActiveMQJmxSpyComponent.class);6//AMQ jmx serverUrl to spy7privateString serverUrl;8//detect interval(unit is ms)9privateintdetectInterval5000;10//the Queue name list to spy11privateSetdestinationNamesToWatch;12//if queues consumer suspends after then certain time then to notify. default is 3 minutes13privateintqueueSuspendNotifyTime3*60*1000;下面是一个报警组件的实现:只是简单的把监控消息打印在屏幕上PrintScreenAlertComponent1publicclassPrintScreenAlertComponentextendsAbstractAlertComponent{23/**//*(non-Javadoc)4 * see org.xmatthew.spy2servers.core.Component#getName()5*/6publicString getName(){7returnPrintScreenAlertComponent;8 }910/**//*(non-Javadoc)11 * see org.xmatthew.spy2servers.core.Component#startup()12*/13publicvoidstartup(){14 setStatusRun();1516 }1718/**//*(non-Javadoc)19 * see org.xmatthew.spy2servers.core.Component#stop()20*/21publicvoidstop(){22 setStatusStop();2324 }2526 Override27protectedvoidonAlert(Message message){28 System.out.println(message);2930 }3132}33下面该组件的注册。${CUR_PATH}/conf/spy2servers.xml1?xml version1.0 encodingUTF-8?2 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance4 xmlns:aophttp://www.springframework.org/schema/aop5 xmlns:txhttp://www.springframework.org/schema/tx6 xsi:schemaLocationhttp://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.xsd910111213141516171819Matthew.Queue20Rocket.Queue21222324252627ok,现在ActiveMQJmxSpyComponent监控到的消息能会被PrintScreenAlertComponent打印到屏幕上。现在启动程序我们看到ActiveMQJmxSpyComponent和PrintScreenAlertComponent组件已经启动了。使用Jconsole进行监控如果此时需要建立一个消息报警的规则只要实现以下接口并注入到CoreComponent的alertRule属性中即可。1publicinterfaceAlertRule{23booleanisAlertAllow(MessageAlertChannel channel);4}应用这个平台开发监控的组件就这么简单。备注:因为开发时间比较紧如果有什么Bug也希望大家反馈给我我会改进。Yours Matthew!posted on 2008-03-12 13:41 x.matthew 阅读(1953) 评论(7) 编辑 收藏