public void collectRequestStats()

in zuul-core/src/main/java/com/netflix/zuul/stats/StatsManager.java [138:176]


    public void collectRequestStats(HttpRequestInfo req) {
        // ipv4/ipv6 tracking
        String clientIp;
        String xForwardedFor = req.getHeaders().getFirst(X_FORWARDED_FOR_HEADER);
        if (xForwardedFor == null) {
            clientIp = req.getClientIp();
        } else {
            clientIp = extractClientIpFromXForwardedFor(xForwardedFor);
        }

        boolean isIPv6 = (clientIp != null) ? isIPv6(clientIp) : false;

        String ipVersionKey = isIPv6 ? "ipv6" : "ipv4";
        incrementNamedCountingMonitor(ipVersionKey, ipVersionCounterMap);

        // host header
        String host = req.getHeaders().getFirst(HOST_HEADER);
        if (host != null) {
            int colonIdx;
            if (isIPv6) {
                // an ipv6 host might be a raw IP with 7+ colons
                colonIdx = host.lastIndexOf(":");
            } else {
                // strips port from host
                colonIdx = host.indexOf(":");
            }
            if (colonIdx > -1) {
                host = host.substring(0, colonIdx);
            }
            incrementNamedCountingMonitor(hostKey(host), this.hostCounterMap);
        }

        // http vs. https
        String protocol = req.getHeaders().getFirst(X_FORWARDED_PROTO_HEADER);
        if (protocol == null) {
            protocol = req.getScheme();
        }
        incrementNamedCountingMonitor(protocolKey(protocol), this.protocolCounterMap);
    }