Home  >  Article  >  Java  >  Detailed introduction to Druid monitoring page

Detailed introduction to Druid monitoring page

零下一度
零下一度Original
2017-07-18 17:54:534924browse

1. Add Durid connection pool dependency in Maven

<!-- druid连接池 -->
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid</artifactId>
  <version>1.0.29</version>
</dependency>

2 , Configure Druid data source in Spring, and set monitoring parameters

<!-- druid数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  <!-- 基本属性 url、user、password -->
  <property name="url" value="${db.url}" />
  <property name="username" value="${db.username}" />
  <property name="password" value="${db.password}" />

  <!-- 配置初始化大小、最小、最大 -->
  <property name="initialSize" value="20" />
  <property name="minIdle" value="1" />
  <property name="maxActive" value="40" />

  <!-- 配置获取连接等待超时的时间 -->
  <property name="maxWait" value="60000" />

  <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  <property name="timeBetweenEvictionRunsMillis" value="60000" />

  <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  <property name="minEvictableIdleTimeMillis" value="300000" />

  <property name="validationQuery" value="SELECT &#39;x&#39;" />
  <property name="testWhileIdle" value="true" />
  <property name="testOnBorrow" value="false" />
  <property name="testOnReturn" value="false" />

  <!-- 配置监控统计拦截的filters -->
  <property name="filters" value="stat" />
  </bean>

3. Configure Druid monitoring Servlet## in web.xml

#
<!-- druid监控 -->
  <servlet>
  <servlet-name>DruidStatView</servlet-name>
  <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  <init-param>
  <!-- 用户名 -->
  <param-name>loginUsername</param-name>
  <param-value>druid</param-value>
  </init-param>
  <init-param>
  <!-- 密码 -->
  <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>

The above is the detailed content of Detailed introduction to Druid monitoring page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn