集成服务监控器green.monitor发布
集成服务监控器-green.monitor发布
在大型企业应用开发中,一个项目经常需要依赖于多个项目集成,经常某个集成服务的升级或者不工作,会导致你所工作的服务也挂掉,甚至影响你的开发流程。你是否还在接到测试团队或者运维团队的某个Bug,而自己花费了大量时间终于查出来是某个集成服务升级或异常,在这里浪费了大量时间,在笔者为所在项目建立了一个第三方集成服务监控的Monitor,去实时监控项目所依赖的所有集成服务,数据库。现在开源在github https://github.com/greengerong/green-monitor ,在其sample目录下有个使用demo。
maven dependency
< dependency > < groupId > com.github.greengerong </ groupId > < artifactId > green.monitor </ artifactId > < version > 1.2 </ version > </ dependency >
demo效果如下:
建立自己的monitor:
1:首先在你spring mvc web project 的 pom文件中引 入green-monitor的dependency。(spring 3.0以上)
2:在spring mvc的 ioc context config中启用annotation dirver,如下xml:
<? xml version="1.0" encoding="UTF-8" ?> < beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns:p ="http://www.springframework.org/schema/p" xmlns:mvc ="http://www.springframework.org/schema/mvc" xmlns:context ="http://www.springframework.org/schema/context" xmlns:util ="http://www.springframework.org/schema/util" xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd" > < mvc:annotation-driven /> < context:component-scan base-package ="green.monitor" /> < bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> < bean id ="viewResolver" class ="org.springframework.web.servlet.view.InternalResourceViewResolver" > < property name ="prefix" > < value > /WEB-INF/pages/ </ value > </ property > < property name ="suffix" > < value > .jsp </ value > </ property > </ bean > </ beans >
3:在项目resources(mian/resources)下建立monitor-config.xml。如果需要 在不同环境配置不同信息,可以在运行机器上加入key为appenv的环境变量,程序会根据不同agent加载monitor-config.[appenv].xml配置文件.或者利用mavn,gradle这类构建工具按环境输出配置信息。
配置文件形如:
<? xml version="1.0" encoding="UTF-8" ?> < monitoring version ="1.0" name ="monitor-sample" > < monitors > < monitor name ="mock-monitor" > green.monitor.demo.MockMonitorRunner </ monitor > </ monitors > < items > < item monitor ="http-connection" name ="hello service" > < params > < param name ="url" > http://localhost:8080/demo/hello </ param > < param name ="method" > GET </ param > < param name ="response-code" > 200 </ param > < param name ="param" > name=success </ param > </ params > < description > This is a monitor for hello service.should be success. </ description > </ item > < item monitor ="http-connection" name ="error service 2" > < params > < param name ="url" > http://localhost:8080/demo/failed </ param > < param name ="method" > GET </ param > < param name ="response-code" > 200 </ param > < param name ="param" > name=must be failed </ param > </ params > < description > This is a monitor for error service.should be failed. </ description > </ item > < item monitor ="mock-monitor" name ="Random failed Service" > < description > This monitor will be random failed! </ description > </ item > </ items > </ monitoring >
这样你就可以运行monitor了,url为host + “/monitor”
扩展1:扩展runner 同时monitor为你提供了自我特定需求扩展的机会,在xml config中你应该主意到了有个monitor的配置节,这里就可以配置你自定义runner(其实现MonitorRunner接口),配置节name则作为后边item的引用name。
系统默认加入了web-service,dababase,http-connection3个常用runner。具体使用请看demo。
2:系统提供了service为基于spring restfull api,所以你可以在其他地方展示该monitor状况。(在下一个版本将提供jsonp的跨域处理)。
monitor project repo: https://github.com/greengerong/green-monitor
作者: 破 狼
出处: http://www.cnblogs.com/whitewolf/
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。该文章也同时发布在我的独立博客中- 博客园--破狼 和 51CTO--破狼 。
分类: AngularJs , JavaScript , Java世界 , 敏捷/持续集成
作者: Leo_wl
出处: http://www.cnblogs.com/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于集成服务监控器green.monitor发布的详细内容...