Spring centralized druid for database monitoring

Druid provides a built-in StatViewServlet for displaying Druid's statistics.

The uses of this StatViewServlet include:

  • Provides an html page for monitoring information display
  • JSON API providing monitoring information

Note: To use StatViewServlet, it is recommended to use druid 0.2.6 or later.

1. Configure web.xml

StatViewServlet is a standard javax.servlet.http.HttpServlet that needs to be configured in WEB-INF/web.xml in your web application.

  <servlet>
      <servlet-name>DruidStatView</servlet-name>
      <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>DruidStatView</servlet-name>
      <url-pattern>/druid/*</url-pattern>
  </servlet-mapping>

Access the built-in monitoring page according to the url-pattern in the configuration. If it is the above configuration, the home page of the built-in monitoring page is /druid/index.html

For example:
http://110.76.43.235:9000/druid/index.html  
http://110.76.43.235:8080/mini-web/druid/index.html 

1.1 Configure monitoring page access password

Need to configure the servlet  loginUsername and  loginPasswordthese two initial parameters.

For details, please refer to:  Configuring access permissions for Druid monitoring (configuring users and passwords for accessing monitoring information)

Examples are as follows:

<!-- 配置 Druid 监控信息显示页面 -->  
<servlet>  
    <servlet-name>DruidStatView</servlet-name>  
    <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
    <init-param>  
	<!-- 允许清空统计数据 -->  
	<param-name>resetEnable</param-name>  
	<param-value>true</param-value>  
    </init-param>  
    <init-param>  
	<!-- 用户名 -->  
	<param-name>loginUsername</param-name>  
	<param-value>druid</param-value>  
    </init-param>  
    <init-param>  
	<!-- 密码 -->  
	<param-name>loginPassword</param-name>  
	<param-value>druid</param-value>  
    </init-param>  
</servlet>  
<servlet-mapping>  
    <servlet-name>DruidStatView</servlet-name>  
    <url-pattern>/druid/*</url-pattern>  
</servlet-mapping>  

2. Configure allow and deny

The monitoring information displayed by StatViewSerlvet is more sensitive and is the internal situation of the system operation. If you need to do access control, you can configure the two parameters allow and deny. for example:

  <servlet>
      <servlet-name>DruidStatView</servlet-name>
      <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  	<init-param>
  		<param-name>allow</param-name>
  		<param-value>128.242.127.1/24,128.242.128.1</param-value>
  	</init-param>
  	<init-param>
  		<param-name>deny</param-name>
  		<param-value>128.242.127.4</param-value>
  	</init-param>
  </servlet>

Judgment Rules

  • deny takes precedence over allow, and if it is in the deny list, it will be denied even if it is in the allow list.
  • If allow is not configured or empty, all access is allowed

ip configuration rules

configuration format

  <IP>
  或者
  <IP>/<SUB_NET_MASK_size>

in

  128.242.127.1/24

24 means that the first 24 bits are the subnet mask. When comparing, if the first 24 bits are the same, it will match.

Does not support IPV6

Since the matching rule does not support IPV6, if allow or deny is configured, IPV6 cannot be accessed.

3. Configure resetEnable

在StatViewSerlvet输出的html页面中,有一个功能是Reset All,执行这个操作之后,会导致所有计数器清零,重新计数。你可以通过配置参数关闭它。

  <servlet>
      <servlet-name>DruidStatView</servlet-name>
      <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  	<init-param>
  		<param-name>resetEnable</param-name>
  		<param-value>false</param-value>
  	</init-param>
  </servlet>

4. 按需要配置Spring和Web的关联监控



 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326022965&siteId=291194637