<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>
JDBC
若是你的数据源命名为"jdbc/MyDataSource", 而且配置在应用服务器 (webapp的context), 那么你的sql请求会被自动监控而不须要任何参数(在 Tomcat 5.5 and 6, glassfish 3, jboss 5, weblogic 11g, jetty 6上测试经过).
若是你的JDBC驱动是无数据源直接使用的, 那你的驱动类应该定义为:"net.bull.javamelody.JdbcDriver" ,而后应该加入jdbc属性"driver"值为真正的dirver class. 例如, 若是你使用的是hibernate.cfg.xml和mysql (无hibernate.connection.datasource): java
<property name ="hibernate.connection.driver_class" >net.bull.javamelody.JdbcDriver </property> <property name ="hibernate.connection.driver">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/myschema </property> <property nam="hibernate.connection.username">myuser</property> <property name="hibernate.connection.password">mypassword</property>
若是你使用了数据源可是名称并不像"jdbc/MyDataSource"这样,或者数据源没有在一个日常的"java:comp/env/" 或者 "java:/"的JNDI 上下文中,那么你能够能够增长可选参数“datasources” (在system property或filter的上下文中) 去定义应用使用的数据源的JNDI. 若是有多个数据源,这个参数的值能够用逗号分隔。 若是使用 的服务器是jonas V5,数据源能够被监控,但如今看来,它们必须定义在 datasources参数中。
例如: mysql
-Djavamelody.datasources=java:comp/env/myapp/MyDataSource
若是数据源定义在spring中, 如: web
<bean class="org.apache.commons.dbcp.BasicDataSource">...</bean>
它也是能够被监控到的,利用Spring post-processor. 须确保Spring的配置文件 (net/bull/javamelody/monitoring-spring.xml ,包含在jar包中)被看成配置文件第一个加载. spring
例如:若是你在你的 web.xml中 配置了 sql
org.springframework.web.context.ContextLoaderListener
那你的配置中应该配置参数: apache
<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>