Refactored metrics package. Added tests.

This commit is contained in:
Christian P. MOMON 2021-02-19 02:16:56 +01:00
parent 029a9f563d
commit 45d797ea06
32 changed files with 325 additions and 182 deletions

View file

@ -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;

View file

@ -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.

View file

@ -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;

View file

@ -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;

View file

@ -1,145 +0,0 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -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)

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.core;
package fr.devinsy.statoolinfos.metrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics;
import java.time.LocalDate;
import java.time.LocalDateTime;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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.

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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.

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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.
*/

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
/**
* The Enum HttpStatusCategory.

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
import java.util.HashMap;
import java.util.regex.Pattern;

View file

@ -16,10 +16,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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;
/**

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
/**
* The Enum UserAgentBrowser.

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
/**
* The Enum UserAgentDevice.

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
public enum UserAgentOS
{

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.metrics.http;
/**
* The Enum UserAgentType.

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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)

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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;
/**

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
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>
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());

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.probes;
package fr.devinsy.statoolinfos.util;
import java.io.BufferedReader;
import java.io.File;

View file

@ -0,0 +1,277 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}