您的位置:首页 > 产品设计 > UI/UE

druid StatViewServlet配置 内置web页面

2017-04-26 09:58 246 查看

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

<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>  

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

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

2. 配置allow和deny

StatViewSerlvet展示出来的监控信息比较敏感,是系统运行的内部情况,如果你需要做访问控制,可以配置allow和deny这两个参数。比如:

[html]
view plain
copy

<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>  

判断规则

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

<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> 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: