When we use the Druid in the Javaweb project as our connection pool, we must not forget to add the monitoring function. Let's take a look at a simple Web project (not yet using any framework) if we're going to configure our website. XML to complete our monitoring configuration
The first is the configuration of filter filters, and the following configuration is added in Web. xml
<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>
1.1 Configuring the Monitoring page access password
The servlet loginUsername
and loginPassword
These two initial parameters need to be configured.
Refer to: Configure Access for Druid monitoring (Users and passwords that configure access monitoring information)
Examples are as follows:
<!--Configuring the DRUID Monitoring Information Display page - <servlet> <Servlet-name>Druidstatview</Servlet-name> <Servlet-class>Com.alibaba.druid.support.http.StatViewServlet</Servlet-class> <Init-param> <!--allow emptying of statistics - <Param-name>Resetenable</Param-name> <Param-value>True</Param-value> </Init-param> <Init-param> <!--User name - <Param-name>Loginusername</Param-name> <Param-value>Druid</Param-value> </Init-param> <Init-param> <!--Password - <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
Statviewserlvet Display of monitoring information is sensitive, is the internal condition of the system operation, if you need to do access control, you can configure allow and deny these two parameters. Like what:
<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>
Judging rules
- Deny takes precedence over allow, and is rejected in the Deny list even if it is in the Allow list.
- If allow is not configured or is empty, all access is allowed
IP Configuration Rules
Format of the configuration
<IP> 或者 <IP>/<SUB_NET_MASK_size>
which
128.242.127.1/24
24 means that the front 24 bits are subnet masks, and the previous 24 bits are matched when compared.
IPV6 not supported
Because the match rule does not support IPV6, the Allow or deny is configured to cause IPV6 to be inaccessible.
3. Configure Resetenable
In the HTML page of the Statviewserlvet output, one function is reset all, which causes all counters to be zeroed and re-counted after performing this operation. You can turn it off by configuring the parameters.
<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>
Reference Url:https://github.com/alibaba/druid/wiki/%e9%85%8d%e7%bd%ae_statviewservlet%e9%85%8d%e7%bd%ae
Druid Use Start-Configure the Monitoring connection pool in the Javaweb project