From 4ee90a3671d96ea2250760dc062c182fc54a07a7 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 20 Feb 2021 02:00:00 +0100 Subject: [PATCH] Added http error log analyze. --- .../devinsy/statoolinfos/metrics/Prober.java | 6 +- .../http/{HttpLog.java => HttpAccessLog.java} | 10 +- .../metrics/http/HttpAccessLogAnalyzer.java | 55 +++--- .../metrics/http/HttpErrorLog.java | 163 ++++++++++++++++++ .../metrics/http/HttpErrorLogAnalyzer.java | 91 +++++++++- .../metrics/http/HttpLogIterator.java | 4 +- .../metrics/http/VisitCounters.java | 4 +- .../metrics/http/VisitCountersTest.java | 24 +-- 8 files changed, 294 insertions(+), 63 deletions(-) rename src/fr/devinsy/statoolinfos/metrics/http/{HttpLog.java => HttpAccessLog.java} (96%) create mode 100644 src/fr/devinsy/statoolinfos/metrics/http/HttpErrorLog.java diff --git a/src/fr/devinsy/statoolinfos/metrics/Prober.java b/src/fr/devinsy/statoolinfos/metrics/Prober.java index 36452c7..78b7741 100644 --- a/src/fr/devinsy/statoolinfos/metrics/Prober.java +++ b/src/fr/devinsy/statoolinfos/metrics/Prober.java @@ -114,11 +114,7 @@ public class Prober } // - { - PathCounter counter = counters.get("metrics.http.hits", "2020"); - logger.info("counter=" + counter.getCounter()); - logger.info("size={}", counters.size()); - } + logger.info("size={}", counters.size()); } /** diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpLog.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java similarity index 96% rename from src/fr/devinsy/statoolinfos/metrics/http/HttpLog.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java index ea738c0..390b750 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpLog.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java @@ -31,11 +31,11 @@ import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; /** - * The Class HttpLog. + * The Class HttpAccessLog. */ -public class HttpLog +public class HttpAccessLog { - private static Logger logger = LoggerFactory.getLogger(HttpLog.class); + private static Logger logger = LoggerFactory.getLogger(HttpAccessLog.class); public static final Pattern IPV4_PATTERN = Pattern.compile("\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}"); public static final Pattern IPV6_PATTERN = Pattern.compile("([0-9a-f]{1,4}:{1,2}){4,7}([0-9a-f]){1,4}", Pattern.CASE_INSENSITIVE); @@ -50,9 +50,9 @@ public class HttpLog private UserAgent userAgent; /** - * Instantiates a new http log. + * Instantiates a new http access log. */ - public HttpLog() + public HttpAccessLog() { this.remoteAddress = null; this.remoteUser = null; diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java index 0f801a3..396bb8e 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java @@ -124,8 +124,7 @@ public class HttpAccessLogAnalyzer */ public void probeLine(final String line) { - - HttpLog log = parseNginxCombinedLog(line); + HttpAccessLog log = parseNginxCombinedLog(line); // logger.info("=================="); if (log == null) @@ -171,7 +170,7 @@ public class HttpAccessLogAnalyzer } // metrics.http.pages.* = - if (StringUtils.endsWithAny(log.getRequest(), ".html", ".htm", ".xhtml", ".cgi")) + if (StringUtils.endsWithAny(log.getRequest(), ".html", ".htm", ".xhtml", ".cgi", "/")) { this.counters.inc("metrics.http.pages", year, yearMonth, yearWeek, date); } @@ -223,38 +222,16 @@ public class HttpAccessLogAnalyzer * the line * @return the http log */ - public static HttpLog parseNginxCombinedLog(final String line) + public static HttpAccessLog parseLog(final String line, final String pattern) { - HttpLog result; - - // log_format combined '$remote_addr - $remote_user [$time_local] ' - // '"$request" $status $body_bytes_sent ' - // '"$http_referer" "$http_user_agent"'; - String combinedPattern = "^(?[a-zA-F0-9\\\\:\\\\.]+) - (?\\S+) \\[(?