Druid monitoring page configuration and use, druid monitoring page
1. Add Durid connection pool dependency to Maven
<! -- Druid connection pool --> <dependency> <groupId> com. alibaba </groupId> <artifactId> druid </artifactId> <version> 1.0.29 </version> </dependency>
2. Configure the Druid data source in Spring and set monitoring parameters
<! -- Druid data source --> <bean id = "dataSource" class = "com. alibaba. druid. pool. druidDataSource "init-method =" init "destroy-method =" close "> <! -- Basic attribute url, user, password --> <property name = "url" value = "$ {db. url} "/> <property name =" username "value =" $ {db. username} "/> <property name =" password "value =" $ {db. password} "/> <! -- Configure the initialization size, minimum, and maximum --> <property name = "initialSize" value = "20"/> <property name = "minIdle" value = "1"/> <property name = "maxActive" value = "40"/> <! -- Configure the timeout time for obtaining connections --> <property name = "maxWait" value = "60000"/> <! -- Configure the interval for a test to detect idle connections that need to be closed, in milliseconds --> <property name = "timeBetweenEvictionRunsMillis" value = "60000"/> <! -- Configure the minimum time for a connection to survive in the pool, unit: millisecond --> <property name = "minEvictableIdleTimeMillis" value = "300000"/> <property name = "validationQuery" value = "SELECT 'x'"/> <property name = "testWhileIdle" value = "true"/> <property name = "testOnBorrow" value = "false"/> <property name = "testOnReturn" value = "false"/> <! -- Configure the monitoring statistic interception filters --> <property name = "filters" value = "stat"/> </bean>
3. Configure the Druid monitoring Servlet in web. xml
<! -- Druid monitoring --> <servlet-name> DruidStatView </servlet-name> <servlet-class> com. alibaba. druid. support. http. statViewServlet </servlet-class> <init-param> <! -- Username --> <param-name> loginUsername </param-name> <param-value> druid </param-value> </init-param> <! -- Password --> <param-name> loginPassword </param-name> <param-value> bounter </param-value> </init-param> </servlet> <servlet -mapping> <servlet-name> DruidStatView </servlet-name> <url-pattern>/druid/* </url-pattern> </servlet-mapping>
4. Access http: // localhost: 8080/druid/through a browser/