From 029a9f563d2c62669523bd48070e5eaab199cae8 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 18 Feb 2021 05:33:27 +0100 Subject: [PATCH] Added code for http log analyze. --- .../statoolinfos/core/Configuration.java | 77 ++++- .../htmlize/probes/HttpAccessLogAnalyzer.java | 302 ++++++++++-------- ...gProber.java => HttpErrorLogAnalyzer.java} | 160 +++++----- .../statoolinfos/htmlize/probes/HttpLog.java | 35 +- .../htmlize/probes/HttpLogIterator.java | 2 +- .../htmlize/probes/IpCounters.java | 116 +++++++ .../htmlize/probes/LineIterator.java | 11 +- .../htmlize/probes/PathCounter.java | 27 +- .../htmlize/probes/PathCounters.java | 2 +- .../statoolinfos/htmlize/probes/Prober.java | 86 +++-- .../statoolinfos/htmlize/probes/TimeMark.java | 171 ++++++++++ .../htmlize/probes/TimeMarkUtils.java | 254 +++++++++++++++ .../statoolinfos/htmlize/probes/Visit.java | 248 ++++++++++++++ .../htmlize/probes/VisitCounter.java | 145 +++++++++ .../htmlize/probes/VisitCounters.java | 167 ++++++++++ .../statoolinfos/htmlize/probes/Visits.java | 209 ++++++++++++ 16 files changed, 1736 insertions(+), 276 deletions(-) rename src/fr/devinsy/statoolinfos/htmlize/probes/{HttpErrorLogProber.java => HttpErrorLogAnalyzer.java} (52%) create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/IpCounters.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/TimeMark.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/TimeMarkUtils.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/Visit.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounter.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounters.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/Visits.java diff --git a/src/fr/devinsy/statoolinfos/core/Configuration.java b/src/fr/devinsy/statoolinfos/core/Configuration.java index cfa5157..b8d82a7 100644 --- a/src/fr/devinsy/statoolinfos/core/Configuration.java +++ b/src/fr/devinsy/statoolinfos/core/Configuration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; +import fr.devinsy.strings.StringList; /** * The Class PathProperty. @@ -346,6 +347,80 @@ public class Configuration extends PathPropertyList return result; } + /** + * Gets the probe http access log file. + * + * @return the probe http access log file + */ + public String getProbeHttpAccessLogSource() + { + String result; + + result = get("conf.probe.httpaccesslog.file"); + + // + return result; + } + + /** + * Gets the probe http error log source. + * + * @return the probe http error log source + */ + public String getProbeHttpErrorLogSource() + { + String result; + + result = get("conf.probe.httperrorlog.file"); + + // + return result; + } + + /** + * Gets the probe target. + * + * @return the probe target + */ + public File getProbeTarget() + { + File result; + + String filename = get("conf.probe.target"); + if (StringUtils.isBlank(filename)) + { + result = null; + } + else + { + result = new File(filename); + } + + // + return result; + } + + /** + * Gets the probe types. + * + * @return the probe types + */ + public StringList getProbeTypes() + { + StringList result; + + result = new StringList(); + + String types = get("conf.probe.types"); + if (!StringUtils.isBlank(types)) + { + result.append(types.split("[, ;]")); + } + + // + return result; + } + /** * Checks for valid cache. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java b/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java index 93f73fc..c9215b4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java @@ -18,18 +18,14 @@ */ package fr.devinsy.statoolinfos.htmlize.probes; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,62 +41,42 @@ public class HttpAccessLogAnalyzer public static final String DEFAULT_CHARSET_NAME = "UTF-8"; + private int errorCount; + private PathCounters counters; + private VisitCounters visits; + private IpCounters ips; + private IpCounters ipv4; + private IpCounters ipv6; + /** * Instantiates a new http access log prober. */ - private HttpAccessLogAnalyzer() + public HttpAccessLogAnalyzer() { + this.counters = new PathCounters(); + this.visits = new VisitCounters(); + this.ips = new IpCounters(); + this.ipv4 = new IpCounters(); + this.ipv6 = new IpCounters(); } /** - * Parses the log. + * Gets the counters. * - * @param line - * the line - * @return the http log + * @return the counters */ - public static HttpLog parseLog(final String line) + public PathCounters getCounters() { - HttpLog result; + PathCounters result; - // - // log_format combined '$remote_addr - $remote_user [$time_local] ' - // '"$request" $status $body_bytes_sent ' - // '"$http_referer" "$http_user_agent"'; - String remoteAddressPattern = "(?[a-zA-F0-9\\\\:\\\\.]+)"; - String remoteUserPattern = "(?\\S+)"; - String timePattern = "(?