Added visitors* metrics.
This commit is contained in:
parent
07b337aac0
commit
f8a5152bb7
2 changed files with 185 additions and 0 deletions
|
@ -54,6 +54,11 @@ public class HttpAccessLogAnalyzer
|
|||
private IpCounters ipv6;
|
||||
private IpCounters botIps;
|
||||
private IpCounters visitorIps;
|
||||
private VisitorCounters visitors;
|
||||
private VisitorCounters ipv4Visitors;
|
||||
private VisitorCounters ipv6Visitors;
|
||||
private VisitorCounters botVisitors;
|
||||
private VisitorCounters humanVisitors;
|
||||
|
||||
/**
|
||||
* Instantiates a new http access log prober.
|
||||
|
@ -69,6 +74,12 @@ public class HttpAccessLogAnalyzer
|
|||
this.ipv6 = new IpCounters();
|
||||
this.botIps = new IpCounters();
|
||||
this.visitorIps = new IpCounters();
|
||||
|
||||
this.visitors = new VisitorCounters();
|
||||
this.ipv4Visitors = new VisitorCounters();
|
||||
this.ipv6Visitors = new VisitorCounters();
|
||||
this.botVisitors = new VisitorCounters();
|
||||
this.humanVisitors = new VisitorCounters();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,6 +104,12 @@ public class HttpAccessLogAnalyzer
|
|||
result.putAll(this.botVisits.getCounters("metrics.http.visits.bots"));
|
||||
result.putAll(this.visitorVisits.getCounters("metrics.http.visits.visitors"));
|
||||
|
||||
result.putAll(this.visitors.getCounters("metrics.http.visitors"));
|
||||
result.putAll(this.ipv4Visitors.getCounters("metrics.http.visitors.ipv4"));
|
||||
result.putAll(this.ipv6Visitors.getCounters("metrics.http.visitors.ipv6"));
|
||||
result.putAll(this.botVisitors.getCounters("metrics.http.visitors.bots"));
|
||||
result.putAll(this.humanVisitors.getCounters("metrics.http.visitors.humans"));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
@ -259,6 +276,35 @@ public class HttpAccessLogAnalyzer
|
|||
this.visitorVisits.storeTimeMarks(year, yearMonth, yearWeek, date);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// metrics.http.visitors.* =
|
||||
this.visitors.put(log.getIp(), log.getUserAgent(), year, yearMonth, yearWeek, date);
|
||||
|
||||
// metrics.http.visitors.ipv4.* =
|
||||
// metrics.http.visitors.ipv6.* =
|
||||
if (log.isIPv4())
|
||||
{
|
||||
this.ipv4Visitors.put(log.getIp(), log.getUserAgent(), year, yearMonth, yearWeek, date);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ipv6Visitors.put(log.getIp(), log.getUserAgent(), year, yearMonth, yearWeek, date);
|
||||
}
|
||||
|
||||
// metrics.http.visitors.bots.*
|
||||
// metrics.http.visitors.humans.*
|
||||
if (log.isBot())
|
||||
{
|
||||
this.botVisitors.put(log.getIp(), log.getUserAgent(), year, yearMonth, yearWeek, date);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.humanVisitors.put(log.getIp(), log.getUserAgent(), year, yearMonth, yearWeek, date);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// metrics.http.countries.XX =
|
||||
|
||||
// metrics.http.errors.* =
|
||||
|
|
139
src/fr/devinsy/statoolinfos/metrics/http/VisitorCounters.java
Normal file
139
src/fr/devinsy/statoolinfos/metrics/http/VisitorCounters.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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.metrics.http;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import fr.devinsy.statoolinfos.metrics.PathCounters;
|
||||
import fr.devinsy.strings.StringSet;
|
||||
|
||||
/**
|
||||
* The Class VisitorCounters.
|
||||
*/
|
||||
public class VisitorCounters extends HashMap<String, StringSet>
|
||||
{
|
||||
private static final long serialVersionUID = -6892042933297886639L;
|
||||
|
||||
/**
|
||||
* Instantiates a new visitor counters.
|
||||
*/
|
||||
public VisitorCounters()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param timeMark
|
||||
* the time mark
|
||||
* @return the string set
|
||||
*/
|
||||
private StringSet get(final String timeMark)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
result = super.get(timeMark);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the counters.
|
||||
*
|
||||
* @return the counters
|
||||
*/
|
||||
public PathCounters getCounters(final String prefix)
|
||||
{
|
||||
PathCounters result;
|
||||
|
||||
result = new PathCounters();
|
||||
|
||||
for (String timeMark : keySet())
|
||||
{
|
||||
StringSet set = get(timeMark);
|
||||
result.inc(set.size(), prefix, timeMark);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the counts of a timeMark.
|
||||
*
|
||||
* @param timeMark
|
||||
* the time mark
|
||||
* @return the counts
|
||||
*/
|
||||
public int getCounts(final String timeMark)
|
||||
{
|
||||
int result;
|
||||
|
||||
StringSet set = get(timeMark);
|
||||
if (set == null)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = set.size();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put.
|
||||
*
|
||||
* @param ip
|
||||
* the ip
|
||||
* @param timeMarks
|
||||
* the time marks
|
||||
*/
|
||||
public void put(final String ip, final UserAgent userAgent, final String... timeMarks)
|
||||
{
|
||||
for (String timeMark : timeMarks)
|
||||
{
|
||||
put(ip, userAgent, timeMark);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put.
|
||||
*
|
||||
* @param timemark
|
||||
* the timemark
|
||||
* @param ip
|
||||
* the ip
|
||||
*/
|
||||
public void put(final String ip, final UserAgent userAgent, final String timemark)
|
||||
{
|
||||
StringSet set = super.get(timemark);
|
||||
if (set == null)
|
||||
{
|
||||
set = new StringSet();
|
||||
put(timemark, set);
|
||||
}
|
||||
|
||||
set.put(ip + userAgent);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue