`

JavaMelody开源系统性能监控

阅读更多

1.下载运行需要的jar包

JavaMelody运行需要两个jar包:jrobin.jar和javamelody.jar,请到官方网站下载javamelody-1.36.0.zip,里面含有这两个jar包。

JavaMelody开源项目地址:http://code.google.com/p/javamelody/

 

2.搭建环境

(1)将jrobin.jar和javamelody.jar放到本地WEB工程的WEB-INF/lib下面,使其在ClassPath下能访问。

(2)打开WEB工程的web.xml文件,在里面添加以下的一段配置:

 

<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>
 

 

(3)将该WEB工程部署到J2EE容器并启动容器,通过下面的 URL 访问到程序运行情况。

 

http://<host>:<port>/<context>/monitoring

 

<host>:为你的主机名

<port>:端口地址

<context>:为你的应用配置地址

 

可以看到内存使用量,session数量,线程数等的内容,还可以以日,周,月,年图表现实,相当方便实用

 

(4)从刚才的界面发现JDBC和SQL没有监控起来,因为我的数据源是配置在spring的bean里面的。

需要在web.xml中加载spring配置文件的地方加入javamelody的spring配置,它能够将spring的对象进行包装代理。只要在该配置的第一行添加classpath:net/bull/javamelody/monitoring-spring.xml就可以了。具体如下:

 

 

        <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>
                classpath:net/bull/javamelody/monitoring-spring.xml
                classpath:context/services.xml
                classpath:context/data-access-layer.xml
                /WEB-INF/applicationContext.xml
          </param-value>
        </context-param>
 

(5)重新启动J2EE容器,这个时候就可以看到JDBC的连接数和SQL执行的情况了。

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics