druid StatViewServlet配置 内置web页面

来源:互联网 发布:外卖快餐软件 编辑:程序博客网 时间:2024/06/03 22:38

druid StatViewServlet配置 内置web页面

Druid内置提供了一个StatViewServlet用于展示Druid的统计信息。

这个StatViewServlet的用途包括:

  • 提供监控信息展示的html页面
  • 提供监控信息的JSON API

注意:使用StatViewServlet,建议使用druid 0.2.6以上版本。

1. 配置web.xml

StatViewServlet是一个标准的javax.servlet.http.HttpServlet,需要配置在你web应用中的WEB-INF/web.xml中。


[html] view plain copy
  1. <servlet>  
  2.       <servlet-name>DruidStatView</servlet-name>  
  3.       <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
  4.   </servlet>  
  5.   <servlet-mapping>  
  6.       <servlet-name>DruidStatView</servlet-name>  
  7.       <url-pattern>/druid/*</url-pattern>  
  8.   </servlet-mapping>  

根据配置中的url-pattern来访问内置监控页面,如果是上面的配置,内置监控页面的首页是/druid/index.html

例如:
http://server:port/appname/druid/index.html

2. 配置allow和deny

StatViewSerlvet展示出来的监控信息比较敏感,是系统运行的内部情况,如果你需要做访问控制,可以配置allow和deny这两个参数。比如:
[html] view plain copy
  1. <servlet>  
  2.     <servlet-name>DruidStatView</servlet-name>  
  3.     <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
  4.   <init-param>  
  5.       <param-name>allow</param-name>  
  6.       <param-value>128.242.127.1/24,128.242.128.1</param-value>  
  7.   </init-param>  
  8.   <init-param>  
  9.       <param-name>deny</param-name>  
  10.       <param-value>128.242.127.4</param-value>  
  11.   </init-param>  
  12. </servlet>  

判断规则

  • deny优先于allow,如果在deny列表中,就算在allow列表中,也会被拒绝。
  • 如果allow没有配置或者为空,则允许所有访问

ip配置规则

配置的格式

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

其中

  128.242.127.1/24

24表示,前面24位是子网掩码,比对的时候,前面24位相同就匹配。

不支持IPV6

由于匹配规则不支持IPV6,配置了allow或者deny之后,会导致IPV6无法访问。

3. 配置resetEnable

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

[html] view plain copy
  1. <servlet>  
  2.       <servlet-name>DruidStatView</servlet-name>  
  3.       <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
  4.     <init-param>  
  5.         <param-name>resetEnable</param-name>  
  6.         <param-value>false</param-value>  
  7.     </init-param>  
  8.   </servlet> 
0 0
原创粉丝点击