Search in sources :

Example 1 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class WebStatFilter method init.

@Override
public void init(FilterConfig config) throws ServletException {
    {
        String exclusions = config.getInitParameter(PARAM_NAME_EXCLUSIONS);
        if (exclusions != null && exclusions.trim().length() != 0) {
            excludesPattern = new HashSet<String>(Arrays.asList(exclusions.split("\\s*,\\s*")));
        }
    }
    {
        String param = config.getInitParameter(PARAM_NAME_PRINCIPAL_SESSION_NAME);
        if (param != null) {
            param = param.trim();
            if (param.length() != 0) {
                this.principalSessionName = param;
            }
        }
    }
    {
        String param = config.getInitParameter(PARAM_NAME_PRINCIPAL_COOKIE_NAME);
        if (param != null) {
            param = param.trim();
            if (param.length() != 0) {
                this.principalCookieName = param;
            }
        }
    }
    {
        String param = config.getInitParameter(PARAM_NAME_SESSION_STAT_ENABLE);
        if (param != null && param.trim().length() != 0) {
            param = param.trim();
            if ("true".equals(param)) {
                this.sessionStatEnable = true;
            } else if ("false".equals(param)) {
                this.sessionStatEnable = false;
            } else {
                LOG.error("WebStatFilter Parameter '" + PARAM_NAME_SESSION_STAT_ENABLE + "' config error");
            }
        }
    }
    {
        String param = config.getInitParameter(PARAM_NAME_PROFILE_ENABLE);
        if (param != null && param.trim().length() != 0) {
            param = param.trim();
            if ("true".equals(param)) {
                this.profileEnable = true;
            } else if ("false".equals(param)) {
                this.profileEnable = false;
            } else {
                LOG.error("WebStatFilter Parameter '" + PARAM_NAME_PROFILE_ENABLE + "' config error");
            }
        }
    }
    {
        String param = config.getInitParameter(PARAM_NAME_SESSION_STAT_MAX_COUNT);
        if (param != null && param.trim().length() != 0) {
            param = param.trim();
            try {
                this.sessionStatMaxCount = Integer.parseInt(param);
            } catch (NumberFormatException e) {
                LOG.error("WebStatFilter Parameter '" + PARAM_NAME_SESSION_STAT_ENABLE + "' config error", e);
            }
        }
    }
    // realIpHeader
    {
        String param = config.getInitParameter(PARAM_NAME_REAL_IP_HEADER);
        if (param != null) {
            param = param.trim();
            if (param.length() != 0) {
                this.realIpHeader = param;
            }
        }
    }
    StatFilterContext.getInstance().addContextListener(statFilterContextListener);
    this.contextPath = DruidWebUtils.getContextPath(config.getServletContext());
    if (webAppStat == null) {
        webAppStat = new WebAppStat(contextPath, this.sessionStatMaxCount);
    }
    WebAppStatManager.getInstance().addWebAppStatSet(webAppStat);
}
Also used : WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat) HashSet(java.util.HashSet)

Example 2 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class MonitorClient method collectWebURI.

private void collectWebURI() {
    if ((!collectWebAppEnable) && !collectWebURIEnable) {
        return;
    }
    List<WebURIStatValue> webURIValueList = new ArrayList<WebURIStatValue>();
    List<WebAppStatValue> webAppStatValueList = new ArrayList<WebAppStatValue>();
    Set<Object> stats = WebAppStatManager.getInstance().getWebAppStatSet();
    for (Object item : stats) {
        if (!(item instanceof WebAppStat)) {
            continue;
        }
        WebAppStat webAppStat = (WebAppStat) item;
        if (collectWebAppEnable) {
            WebAppStatValue webAppStatValue = webAppStat.getStatValue(true);
            webAppStatValueList.add(webAppStatValue);
        }
        if (collectWebURIEnable) {
            webURIValueList.addAll(webAppStat.getURIStatValueList(true));
        }
    }
    MonitorContext ctx = createContext();
    if (webURIValueList.size() > 0) {
        dao.saveWebURI(ctx, webURIValueList);
    }
    if (webAppStatValueList.size() > 0) {
        dao.saveWebApp(ctx, webAppStatValueList);
    }
}
Also used : WebAppStatValue(com.alibaba.druid.support.http.stat.WebAppStatValue) ArrayList(java.util.ArrayList) WebURIStatValue(com.alibaba.druid.support.http.stat.WebURIStatValue) WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat)

Example 3 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class UserAgentAndroid_4_0_3_Test method test_mac_firefox.

public void test_mac_firefox() throws Exception {
    WebAppStat stat = new WebAppStat("");
    stat.computeUserAgent("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
    Assert.assertEquals(0, stat.getBrowserChromeCount());
    Assert.assertEquals(0, stat.getBrowserFirefoxCount());
    Assert.assertEquals(0, stat.getBrowserOperaCount());
    Assert.assertEquals(0, stat.getBrowserSafariCount());
    Assert.assertEquals(0, stat.getBrowserIECount());
    Assert.assertEquals(0, stat.getBrowserIE10Count());
    Assert.assertEquals(1, stat.getDeviceAndroidCount());
    Assert.assertEquals(0, stat.getDeviceIphoneCount());
    Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
    Assert.assertEquals(1, stat.getOSLinuxCount());
    Assert.assertEquals(1, stat.getOSAndroidCount());
    Assert.assertEquals(1, stat.getOSAndroid40Count());
    Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
    Assert.assertEquals(0, stat.getOSMacOSXCount());
    Assert.assertEquals(0, stat.getOSWindowsCount());
    Assert.assertEquals(0, stat.getOSWindows8Count());
    Assert.assertEquals(0, stat.getOSSymbianCount());
    Assert.assertEquals(0, stat.getOSFreeBSDCount());
    Assert.assertEquals(0, stat.getOSOpenBSDCount());
}
Also used : WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat)

Example 4 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class UserAgentAndroid_4_0_3_Test_2 method test_mac_firefox.

public void test_mac_firefox() throws Exception {
    WebAppStat stat = new WebAppStat("");
    stat.computeUserAgent("Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
    Assert.assertEquals(0, stat.getBrowserChromeCount());
    Assert.assertEquals(0, stat.getBrowserFirefoxCount());
    Assert.assertEquals(0, stat.getBrowserOperaCount());
    Assert.assertEquals(0, stat.getBrowserSafariCount());
    Assert.assertEquals(0, stat.getBrowserIECount());
    Assert.assertEquals(0, stat.getBrowserIE10Count());
    Assert.assertEquals(1, stat.getDeviceAndroidCount());
    Assert.assertEquals(0, stat.getDeviceIphoneCount());
    Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
    Assert.assertEquals(1, stat.getOSLinuxCount());
    Assert.assertEquals(1, stat.getOSAndroidCount());
    Assert.assertEquals(1, stat.getOSAndroid40Count());
    Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
    Assert.assertEquals(0, stat.getOSMacOSXCount());
    Assert.assertEquals(0, stat.getOSWindowsCount());
    Assert.assertEquals(0, stat.getOSWindows8Count());
    Assert.assertEquals(0, stat.getOSSymbianCount());
    Assert.assertEquals(0, stat.getOSFreeBSDCount());
    Assert.assertEquals(0, stat.getOSOpenBSDCount());
}
Also used : WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat)

Example 5 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class UserAgentWindows method test_windowsXP_IE6.

public void test_windowsXP_IE6() throws Exception {
    WebAppStat stat = new WebAppStat("");
    stat.computeUserAgent("User-Agent: Mozilla/5.0 (compatible; MSIE 6.0;Windows XP)");
    Assert.assertEquals(1, stat.getBrowserIECount());
    Assert.assertEquals(0, stat.getBrowserChromeCount());
    Assert.assertEquals(0, stat.getBrowserFirefoxCount());
    Assert.assertEquals(0, stat.getBrowserIE10Count());
    Assert.assertEquals(0, stat.getBrowserIE5Count());
    Assert.assertEquals(1, stat.getBrowserIE6Count());
    Assert.assertEquals(0, stat.getBrowserIE7Count());
    Assert.assertEquals(0, stat.getBrowserIE8Count());
    Assert.assertEquals(0, stat.getBrowserIE9Count());
    Assert.assertEquals(0, stat.getBrowserOperaCount());
    Assert.assertEquals(0, stat.getBrowserSafariCount());
    Assert.assertEquals(0, stat.getDeviceAndroidCount());
    Assert.assertEquals(0, stat.getDeviceIpadCount());
    Assert.assertEquals(0, stat.getDeviceIphoneCount());
    Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
    Assert.assertEquals(0, stat.getOSLinuxCount());
    Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
    Assert.assertEquals(0, stat.getOSMacOSXCount());
    Assert.assertEquals(1, stat.getOSWindowsCount());
    Assert.assertEquals(0, stat.getOSSymbianCount());
    Assert.assertEquals(0, stat.getOSFreeBSDCount());
    Assert.assertEquals(0, stat.getOSOpenBSDCount());
    Assert.assertEquals(0, stat.getOSWindows98Count());
    Assert.assertEquals(1, stat.getOSWindowsXPCount());
}
Also used : WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat)

Aggregations

WebAppStat (com.alibaba.druid.support.http.stat.WebAppStat)113 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)3 MockFilterChain (org.springframework.mock.web.MockFilterChain)3 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockServletContext (org.springframework.mock.web.MockServletContext)3 WebAppStatValue (com.alibaba.druid.support.http.stat.WebAppStatValue)1 WebRequestStat (com.alibaba.druid.support.http.stat.WebRequestStat)1 WebSessionStat (com.alibaba.druid.support.http.stat.WebSessionStat)1 WebURIStat (com.alibaba.druid.support.http.stat.WebURIStat)1 WebURIStatValue (com.alibaba.druid.support.http.stat.WebURIStatValue)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1