Improved Uptime feature.
This commit is contained in:
parent
f8a5152bb7
commit
fe72332ff3
14 changed files with 274 additions and 22 deletions
|
@ -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
|
public static void build(final File htmlizeDirectory, final Federation federation, final ViewMenu view, final PeriodMenu period) throws StatoolInfosException, IOException
|
||||||
{
|
{
|
||||||
String result;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TagDataManager data = new TagDataManager();
|
TagDataManager data = new TagDataManager();
|
||||||
|
@ -71,7 +69,7 @@ public class FederationMetricSummaryPage
|
||||||
data.setContent("metricMenuView", FederationMetricMenuView.htmlize(federation, TypeMenu.SUMMARY, view, period));
|
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.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);
|
FederationMetricHtmlizer.htmlize(data, "http.visits.visitors", federation, view, period, "metrics.http.visits.visitors", ChartColor.GREEN);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -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.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.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", 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,
|
FederationMetricHtmlizer.htmlize(data, "http.visits-visitorsbots", federation, view, period, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN,
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class OrganizationMetricSummaryPage
|
||||||
data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, TypeMenu.SUMMARY, view, period));
|
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.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);
|
OrganizationMetricHtmlizer.htmlize(data, "http.visits.visitors", organization, view, period, "metrics.http.visits.visitors", ChartColor.GREEN);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -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.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.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", 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,
|
OrganizationMetricHtmlizer.htmlize(data, "http.visits-visitorsbots", organization, view, period, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN,
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class ServiceMetricSummaryPage
|
||||||
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, TypeMenu.SUMMARY, view, period));
|
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.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);
|
ServiceMetricHtmlizer.htmlize(data, "http.visits.visitors", service, view, period, "metrics.http.visits.visitors", ChartColor.GREEN);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -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.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.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.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,
|
ServiceMetricHtmlizer.htmlizeData(data, "http.visits-visitorsbots", service, view, period, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN,
|
||||||
|
|
|
@ -32,6 +32,7 @@ import fr.devinsy.statoolinfos.core.Services;
|
||||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||||
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
|
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
|
||||||
import fr.devinsy.statoolinfos.uptime.UptimeStat;
|
import fr.devinsy.statoolinfos.uptime.UptimeStat;
|
||||||
|
import fr.devinsy.strings.StringList;
|
||||||
import fr.devinsy.xidyn.XidynException;
|
import fr.devinsy.xidyn.XidynException;
|
||||||
import fr.devinsy.xidyn.data.TagDataManager;
|
import fr.devinsy.xidyn.data.TagDataManager;
|
||||||
import fr.devinsy.xidyn.presenters.PresenterUtils;
|
import fr.devinsy.xidyn.presenters.PresenterUtils;
|
||||||
|
@ -63,6 +64,26 @@ public class UptimeView
|
||||||
{
|
{
|
||||||
TagDataManager data = new TagDataManager();
|
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;
|
int index = 0;
|
||||||
for (Service service : services.sortByName())
|
for (Service service : services.sortByName())
|
||||||
{
|
{
|
||||||
|
@ -76,31 +97,34 @@ public class UptimeView
|
||||||
data.setEscapedContent("line", index, "lineOrganizationValue", service.getOrganization().getName());
|
data.setEscapedContent("line", index, "lineOrganizationValue", service.getOrganization().getName());
|
||||||
|
|
||||||
//
|
//
|
||||||
LocalDate now = LocalDate.now();
|
|
||||||
for (int dayCount = 0; dayCount < 22; dayCount++)
|
for (int dayCount = 0; dayCount < 22; dayCount++)
|
||||||
{
|
{
|
||||||
LocalDate date = now.minusDays(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();
|
DayOfWeek weekDay = date.getDayOfWeek();
|
||||||
if ((weekDay == DayOfWeek.SUNDAY) || (weekDay == DayOfWeek.SATURDAY))
|
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;");
|
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);
|
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");
|
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")));
|
// String title = String.format("%d ok + %d err %s",
|
||||||
data.setAttribute("line", index, "statusImg-" + dayCount, "title", title);
|
// stat.getOkCount(), stat.getErrorCount(),
|
||||||
|
// date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
|
||||||
|
data.setAttribute("line", index, "statusImg-" + dayCount, "title", lines.toStringSeparatedBy(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<div id="metricMenuView" />
|
<div id="metricMenuView" />
|
||||||
<div id="charts" style="display: block;">
|
<div id="charts" style="display: block;">
|
||||||
<div id="http.hits.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
<div id="http.hits.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
<div id="http.ip.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
<div id="http.visitors.humans" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
<div id="http.visits.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
<div id="http.visits.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -46,6 +46,17 @@
|
||||||
<div id="http.ip.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
<div id="http.ip.visitors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
<div id="http.ip.bots" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
<div id="http.ip.bots" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
|
||||||
|
<h2>http.visitors</h2>
|
||||||
|
<div id="http.visitors" style="width: 450px; height: 300px; border: 1px solid #e7e7e7;"/>
|
||||||
|
|
||||||
|
<div id="http.visitors-ipv4ipv6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
<div id="http.visitors.ipv4" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
<div id="http.visitors.ipv6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
<br/>
|
||||||
|
<div id="http.visitors-humansbots" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
<div id="http.visitors.humans" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
<div id="http.visitors.bots" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
|
||||||
|
|
||||||
<h2>http.visits</h2>
|
<h2>http.visits</h2>
|
||||||
<div id="http.visits" style="width: 450px; height: 300px; border: 1px solid #e7e7e7;"/>
|
<div id="http.visits" style="width: 450px; height: 300px; border: 1px solid #e7e7e7;"/>
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class Uptime
|
||||||
return this.code;
|
return this.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getDatetime()
|
public LocalDateTime getDateTime()
|
||||||
{
|
{
|
||||||
return this.datetime;
|
return this.datetime;
|
||||||
}
|
}
|
||||||
|
|
126
src/fr/devinsy/statoolinfos/uptime/UptimeComparator.java
Normal file
126
src/fr/devinsy/statoolinfos/uptime/UptimeComparator.java
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
/*
|
||||||
|
* 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.uptime;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import fr.devinsy.statoolinfos.util.CompareUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class UptimeComparator.
|
||||||
|
*/
|
||||||
|
public class UptimeComparator implements Comparator<Uptime>
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -120,7 +120,7 @@ public class UptimeJournal
|
||||||
result.incError();
|
result.incError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((older == null) || (older.getDatetime().isAfter(uptime.getDatetime())))
|
if ((older == null) || (uptime.getDateTime().isAfter(older.getDateTime())))
|
||||||
{
|
{
|
||||||
older = uptime;
|
older = uptime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,7 +221,7 @@ public class UptimeJournalFile
|
||||||
{
|
{
|
||||||
for (Uptime uptime : journal.getUptimesAll())
|
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(line);
|
||||||
out.write("\n");
|
out.write("\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,15 @@
|
||||||
package fr.devinsy.statoolinfos.uptime;
|
package fr.devinsy.statoolinfos.uptime;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import fr.devinsy.strings.StringList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Uptimes.
|
* The Class Uptimes.
|
||||||
*/
|
*/
|
||||||
|
@ -76,7 +79,7 @@ public class Uptimes extends ArrayList<Uptime>
|
||||||
|
|
||||||
for (Uptime uptime : this)
|
for (Uptime uptime : this)
|
||||||
{
|
{
|
||||||
if (uptime.getDatetime().toLocalDate().isEqual(date))
|
if (uptime.getDateTime().toLocalDate().isEqual(date))
|
||||||
{
|
{
|
||||||
result.add(uptime);
|
result.add(uptime);
|
||||||
}
|
}
|
||||||
|
@ -102,10 +105,64 @@ public class Uptimes extends ArrayList<Uptime>
|
||||||
{
|
{
|
||||||
Uptime uptime = iterator.next();
|
Uptime uptime = iterator.next();
|
||||||
|
|
||||||
if (uptime.getDatetime().toLocalDate().isBefore(limit))
|
if (uptime.getDateTime().toLocalDate().isBefore(limit))
|
||||||
{
|
{
|
||||||
iterator.remove();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue