From 45d797ea0686ff44b282e7496203595dc014024f Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 19 Feb 2021 02:16:56 +0100 Subject: [PATCH] Refactored metrics package. Added tests. --- src/fr/devinsy/statoolinfos/core/Service.java | 1 + .../statoolinfos/core/StatoolInfos.java | 2 +- .../statoolinfos/htmlize/ServicePage.java | 2 +- .../htmlize/charts/BarMonthsChartView.java | 2 +- .../htmlize/probes/VisitCounter.java | 145 --------- src/fr/devinsy/statoolinfos/io/JSONFile.java | 4 +- .../{core => metrics}/Metric.java | 2 +- .../probes => metrics}/PathCounter.java | 2 +- .../probes => metrics}/PathCounters.java | 2 +- .../{htmlize/probes => metrics}/Prober.java | 4 +- .../{htmlize/probes => metrics}/TimeMark.java | 2 +- .../probes => metrics}/TimeMarkUtils.java | 2 +- .../http}/HttpAccessLogAnalyzer.java | 4 +- .../http}/HttpAccessLogStat.java | 2 +- .../http}/HttpErrorLogAnalyzer.java | 4 +- .../probes => metrics/http}/HttpLog.java | 3 +- .../http}/HttpLogIterator.java | 4 +- .../probes => metrics/http}/HttpStatus.java | 2 +- .../http}/HttpStatusCategory.java | 2 +- .../http}/HttpStatusTable.java | 2 +- .../probes => metrics/http}/IpCounters.java | 3 +- .../http}/NGinxLogAnalyzer.java | 2 +- .../probes => metrics/http}/UserAgent.java | 2 +- .../http}/UserAgentBrowser.java | 2 +- .../http}/UserAgentDevice.java | 2 +- .../probes => metrics/http}/UserAgentOS.java | 2 +- .../http}/UserAgentType.java | 2 +- .../probes => metrics/http}/Visit.java | 12 +- .../http}/VisitCounters.java | 4 +- .../probes => metrics/http}/Visits.java | 4 +- .../probes => util}/LineIterator.java | 2 +- .../metrics/http/VisitCountersTest.java | 277 ++++++++++++++++++ 32 files changed, 325 insertions(+), 182 deletions(-) delete mode 100644 src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounter.java rename src/fr/devinsy/statoolinfos/{core => metrics}/Metric.java (98%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics}/PathCounter.java (98%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics}/PathCounters.java (99%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics}/Prober.java (97%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics}/TimeMark.java (98%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics}/TimeMarkUtils.java (99%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpAccessLogAnalyzer.java (98%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpAccessLogStat.java (97%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpErrorLogAnalyzer.java (96%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpLog.java (98%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpLogIterator.java (96%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpStatus.java (97%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpStatusCategory.java (98%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/HttpStatusTable.java (99%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/IpCounters.java (96%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/NGinxLogAnalyzer.java (96%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/UserAgent.java (99%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/UserAgentBrowser.java (95%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/UserAgentDevice.java (95%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/UserAgentOS.java (95%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/UserAgentType.java (95%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/Visit.java (96%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/VisitCounters.java (96%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => metrics/http}/Visits.java (97%) rename src/fr/devinsy/statoolinfos/{htmlize/probes => util}/LineIterator.java (98%) create mode 100644 test/fr/devinsy/statoolinfos/metrics/http/VisitCountersTest.java diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index b046088..fda82d0 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -31,6 +31,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.metrics.Metric; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathPropertyList; diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java index 5008520..9a73d4c 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.build.Builder; import fr.devinsy.statoolinfos.crawl.Crawler; import fr.devinsy.statoolinfos.htmlize.Htmlizer; -import fr.devinsy.statoolinfos.htmlize.probes.Prober; +import fr.devinsy.statoolinfos.metrics.Prober; /** * The Class StatoolInfos. diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index abf0cd2..23f3167 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -31,13 +31,13 @@ import fr.devinsy.catgenerator.core.BirdGenerator; import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.checker.PropertyChecker; import fr.devinsy.statoolinfos.checker.PropertyChecks; -import fr.devinsy.statoolinfos.core.Metric; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.htmlize.charts.BarMonthsChartView; import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; +import fr.devinsy.statoolinfos.metrics.Metric; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.DisplayMode; import fr.devinsy.xidyn.data.TagDataManager; diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java index b383429..b644252 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java @@ -25,8 +25,8 @@ import org.apache.commons.codec.digest.DigestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fr.devinsy.statoolinfos.core.Metric; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.Metric; import fr.devinsy.strings.StringList; import fr.devinsy.xidyn.utils.XidynUtils; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounter.java b/src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounter.java deleted file mode 100644 index 0331716..0000000 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounter.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2021 Christian Pierre MOMON - * - * This file is part of StatoolInfos, simple service statistics tool. - * - * StatoolInfos is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * StatoolInfos is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with StatoolInfos. If not, see . - */ -package fr.devinsy.statoolinfos.htmlize.probes; - -import java.util.regex.Pattern; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The Class PathCounter. - */ -public class VisitCounter -{ - private static Logger logger = LoggerFactory.getLogger(VisitCounter.class); - - private String path; - private String timeMark; - private long counter; - - /** - * Instantiates a new path counter. - * - * @param path - * the path - * @param timeMark - * the time mark - */ - public VisitCounter(final String path, final String timeMark) - { - this.path = path; - this.timeMark = timeMark; - this.counter = 0; - } - - public long getCounter() - { - return this.counter; - } - - public String getPath() - { - return this.path; - } - - public String getTimeMark() - { - return this.timeMark; - } - - /** - * Inc. - */ - public void inc() - { - this.counter += 1; - } - - public void inc(final long value) - { - this.counter += value; - } - - /** - * Checks if is date. - * - * @return true, if is date - */ - public boolean isDate() - { - boolean result; - - Pattern pattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$"); - - result = (pattern.matcher(this.timeMark).matches()); - - // - return result; - } - - /** - * Checks if is year mark. - * - * @return true, if is year mark - */ - public boolean isYearMark() - { - boolean result; - - Pattern pattern = Pattern.compile("^\\d{4}$"); - - result = (pattern.matcher(this.timeMark).matches()); - - // - return result; - } - - /** - * Checks if is year week. - * - * @return true, if is year week - */ - public boolean isYearWeek() - { - boolean result; - - Pattern pattern = Pattern.compile("^\\d{4}W\\d{2}$"); - - result = (pattern.matcher(this.timeMark).matches()); - - // - return result; - } - - public void setCounter(final long counter) - { - this.counter = counter; - } - - public void setPath(final String path) - { - this.path = path; - } - - public void setTimeMark(final String timeMark) - { - this.timeMark = timeMark; - } -} diff --git a/src/fr/devinsy/statoolinfos/io/JSONFile.java b/src/fr/devinsy/statoolinfos/io/JSONFile.java index ffa9249..154c9c0 100644 --- a/src/fr/devinsy/statoolinfos/io/JSONFile.java +++ b/src/fr/devinsy/statoolinfos/io/JSONFile.java @@ -236,8 +236,8 @@ public class JSONFile /** * To JSON. * - * @param properties - * the properties + * @param service + * the service * @return the string list */ public static StringList toJSON(final Service service) diff --git a/src/fr/devinsy/statoolinfos/core/Metric.java b/src/fr/devinsy/statoolinfos/metrics/Metric.java similarity index 98% rename from src/fr/devinsy/statoolinfos/core/Metric.java rename to src/fr/devinsy/statoolinfos/metrics/Metric.java index 5da95fc..f5178ea 100644 --- a/src/fr/devinsy/statoolinfos/core/Metric.java +++ b/src/fr/devinsy/statoolinfos/metrics/Metric.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.core; +package fr.devinsy.statoolinfos.metrics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/PathCounter.java b/src/fr/devinsy/statoolinfos/metrics/PathCounter.java similarity index 98% rename from src/fr/devinsy/statoolinfos/htmlize/probes/PathCounter.java rename to src/fr/devinsy/statoolinfos/metrics/PathCounter.java index 36d4405..7959a05 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/PathCounter.java +++ b/src/fr/devinsy/statoolinfos/metrics/PathCounter.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/PathCounters.java b/src/fr/devinsy/statoolinfos/metrics/PathCounters.java similarity index 99% rename from src/fr/devinsy/statoolinfos/htmlize/probes/PathCounters.java rename to src/fr/devinsy/statoolinfos/metrics/PathCounters.java index 3d12bb2..794167a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/PathCounters.java +++ b/src/fr/devinsy/statoolinfos/metrics/PathCounters.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics; import java.time.LocalDate; import java.time.format.DateTimeFormatter; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/Prober.java b/src/fr/devinsy/statoolinfos/metrics/Prober.java similarity index 97% rename from src/fr/devinsy/statoolinfos/htmlize/probes/Prober.java rename to src/fr/devinsy/statoolinfos/metrics/Prober.java index f261749..36452c7 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/Prober.java +++ b/src/fr/devinsy/statoolinfos/metrics/Prober.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics; import java.io.File; import java.io.FileNotFoundException; @@ -29,6 +29,8 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Factory; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer; +import fr.devinsy.statoolinfos.metrics.http.HttpErrorLogAnalyzer; import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/TimeMark.java b/src/fr/devinsy/statoolinfos/metrics/TimeMark.java similarity index 98% rename from src/fr/devinsy/statoolinfos/htmlize/probes/TimeMark.java rename to src/fr/devinsy/statoolinfos/metrics/TimeMark.java index 842b9b4..8bb989c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/TimeMark.java +++ b/src/fr/devinsy/statoolinfos/metrics/TimeMark.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/TimeMarkUtils.java b/src/fr/devinsy/statoolinfos/metrics/TimeMarkUtils.java similarity index 99% rename from src/fr/devinsy/statoolinfos/htmlize/probes/TimeMarkUtils.java rename to src/fr/devinsy/statoolinfos/metrics/TimeMarkUtils.java index 9d10c2b..51c3ba3 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/TimeMarkUtils.java +++ b/src/fr/devinsy/statoolinfos/metrics/TimeMarkUtils.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics; import java.time.LocalDate; import java.time.LocalDateTime; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java similarity index 98% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java index c9215b4..0f801a3 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.io.File; import java.io.IOException; @@ -31,6 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.PathCounters; +import fr.devinsy.statoolinfos.util.LineIterator; /** * The Class HttpAccessLogProber. diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogStat.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogStat.java similarity index 97% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogStat.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogStat.java index 36d9123..f6654df 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpAccessLogStat.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogStat.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpErrorLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpErrorLogAnalyzer.java similarity index 96% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpErrorLogAnalyzer.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpErrorLogAnalyzer.java index 0208a9f..0089593 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpErrorLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpErrorLogAnalyzer.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.io.File; import java.io.IOException; @@ -29,6 +29,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.PathCounters; +import fr.devinsy.statoolinfos.util.LineIterator; /** * The Class HttpErrorLogAnalyzer. diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpLog.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpLog.java similarity index 98% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpLog.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpLog.java index 52c73d9..ea738c0 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpLog.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpLog.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -26,6 +26,7 @@ import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.metrics.TimeMarkUtils; import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpLogIterator.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpLogIterator.java similarity index 96% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpLogIterator.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpLogIterator.java index b78b656..4a919a2 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpLogIterator.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpLogIterator.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.io.File; import java.io.IOException; @@ -24,6 +24,8 @@ import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.util.LineIterator; + /** * The Class HttpLogIterator. */ diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatus.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java similarity index 97% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatus.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java index ca0aed7..db6bb4b 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatus.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatusCategory.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java similarity index 98% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatusCategory.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java index 72de85f..454db65 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatusCategory.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; /** * The Enum HttpStatusCategory. diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatusTable.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusTable.java similarity index 99% rename from src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatusTable.java rename to src/fr/devinsy/statoolinfos/metrics/http/HttpStatusTable.java index 2a61b44..020242c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/HttpStatusTable.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusTable.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.util.HashMap; import java.util.regex.Pattern; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/IpCounters.java b/src/fr/devinsy/statoolinfos/metrics/http/IpCounters.java similarity index 96% rename from src/fr/devinsy/statoolinfos/htmlize/probes/IpCounters.java rename to src/fr/devinsy/statoolinfos/metrics/http/IpCounters.java index 9516eff..af99ed9 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/IpCounters.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/IpCounters.java @@ -16,10 +16,11 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.util.HashMap; +import fr.devinsy.statoolinfos.metrics.PathCounters; import fr.devinsy.strings.StringSet; /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/NGinxLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/NGinxLogAnalyzer.java similarity index 96% rename from src/fr/devinsy/statoolinfos/htmlize/probes/NGinxLogAnalyzer.java rename to src/fr/devinsy/statoolinfos/metrics/http/NGinxLogAnalyzer.java index ac2a02f..978b1cf 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/NGinxLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/NGinxLogAnalyzer.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgent.java b/src/fr/devinsy/statoolinfos/metrics/http/UserAgent.java similarity index 99% rename from src/fr/devinsy/statoolinfos/htmlize/probes/UserAgent.java rename to src/fr/devinsy/statoolinfos/metrics/http/UserAgent.java index e37ccd1..01f4443 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgent.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/UserAgent.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentBrowser.java b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentBrowser.java similarity index 95% rename from src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentBrowser.java rename to src/fr/devinsy/statoolinfos/metrics/http/UserAgentBrowser.java index 5fa3ddd..77b197f 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentBrowser.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentBrowser.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; /** * The Enum UserAgentBrowser. diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentDevice.java b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentDevice.java similarity index 95% rename from src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentDevice.java rename to src/fr/devinsy/statoolinfos/metrics/http/UserAgentDevice.java index 2536f78..4d33362 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentDevice.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentDevice.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; /** * The Enum UserAgentDevice. diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentOS.java b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentOS.java similarity index 95% rename from src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentOS.java rename to src/fr/devinsy/statoolinfos/metrics/http/UserAgentOS.java index a7d85c0..2f74d98 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentOS.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentOS.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; public enum UserAgentOS { diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentType.java b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentType.java similarity index 95% rename from src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentType.java rename to src/fr/devinsy/statoolinfos/metrics/http/UserAgentType.java index 6de89d8..b56ff1f 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/UserAgentType.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/UserAgentType.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; /** * The Enum UserAgentType. diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/Visit.java b/src/fr/devinsy/statoolinfos/metrics/http/Visit.java similarity index 96% rename from src/fr/devinsy/statoolinfos/htmlize/probes/Visit.java rename to src/fr/devinsy/statoolinfos/metrics/http/Visit.java index a93db69..46dd995 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/Visit.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/Visit.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.time.LocalDate; import java.time.LocalDateTime; @@ -175,8 +175,8 @@ public class Visit /** * Checks if is matching. * - * @param timemark - * the timemark + * @param yearMonth + * the year month * @return true, if is matching */ public boolean isMatching(final YearMonth yearMonth) @@ -209,10 +209,8 @@ public class Visit /** * Checks if is matching. * - * @param year - * the year - * @param week - * the week + * @param yearWeek + * the year week * @return true, if is matching */ public boolean isMatching(final YearWeek yearWeek) diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounters.java b/src/fr/devinsy/statoolinfos/metrics/http/VisitCounters.java similarity index 96% rename from src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounters.java rename to src/fr/devinsy/statoolinfos/metrics/http/VisitCounters.java index 46205aa..a446753 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/VisitCounters.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/VisitCounters.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.time.LocalDate; import java.time.YearMonth; @@ -26,6 +26,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.threeten.extra.YearWeek; +import fr.devinsy.statoolinfos.metrics.PathCounters; +import fr.devinsy.statoolinfos.metrics.TimeMarkUtils; import fr.devinsy.strings.StringSet; /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/Visits.java b/src/fr/devinsy/statoolinfos/metrics/http/Visits.java similarity index 97% rename from src/fr/devinsy/statoolinfos/htmlize/probes/Visits.java rename to src/fr/devinsy/statoolinfos/metrics/http/Visits.java index 2f9744f..b181e5e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/Visits.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/Visits.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.metrics.http; import java.time.LocalDate; import java.time.LocalDateTime; @@ -86,7 +86,7 @@ public class Visits extends ArrayList visit.setEnd(date); if (index + 1 < size()) { - Visit next = get(index - 1); + Visit next = get(index + 1); if (next.getStart().isBefore(visit.getEnd().plusMinutes(BORDER_MINUTES))) { visit.setEnd(next.getEnd()); diff --git a/src/fr/devinsy/statoolinfos/htmlize/probes/LineIterator.java b/src/fr/devinsy/statoolinfos/util/LineIterator.java similarity index 98% rename from src/fr/devinsy/statoolinfos/htmlize/probes/LineIterator.java rename to src/fr/devinsy/statoolinfos/util/LineIterator.java index 360bc00..45fcc46 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/probes/LineIterator.java +++ b/src/fr/devinsy/statoolinfos/util/LineIterator.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.htmlize.probes; +package fr.devinsy.statoolinfos.util; import java.io.BufferedReader; import java.io.File; diff --git a/test/fr/devinsy/statoolinfos/metrics/http/VisitCountersTest.java b/test/fr/devinsy/statoolinfos/metrics/http/VisitCountersTest.java new file mode 100644 index 0000000..bae70a0 --- /dev/null +++ b/test/fr/devinsy/statoolinfos/metrics/http/VisitCountersTest.java @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple key value database. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.metrics.http; + +import java.time.LocalDateTime; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.PathCounter; +import fr.devinsy.statoolinfos.metrics.PathCounters; + +/** + * The Class VisitCountersTest. + */ +public class VisitCountersTest +{ + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(VisitCountersTest.class); + + /** + * Test 01. + * + * @throws Exception + * the exception + */ + @Test + public void test01() throws Exception + { + VisitCounters visitCounters = new VisitCounters(); + + // + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setTime(LocalDateTime.of(2020, 10, 20, 23, 0)); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + visitCounters.putVisit(log); + + // + visitCounters.storeTimeMarks("2020-10"); + PathCounters counters = visitCounters.getCounters("metrics.aaa"); + + for (PathCounter counter : counters.values()) + { + logger.info(counter.getPath() + " " + counter.getTimeMark() + " " + counter.getCounter()); + } + + Assert.assertEquals(1, counters.size()); + Assert.assertEquals(1, counters.get("metrics.aaa", "2020-10").getCounter()); + } + + /** + * Test 02. + * + * @throws Exception + * the exception + */ + @Test + public void test02() throws Exception + { + VisitCounters visitCounters = new VisitCounters(); + + // + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 0)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 20)); + visitCounters.putVisit(log); + } + + // + visitCounters.storeTimeMarks("2020-10"); + PathCounters counters = visitCounters.getCounters("metrics.aaa"); + + for (PathCounter counter : counters.values()) + { + logger.info(counter.getPath() + " " + counter.getTimeMark() + " " + counter.getCounter()); + } + + Assert.assertEquals(1, counters.size()); + Assert.assertEquals(1, counters.get("metrics.aaa", "2020-10").getCounter()); + } + + /** + * Test 03. + * + * @throws Exception + * the exception + */ + @Test + public void test03() throws Exception + { + VisitCounters visitCounters = new VisitCounters(); + + // + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 0)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 20)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 55)); + visitCounters.putVisit(log); + } + + // + visitCounters.storeTimeMarks("2020-10"); + PathCounters counters = visitCounters.getCounters("metrics.aaa"); + + for (PathCounter counter : counters.values()) + { + logger.info(counter.getPath() + " " + counter.getTimeMark() + " " + counter.getCounter()); + } + + Assert.assertEquals(1, counters.size()); + Assert.assertEquals(2, counters.get("metrics.aaa", "2020-10").getCounter()); + } + + /** + * Test 04. + * + * @throws Exception + * the exception + */ + @Test + public void test04() throws Exception + { + VisitCounters visitCounters = new VisitCounters(); + + // + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 0)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 55)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 20)); + visitCounters.putVisit(log); + } + + // + visitCounters.storeTimeMarks("2020-10"); + PathCounters counters = visitCounters.getCounters("metrics.aaa"); + + for (PathCounter counter : counters.values()) + { + logger.info(counter.getPath() + " " + counter.getTimeMark() + " " + counter.getCounter()); + } + + Assert.assertEquals(1, counters.size()); + Assert.assertEquals(2, counters.get("metrics.aaa", "2020-10").getCounter()); + } + + /** + * Test 05. + * + * @throws Exception + * the exception + */ + @Test + public void test05() throws Exception + { + VisitCounters visitCounters = new VisitCounters(); + + // + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 0)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 35)); + visitCounters.putVisit(log); + } + { + HttpLog log = new HttpLog(); + log.setRemoteAddress("192.168.1.1"); + log.setUserAgent(new UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36")); + log.setTime(LocalDateTime.of(2020, 10, 20, 12, 20)); + visitCounters.putVisit(log); + } + + // + visitCounters.storeTimeMarks("2020-10"); + PathCounters counters = visitCounters.getCounters("metrics.aaa"); + + for (PathCounter counter : counters.values()) + { + logger.info(counter.getPath() + " " + counter.getTimeMark() + " " + counter.getCounter()); + } + + Assert.assertEquals(1, counters.size()); + Assert.assertEquals(1, counters.get("metrics.aaa", "2020-10").getCounter()); + } + + /** + * After class. + * + * @throws StatoolInfosException + * the Juga exception + */ + @AfterClass + public static void afterClass() throws StatoolInfosException + { + } + + /** + * Before class. + * + * @throws StatoolInfosException + * the Juga exception + */ + @BeforeClass + public static void beforeClass() throws StatoolInfosException + { + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.DEBUG); + } +}