druid配置WebStatFilter完成网络url统计

druid我们都很熟悉,是一款非常好用的数据连接池,但是很多开发者不知, druid除了数据连接池,还集成了对站点的URL进行统计的功能,下面就详细的为大家讲解一下如何配置druid的url统计。
WebStatFilter用于采集web-jdbc关联监控的数据

监控拦截器

web.xml配置

<filter>
  <filter-name>DruidWebStatFilterfilter-name>
  <filter-class>com.alibaba.druid.support.http.WebStatFilterfilter-class>
  <init-param>
    <param-name>exclusionsparam-name>
    <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,*.jsp,/druid/*,/download/*param-value>
  init-param>
  <init-param>
    <param-name>sessionStatMaxCountparam-name>
    <param-value>2000param-value>
  init-param>
  <init-param>
    <param-name>sessionStatEnableparam-name>
    <param-value>trueparam-value>
  init-param>
  <init-param>
    <param-name>principalSessionNameparam-name>
    <param-value>session_user_keyparam-value>
  init-param>
  <init-param>
    <param-name>profileEnableparam-name>
    <param-value>trueparam-value>
  init-param>
filter>
<filter-mapping>
  <filter-name>DruidWebStatFilterfilter-name>
  <url-pattern>/*url-pattern>
filter-mapping>

配置详解

exlusions配置。用于排除一些不必要的url,比如.js,/jslib/等等。配置在init-param中


exclusions

*.js,*.gif,*.jpg,*.png,*.css,*.ico,*.jsp,/druid/*,/download/*

sessionStatMaxCount配置。缺省sessionStatMaxCount是1000个。你可以按需要进行配置

param>
    <param-name>sessionStatMaxCountparam-name>
    <param-value>2000param-value>
param>

sessionStatEnable配置。你可以关闭session统计功能

param>
    <param-name>sessionStatEnableparam-name>
    <param-value>trueparam-value>
param>

principalSessionName配置。你可以配置principalSessionName,使得druid能够知道当前的session的用户是谁

param>
    <param-name>principalSessionNameparam-name>
    <param-value>session_user_keyparam-value>
param>

principalCookieName配置。如果你的user信息保存在cookie中,你可以配置principalCookieName,使得druid知道当前的user是谁

param>  
  <param-name>principalCookieNameparam-name>  
  <param-value>cookie_user_keyparam-value>  
param>  

根据需要,把其中的cookie_user_key修改为你user信息保存在cookie中的cookieName
profileEnable配置。druid 0.2.7版本开始支持profile,配置profileEnable能够监控单个url调用的sql列表

param>
    <param-name>profileEnableparam-name>
    <param-value>trueparam-value>
param>

配置界面显示

web.xml配置


<servlet>
  <servlet-name>DruidStatViewservlet-name>
  <servlet-class>com.alibaba.druid.support.http.StatViewServletservlet-class>
  <init-param>
    
    <param-name>resetEnableparam-name>
    <param-value>trueparam-value>
  init-param>
  <init-param>
    
    <param-name>loginUsernameparam-name>
    <param-value>druidparam-value>
  init-param>
  <init-param>
    
    <param-name>loginPasswordparam-name>
    <param-value>druidparam-value>
  init-param>
servlet>
<servlet-mapping>
    <servlet-name>DruidStatViewservlet-name>
    <url-pattern>/druid/*url-pattern>
servlet-mapping>

上面两项测试完毕之后,浏览器输入网址:http://ip:port/projectName/druid/index.html 将ip、port和projectName换成实际的配置,访问成功!

你可能感兴趣的:(druid配置WebStatFilter完成网络url统计)