From 152af0d74ac6154c1b76675f7c094a92aa1f0e67 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 22 May 2021 01:11:04 +0200 Subject: [PATCH] Improved page metric computation in probing. --- .../metrics/http/HttpAccessLogAnalyzer.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java index 1db92a8..fc85bb5 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java @@ -169,7 +169,7 @@ public class HttpAccessLogAnalyzer } // metrics.http.pages.* = - if (StringUtils.endsWithAny(log.getRequest(), ".html", ".htm", ".xhtml", ".cgi", "/")) + if ((isPage(log.getRequest())) && (log.getStatus().getCategory() == HttpStatusCategory.SUCCESS)) { this.counters.inc("metrics.http.pages", year, yearMonth, yearWeek, date); } @@ -214,6 +214,45 @@ public class HttpAccessLogAnalyzer } } + /** + * Checks if is page. + * + * @param request + * the request + * @return true, if is page + */ + public static boolean isPage(final String request) + { + boolean result; + + if (StringUtils.isBlank(request)) + { + result = false; + } + else + { + Pattern PAGE_PATTERN = Pattern.compile("^.* (?/[^ \\?]*)(\\?.*| .*)?$"); + + Matcher matcher = PAGE_PATTERN.matcher(request); + if (matcher.find()) + { + String path = matcher.group("path").toLowerCase(); + + result = path.matches("^.*(/|/[^/]*\\.html|/[^/]*\\.htm|/[^/]*\\.xhtml|/[^/]*\\.cgi|/[^/]*\\.php|/[^/\\.]*[a-z0-9])$"); + + // System.out.println(result + " [" + path + "] [" + request + + // "]"); + } + else + { + result = false; + } + } + + // + return result; + } + /** * Parses the log. *