最近的一个项目,需要监控到服务器的性能情况。在网上找了一下。发现一个开源项目很不错,用起来很简单方便,获取的信息也很全面。现将我做的一个Demo放上来,供大家参考。
下载Jar包javamelody.jar和jrobin-1.5.9.1.jar
JavaMelody开源项目地址:http://code.google.com/p/javamelody/
把解压后的两个jar包放到项目WEB-INF\lib下面。
配制web.xml(添加一个filter和一个listener),代码如下:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>cottsoft</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>monitoring</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> </filter> <filter-mapping> <filter-name>monitoring</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>net.bull.javamelody.SessionListener</listener-class> </listener> </web-app>
运行你的项目后,即可启动监控页面.
比如说我的应用访问路径为:http://10.13.0.3:8080/cottsoft/
那么我可以通过http://10.13.0.3:8080/cottsoft/monitoring?period=jour来访问监控页面.