From fe72332ff33280a9bf07d429e56e82ba18ec049d Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 11 Jun 2021 01:40:42 +0200 Subject: [PATCH] Improved Uptime feature. --- .../htmlize/FederationMetricSummaryPage.java | 4 +- .../htmlize/FederationMetricWebPage.java | 12 ++ .../OrganizationMetricSummaryPage.java | 2 +- .../htmlize/OrganizationMetricWebPage.java | 12 ++ .../htmlize/ServiceMetricSummaryPage.java | 2 +- .../htmlize/ServiceMetricWebPage.java | 12 ++ .../statoolinfos/htmlize/UptimeView.java | 46 +++++-- .../htmlize/serviceMetricSummaryView.xhtml | 2 +- .../htmlize/serviceMetricWebView.xhtml | 11 ++ .../devinsy/statoolinfos/uptime/Uptime.java | 2 +- .../statoolinfos/uptime/UptimeComparator.java | 126 ++++++++++++++++++ .../statoolinfos/uptime/UptimeJournal.java | 2 +- .../uptime/UptimeJournalFile.java | 2 +- .../devinsy/statoolinfos/uptime/Uptimes.java | 61 ++++++++- 14 files changed, 274 insertions(+), 22 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/uptime/UptimeComparator.java diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationMetricSummaryPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationMetricSummaryPage.java index 4bf31a5..d83c408 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationMetricSummaryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationMetricSummaryPage.java @@ -61,8 +61,6 @@ public class FederationMetricSummaryPage */ public static void build(final File htmlizeDirectory, final Federation federation, final ViewMenu view, final PeriodMenu period) throws StatoolInfosException, IOException { - String result; - try { TagDataManager data = new TagDataManager(); @@ -71,7 +69,7 @@ public class FederationMetricSummaryPage data.setContent("metricMenuView", FederationMetricMenuView.htmlize(federation, TypeMenu.SUMMARY, view, period)); FederationMetricHtmlizer.htmlize(data, "http.hits.visitors", federation, view, period, "metrics.http.hits.visitors", ChartColor.GREEN); - FederationMetricHtmlizer.htmlize(data, "http.ip.visitors", federation, view, period, "metrics.http.ip.visitors", ChartColor.GREEN); + FederationMetricHtmlizer.htmlize(data, "http.visitors.humans", federation, view, period, "metrics.http.visitors.humans", ChartColor.GREEN); FederationMetricHtmlizer.htmlize(data, "http.visits.visitors", federation, view, period, "metrics.http.visits.visitors", ChartColor.GREEN); // diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationMetricWebPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationMetricWebPage.java index 6f9d008..9b78248 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationMetricWebPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationMetricWebPage.java @@ -95,6 +95,18 @@ public class FederationMetricWebPage FederationMetricHtmlizer.htmlize(data, "http.ip.ipv4", federation, view, period, "metrics.http.ip.ipv4", ChartColor.YELLOW); FederationMetricHtmlizer.htmlize(data, "http.ip.ipv6", federation, view, period, "metrics.http.ip.ipv6", ChartColor.GREEN); + FederationMetricHtmlizer.htmlize(data, "http.visitors", federation, view, period, "metrics.http.visitors", ChartColor.BLUE); + + FederationMetricHtmlizer.htmlize(data, "http.visitors-humansbots", federation, view, period, "http.visitors (humans + bots)", "metrics.http.visitors.humans", ChartColor.GREEN, + "metrics.http.visitors.bots", ChartColor.YELLOW); + FederationMetricHtmlizer.htmlize(data, "http.visitors.humans", federation, view, period, "metrics.http.visitors.humans", ChartColor.GREEN); + FederationMetricHtmlizer.htmlize(data, "http.visitors.bots", federation, view, period, "metrics.http.visitors.bots", ChartColor.YELLOW); + + FederationMetricHtmlizer.htmlize(data, "http.visitors-ipv4ipv6", federation, view, period, "http.visitors (ipv4 + ipv6)", "metrics.http.visitors.ipv4", ChartColor.YELLOW, + "metrics.http.visitors.ipv6", ChartColor.GREEN); + FederationMetricHtmlizer.htmlize(data, "http.visitors.ipv4", federation, view, period, "metrics.http.visitors.ipv4", ChartColor.YELLOW); + FederationMetricHtmlizer.htmlize(data, "http.visitors.ipv6", federation, view, period, "metrics.http.visitors.ipv6", ChartColor.GREEN); + FederationMetricHtmlizer.htmlize(data, "http.visits", federation, view, period, "metrics.http.visits", ChartColor.BLUE); FederationMetricHtmlizer.htmlize(data, "http.visits-visitorsbots", federation, view, period, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java index 59b4463..907fefe 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java @@ -70,7 +70,7 @@ public class OrganizationMetricSummaryPage data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, TypeMenu.SUMMARY, view, period)); OrganizationMetricHtmlizer.htmlize(data, "http.hits.visitors", organization, view, period, "metrics.http.hits.visitors", ChartColor.GREEN); - OrganizationMetricHtmlizer.htmlize(data, "http.ip.visitors", organization, view, period, "metrics.http.ip.visitors", ChartColor.GREEN); + OrganizationMetricHtmlizer.htmlize(data, "http.visitors.humans", organization, view, period, "metrics.http.visitors.humans", ChartColor.GREEN); OrganizationMetricHtmlizer.htmlize(data, "http.visits.visitors", organization, view, period, "metrics.http.visits.visitors", ChartColor.GREEN); // diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java index ec368f4..96d684a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java @@ -102,6 +102,18 @@ public class OrganizationMetricWebPage OrganizationMetricHtmlizer.htmlize(data, "http.ip.ipv4", organization, view, period, "metrics.http.ip.ipv4", ChartColor.YELLOW); OrganizationMetricHtmlizer.htmlize(data, "http.ip.ipv6", organization, view, period, "metrics.http.ip.ipv6", ChartColor.GREEN); + OrganizationMetricHtmlizer.htmlize(data, "http.visitors", organization, view, period, "metrics.http.visitors", ChartColor.BLUE); + + OrganizationMetricHtmlizer.htmlize(data, "http.visitors-humansbots", organization, view, period, "http.visitors (humans + bots)", "metrics.http.visitors.humans", ChartColor.GREEN, + "metrics.http.visitors.bots", ChartColor.YELLOW); + OrganizationMetricHtmlizer.htmlize(data, "http.visitors.humans", organization, view, period, "metrics.http.visitors.humans", ChartColor.GREEN); + OrganizationMetricHtmlizer.htmlize(data, "http.visitors.bots", organization, view, period, "metrics.http.visitors.bots", ChartColor.YELLOW); + + OrganizationMetricHtmlizer.htmlize(data, "http.visitors-ipv4ipv6", organization, view, period, "http.visitors (ipv4 + ipv6)", "metrics.http.visitors.ipv4", ChartColor.YELLOW, + "metrics.http.visitors.ipv6", ChartColor.GREEN); + OrganizationMetricHtmlizer.htmlize(data, "http.visitors.ipv4", organization, view, period, "metrics.http.visitors.ipv4", ChartColor.YELLOW); + OrganizationMetricHtmlizer.htmlize(data, "http.visitors.ipv6", organization, view, period, "metrics.http.visitors.ipv6", ChartColor.GREEN); + OrganizationMetricHtmlizer.htmlize(data, "http.visits", organization, view, period, "metrics.http.visits", ChartColor.BLUE); OrganizationMetricHtmlizer.htmlize(data, "http.visits-visitorsbots", organization, view, period, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java index 0800acf..9da751f 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java @@ -70,7 +70,7 @@ public class ServiceMetricSummaryPage data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, TypeMenu.SUMMARY, view, period)); ServiceMetricHtmlizer.htmlize(data, "http.hits.visitors", service, view, period, "metrics.http.hits.visitors", ChartColor.GREEN); - ServiceMetricHtmlizer.htmlize(data, "http.ip.visitors", service, view, period, "metrics.http.ip.visitors", ChartColor.GREEN); + ServiceMetricHtmlizer.htmlize(data, "http.visitors.humans", service, view, period, "metrics.http.visitors.humans", ChartColor.GREEN); ServiceMetricHtmlizer.htmlize(data, "http.visits.visitors", service, view, period, "metrics.http.visits.visitors", ChartColor.GREEN); // diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java index 3cc1e51..e148898 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java @@ -101,6 +101,18 @@ public class ServiceMetricWebPage ServiceMetricHtmlizer.htmlize(data, "http.ip.ipv4", service, view, period, "metrics.http.ip.ipv4", ChartColor.YELLOW); ServiceMetricHtmlizer.htmlize(data, "http.ip.ipv6", service, view, period, "metrics.http.ip.ipv6", ChartColor.GREEN); + ServiceMetricHtmlizer.htmlize(data, "http.visitors", service, view, period, "metrics.http.ip", ChartColor.BLUE); + + ServiceMetricHtmlizer.htmlizeData(data, "http.visitors-humansbots", service, view, period, "http.visitors (humans + bots)", "metrics.http.visitors.humans", ChartColor.GREEN, + "metrics.http.visitors.bots", ChartColor.YELLOW); + ServiceMetricHtmlizer.htmlize(data, "http.visitors.humans", service, view, period, "metrics.http.visitors.humans", ChartColor.GREEN); + ServiceMetricHtmlizer.htmlize(data, "http.visitors.bots", service, view, period, "metrics.http.visitors.bots", ChartColor.YELLOW); + + ServiceMetricHtmlizer.htmlizeData(data, "http.visitors-ipv4ipv6", service, view, period, "http.visitors (ipv4 + ipv6)", "metrics.http.visitors.ipv4", ChartColor.YELLOW, + "metrics.http.visitors.ipv6", ChartColor.GREEN); + ServiceMetricHtmlizer.htmlize(data, "http.visitors.ipv4", service, view, period, "metrics.http.visitors.ipv4", ChartColor.YELLOW); + ServiceMetricHtmlizer.htmlize(data, "http.visitors.ipv6", service, view, period, "metrics.http.visitors.ipv6", ChartColor.GREEN); + ServiceMetricHtmlizer.htmlize(data, "http.visits", service, view, period, "metrics.http.visits", ChartColor.BLUE); ServiceMetricHtmlizer.htmlizeData(data, "http.visits-visitorsbots", service, view, period, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, diff --git a/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java index e54fa3b..abd01d4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java @@ -32,6 +32,7 @@ import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.uptime.UptimeJournal; import fr.devinsy.statoolinfos.uptime.UptimeStat; +import fr.devinsy.strings.StringList; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -63,6 +64,26 @@ public class UptimeView { TagDataManager data = new TagDataManager(); + LocalDate now = LocalDate.now(); + for (int dayCount = 0; dayCount < 22; dayCount++) + { + LocalDate date = now.minusDays(dayCount); + + // + data.setContent("lineHeader-" + dayCount, StringUtils.capitalize(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.FRENCH)).substring(0, 2))); + data.setAttribute("lineHeader-" + dayCount, "title", date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); + + DayOfWeek weekDay = date.getDayOfWeek(); + if ((weekDay == DayOfWeek.SUNDAY) || (weekDay == DayOfWeek.SATURDAY)) + { + data.setAttribute("lineHeader-" + dayCount, "style", "background-color: gainsboro;"); + } + else + { + data.setAttribute("lineHeader-" + dayCount, "style", "background-color: #ececec;"); + } + } + int index = 0; for (Service service : services.sortByName()) { @@ -76,31 +97,34 @@ public class UptimeView data.setEscapedContent("line", index, "lineOrganizationValue", service.getOrganization().getName()); // - LocalDate now = LocalDate.now(); for (int dayCount = 0; dayCount < 22; dayCount++) { LocalDate date = now.minusDays(dayCount); // - data.setContent("lineHeader-" + dayCount, StringUtils.capitalize(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.FRENCH)).substring(0, 2))); - data.setAttribute("lineHeader-" + dayCount, "title", date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); - DayOfWeek weekDay = date.getDayOfWeek(); if ((weekDay == DayOfWeek.SUNDAY) || (weekDay == DayOfWeek.SATURDAY)) { - data.setAttribute("lineHeader-" + dayCount, "style", "background-color: gainsboro;"); data.setAttribute("line", index, "uptime-" + dayCount, "style", "background-color: gainsboro;"); } - else - { - data.setAttribute("lineHeader-" + dayCount, "style", "background-color: #ececec;"); - } // UptimeStat stat = journal.getStat(service.getWebsiteURL(), date); + StringList lines = new StringList(); + String header = String.format("%d ok + %d err", stat.getOkCount(), stat.getErrorCount()); + lines.add(header); + header = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); + lines.add(header); + if (stat.getErrorCount() > 0) + { + lines.addAll(journal.getUptimes(service.getWebsiteURL(), date).toTimeList()); + } + data.setAttribute("line", index, "statusImg-" + dayCount, "src", "status-" + stat.getStatus().toString().toLowerCase() + ".png"); - String title = String.format("%d ok + %d err %s", stat.getOkCount(), stat.getErrorCount(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); - data.setAttribute("line", index, "statusImg-" + dayCount, "title", title); + // String title = String.format("%d ok + %d err %s", + // stat.getOkCount(), stat.getErrorCount(), + // date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); + data.setAttribute("line", index, "statusImg-" + dayCount, "title", lines.toStringSeparatedBy(" ")); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml index 2ddd6a3..b8c4601 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml @@ -16,7 +16,7 @@
-
+
diff --git a/src/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml index b77834a..f6f277e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml @@ -46,6 +46,17 @@
+

http.visitors

+
+ +
+
+
+
+
+
+
+

http.visits

diff --git a/src/fr/devinsy/statoolinfos/uptime/Uptime.java b/src/fr/devinsy/statoolinfos/uptime/Uptime.java index 6571373..69a91d3 100644 --- a/src/fr/devinsy/statoolinfos/uptime/Uptime.java +++ b/src/fr/devinsy/statoolinfos/uptime/Uptime.java @@ -77,7 +77,7 @@ public class Uptime return this.code; } - public LocalDateTime getDatetime() + public LocalDateTime getDateTime() { return this.datetime; } diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeComparator.java b/src/fr/devinsy/statoolinfos/uptime/UptimeComparator.java new file mode 100644 index 0000000..6be5f4b --- /dev/null +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeComparator.java @@ -0,0 +1,126 @@ +/* + * 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.uptime; + +import java.time.LocalDateTime; +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class UptimeComparator. + */ +public class UptimeComparator implements Comparator +{ + public enum Sorting + { + DATETIME + } + + private Sorting sorting; + + /** + * Instantiates a new uptime comparator. + * + * @param sorting + * the sorting + */ + public UptimeComparator(final Sorting sorting) + { + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final Uptime alpha, final Uptime bravo) + { + int result; + + result = compare(alpha, bravo, this.sorting); + + // + return result; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @param sorting + * the sorting + * @return the int + */ + public static int compare(final Uptime alpha, final Uptime bravo, final Sorting sorting) + { + int result; + + if (sorting == null) + { + result = 0; + } + else + { + switch (sorting) + { + default: + case DATETIME: + result = CompareUtils.compare(getDateTime(alpha), getDateTime(bravo)); + break; + } + } + + // + return result; + } + + /** + * Gets the datetime. + * + * @param source + * the source + * @return the datetime + */ + public static LocalDateTime getDateTime(final Uptime source) + { + LocalDateTime result; + + if (source == null) + { + result = null; + } + else + { + result = source.getDateTime(); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java index c6ac2b1..87d4654 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java @@ -120,7 +120,7 @@ public class UptimeJournal result.incError(); } - if ((older == null) || (older.getDatetime().isAfter(uptime.getDatetime()))) + if ((older == null) || (uptime.getDateTime().isAfter(older.getDateTime()))) { older = uptime; } diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java index d4e50bb..7a76a58 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java @@ -221,7 +221,7 @@ public class UptimeJournalFile { for (Uptime uptime : journal.getUptimesAll()) { - String line = String.format("%s %s %d %s", uptime.getDatetime().toString(), uptime.getStatus(), uptime.getCode(), uptime.getUrl()); + String line = String.format("%s %s %d %s", uptime.getDateTime().toString(), uptime.getStatus(), uptime.getCode(), uptime.getUrl()); out.write(line); out.write("\n"); } diff --git a/src/fr/devinsy/statoolinfos/uptime/Uptimes.java b/src/fr/devinsy/statoolinfos/uptime/Uptimes.java index 2533e98..cd730f9 100644 --- a/src/fr/devinsy/statoolinfos/uptime/Uptimes.java +++ b/src/fr/devinsy/statoolinfos/uptime/Uptimes.java @@ -19,12 +19,15 @@ package fr.devinsy.statoolinfos.uptime; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Iterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; + /** * The Class Uptimes. */ @@ -76,7 +79,7 @@ public class Uptimes extends ArrayList for (Uptime uptime : this) { - if (uptime.getDatetime().toLocalDate().isEqual(date)) + if (uptime.getDateTime().toLocalDate().isEqual(date)) { result.add(uptime); } @@ -102,10 +105,64 @@ public class Uptimes extends ArrayList { Uptime uptime = iterator.next(); - if (uptime.getDatetime().toLocalDate().isBefore(limit)) + if (uptime.getDateTime().toLocalDate().isBefore(limit)) { iterator.remove(); } } } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the files + */ + public Uptimes sort(final UptimeComparator.Sorting sorting) + { + Uptimes result; + + sort(new UptimeComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by date time. + * + * @return the uptimes + */ + public Uptimes sortByDateTime() + { + Uptimes result; + + result = sort(UptimeComparator.Sorting.DATETIME); + + // + return result; + } + + /** + * To time list. + * + * @return the string list + */ + public StringList toTimeList() + { + StringList result; + + result = new StringList(); + for (Uptime uptime : this.sortByDateTime()) + { + String line = String.format("%s %03d %s", uptime.getDateTime().format(DateTimeFormatter.ofPattern("hh:mm")), uptime.getCode(), uptime.getStatus().name()); + result.append(line); + } + + // + return result; + } }