JAVA Web项目服务器性能监控工具JavaMelody

最近的一个项目,需要监控到服务器的性能情况。在网上找了一下。发现一个开源项目很不错,用起来很简单方便,获取的信息也很全面。现将我做的一个Demo放上来,供大家参考。

下载Jar包javamelody.jar和jrobin-1.5.9.1.jar

把解压后的两个jar包放到项目WEB-INFlib下面。

配制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>
运行你的项目后,即可启动监控页面.

比如说我的应用访问路径为:

那么我可以通过来访问监控页面.

经验分享 程序员 微信小程序 职场和发展