Beispiel #1
0
  public void analyseOneLine(String line) {
    logger.debug("analyse line");

    if (!passFilterUrl(line)) {
      return;
    }

    String useTimeStr = "";
    String requestUrl = "";
    String httpCode = " ";
    try {
      String collectTime = parseLogLineCollectTime(line);
      if (!passFilterCollectTime(collectTime)) {
        return;
      }

      String[] tokens = line.split("\"");
      useTimeStr = tokens[0].split(" ")[1];
      requestUrl = cleanUrl(tokens[1].split(" ")[1]);
      if (requestUrl == null
          || requestUrl.length() < 20
          || (!URL_FILTER.contains(requestUrl.trim()))) {
        return;
      }

      httpCode = tokens[2].trim().split(" ")[0];
      long useTime = 0L;
      if (!useTimeStr.equals("-")) {
        if (useTimeStr.indexOf(".") > -1) {
          useTime = (long) (Float.parseFloat(useTimeStr) * 1000 * 1000);
        } else {
          useTime = Long.parseLong(useTimeStr);
        }
      }

      ApacheSpecialLogKey key = new ApacheSpecialLogKey();
      key.setAppName(this.getAppName());
      key.setRequstUrl(requestUrl);
      key.setHttpCode(httpCode);
      key.setCollectTime(collectTime);

      ApacheSepcial value;
      if (cache.containsKey(key)) {
        value = cache.get(key);
      } else {
        value = new ApacheSepcial();
        cache.put(key, value);
      }

      value.setRequstNum(value.getRequstNum() + 1);
      value.setRt(value.getRt() + useTime);
    } catch (Exception e) {
      logger.error("analyse error", e);
    }
  }
Beispiel #2
0
  private List<Log> generateLogPos() {
    List<Log> list = new ArrayList<Log>();
    for (Map.Entry<ApacheSpecialLogKey, ApacheSepcial> entry : cache.entrySet()) {
      ApacheSpecialLogKey key = entry.getKey();
      ApacheSepcial value = entry.getValue();

      ApacheSpecialLog po = new ApacheSpecialLog();
      po.setAppName(key.getAppName());
      po.setRequestUrl(key.getRequstUrl());
      po.setHttpCode(key.getHttpCode());
      po.setCollectTime(key.getCollectTime());
      po.setRequestNum(value.getRequstNum());
      po.setRt(value.getRt());

      list.add(po);
    }

    return list;
  }