From f8a5152bb72d0a1fc13a77160de8e97f161db247 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 10 Jun 2021 17:05:32 +0200 Subject: [PATCH] Added visitors* metrics. --- .../metrics/http/HttpAccessLogAnalyzer.java | 46 ++++++ .../metrics/http/VisitorCounters.java | 139 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 src/fr/devinsy/statoolinfos/metrics/http/VisitorCounters.java diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java index 4709877..f65961e 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java @@ -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.* = diff --git a/src/fr/devinsy/statoolinfos/metrics/http/VisitorCounters.java b/src/fr/devinsy/statoolinfos/metrics/http/VisitorCounters.java new file mode 100644 index 0000000..b8501ac --- /dev/null +++ b/src/fr/devinsy/statoolinfos/metrics/http/VisitorCounters.java @@ -0,0 +1,139 @@ +/* + * 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.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 +{ + 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); + } +}