Refactored service metrics generate.

This commit is contained in:
Christian P. MOMON 2021-06-02 16:10:09 +02:00
parent 73fae00b63
commit 2de94e2a44
16 changed files with 1652 additions and 198 deletions

View file

@ -18,7 +18,9 @@
*/ */
package fr.devinsy.statoolinfos.htmlize; package fr.devinsy.statoolinfos.htmlize;
import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Locale; import java.util.Locale;
@ -26,6 +28,7 @@ import java.util.Locale;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.threeten.extra.YearWeek;
import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Categories; import fr.devinsy.statoolinfos.core.Categories;
@ -45,6 +48,8 @@ import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
import fr.devinsy.statoolinfos.htmlize.charts.PieChart; import fr.devinsy.statoolinfos.htmlize.charts.PieChart;
import fr.devinsy.statoolinfos.htmlize.charts.PieChart.Position; import fr.devinsy.statoolinfos.htmlize.charts.PieChart.Position;
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView; import fr.devinsy.statoolinfos.htmlize.charts.PieChartView;
import fr.devinsy.statoolinfos.htmlize.charts.WeekValues;
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
import fr.devinsy.statoolinfos.metrics.StringCounter; import fr.devinsy.statoolinfos.metrics.StringCounter;
import fr.devinsy.statoolinfos.metrics.StringCounterList; import fr.devinsy.statoolinfos.metrics.StringCounterList;
import fr.devinsy.statoolinfos.metrics.StringCounters; import fr.devinsy.statoolinfos.metrics.StringCounters;
@ -297,6 +302,101 @@ public class ChartHtmlizer
return result; return result;
} }
/**
* Htmlize metrics chart.
*
* @param title
* the title
* @param start
* the start
* @param end
* the end
* @param colors
* the colors
* @param datasets
* the datasets
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final String title, final Year start, final Year end, final ChartColor[] colors, final YearValues... datasets) throws StatoolInfosException
{
String result;
Year startTarget;
if (start == null)
{
startTarget = null;
for (YearValues dataset : datasets)
{
Year current = dataset.getOldestTimestamp();
if ((startTarget == null) || (current.isBefore(startTarget)))
{
startTarget = current;
}
}
}
else
{
startTarget = start;
}
Year endTarget;
if (end == null)
{
endTarget = Year.now();
}
else
{
endTarget = end;
}
BarChart chart = new BarChart(title);
chart.setStacked(true);
for (YearValues dataset : datasets)
{
chart.addDataset(dataset.getLabel());
}
if (startTarget != null)
{
for (Year timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusYears(1))
{
String timestampLabel = timestamp.format(DateTimeFormatter.ofPattern("yyyy", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
for (int index = 0; index < datasets.length; index++)
{
double value = datasets[index].getValue(timestamp);
chart.add(index, value, colors[index % colors.length]);
}
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param title
* the title
* @param start
* the start
* @param end
* the end
* @param colors
* the colors
* @param datasets
* the datasets
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final String title, final YearMonth start, final YearMonth end, final ChartColor[] colors, final MonthValues... datasets) throws StatoolInfosException public static String htmlizeMetricsChart(final String title, final YearMonth start, final YearMonth end, final ChartColor[] colors, final MonthValues... datasets) throws StatoolInfosException
{ {
String result; String result;
@ -358,6 +458,156 @@ public class ChartHtmlizer
return result; return result;
} }
/**
* Htmlize metrics chart.
*
* @param title
* the title
* @param start
* the start
* @param end
* the end
* @param colors
* the colors
* @param datasets
* the datasets
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final String title, final YearWeek start, final YearWeek end, final ChartColor[] colors, final WeekValues... datasets) throws StatoolInfosException
{
String result;
YearWeek startTarget;
if (start == null)
{
startTarget = null;
for (WeekValues dataset : datasets)
{
YearWeek current = dataset.getOldestTimestamp();
if ((startTarget == null) || (current.isBefore(startTarget)))
{
startTarget = current;
}
}
}
else
{
startTarget = start;
}
YearWeek endTarget;
if (end == null)
{
endTarget = YearWeek.now();
}
else
{
endTarget = end;
}
BarChart chart = new BarChart(title);
chart.setStacked(true);
for (WeekValues dataset : datasets)
{
chart.addDataset(dataset.getLabel());
}
if (startTarget != null)
{
for (YearWeek timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusWeeks(1))
{
LocalDate date = timestamp.atDay(DayOfWeek.MONDAY).plusWeeks(1);
String timestampLabel = date.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
for (int index = 0; index < datasets.length; index++)
{
double value = datasets[index].getValue(timestamp);
chart.add(index, value, colors[index % colors.length]);
}
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param start
* the start
* @param end
* the end
* @param dataset
* the dataset
* @param color
* the color
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final Year start, final Year end, final YearValues dataset, final ChartColor color) throws StatoolInfosException
{
String result;
Year startTarget;
if (start == null)
{
startTarget = dataset.getOldestTimestamp();
}
else
{
startTarget = start;
}
Year endTarget;
if (end == null)
{
endTarget = Year.now();
}
else
{
endTarget = end;
}
ChartColor targetColor;
if (color == null)
{
targetColor = ChartColor.BLUE;
}
else
{
targetColor = color;
}
BarChart chart = new BarChart(dataset.getLabel());
// chart.setStacked(true);
chart.addDataset(dataset.getLabel());
if (startTarget != null)
{
for (Year timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusYears(1))
{
String timestampLabel = timestamp.format(DateTimeFormatter.ofPattern("yyyy", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
double value = dataset.getValue(timestamp);
chart.add(0, value, targetColor);
}
}
result = BarChartView.build(chart);
//
return result;
}
/** /**
* Htmlize metrics chart. * Htmlize metrics chart.
* *
@ -429,6 +679,78 @@ public class ChartHtmlizer
return result; return result;
} }
/**
* Htmlize metrics chart.
*
* @param start
* the start
* @param end
* the end
* @param dataset
* the dataset
* @param color
* the color
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final YearWeek start, final YearWeek end, final WeekValues dataset, final ChartColor color) throws StatoolInfosException
{
String result;
YearWeek startTarget;
if (start == null)
{
startTarget = dataset.getOldestTimestamp();
}
else
{
startTarget = start;
}
YearWeek endTarget;
if (end == null)
{
endTarget = YearWeek.now();
}
else
{
endTarget = end;
}
ChartColor targetColor;
if (color == null)
{
targetColor = ChartColor.BLUE;
}
else
{
targetColor = color;
}
BarChart chart = new BarChart(dataset.getLabel());
// chart.setStacked(true);
chart.addDataset(dataset.getLabel());
if (startTarget != null)
{
for (YearWeek timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusWeeks(1))
{
LocalDate date = timestamp.atDay(DayOfWeek.MONDAY).plusWeeks(1);
String timestampLabel = date.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
double value = dataset.getValue(timestamp);
chart.add(0, value, targetColor);
}
}
result = BarChartView.build(chart);
//
return result;
}
/** /**
* Htmlize organization count chart. * Htmlize organization count chart.
* *

View file

@ -0,0 +1,219 @@
/*
* 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.htmlize;
import java.time.YearMonth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.extra.YearWeek;
import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
import fr.devinsy.statoolinfos.htmlize.charts.WeekValues;
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class MetricHtmlizeDataUtils.
*/
public class MetricHtmlizer
{
private static Logger logger = LoggerFactory.getLogger(MetricHtmlizer.class);
private static final int CHART_YEARS_FULL = 0;
private static final int CHART_MONTHS_FULL = 1;
private static final int CHART_MONTHS_LAST = 2;
private static final int CHART_MONTHS_2020 = 3;
private static final int CHART_MONTHS_2021 = 4;
private static final int CHART_WEEKS_FULL = 5;
private static final int CHART_WEEKS_LAST = 6;
private static final int CHART_WEEKS_2020 = 7;
private static final int CHART_WEEKS_2021 = 8;
private static final int CHART_DAYS_LAST = 9;
/**
* Htmlize.
*
* @param service
* the service
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlize(final Service service) throws StatoolInfosException
{
String result;
try
{
logger.debug("Building service generic metric page {}…", service.get("service.name"));
TagDataManager data = new TagDataManager();
//
data.setContent("headerView", ServiceHeaderView.htmlize(service));
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.WEB));
htmlizeData(data, "http.hits", service, "metrics.http.hits", ChartColor.BLUE);
htmlizeData(data, "http.hits-ipv4ipv6", service, "http.hits (ipv4 + ipv6)", "metrics.http.hits.ipv4", ChartColor.YELLOW, "metrics.http.hits.ipv6", ChartColor.GREEN);
htmlizeData(data, "http.hits.ipv4", service, "metrics.http.hits.ipv4", ChartColor.YELLOW);
htmlizeData(data, "http.hits.ipv6", service, "metrics.http.hits.ipv6", ChartColor.GREEN);
htmlizeData(data, "http.hits-visitorsbots", service, "http.hits (visitors + bots)", "metrics.http.hits.visitors", ChartColor.GREEN, "metrics.http.hits.bots", ChartColor.YELLOW);
htmlizeData(data, "http.hits.visitors", service, "metrics.http.hits.visitors", ChartColor.GREEN);
htmlizeData(data, "http.hits.bots", service, "metrics.http.hits.bots", ChartColor.YELLOW);
htmlizeData(data, "http.errors", service, "metrics.http.errors", ChartColor.RED);
htmlizeData(data, "http.errors.php", service, "metrics.http.errors.php", ChartColor.RED);
htmlizeData(data, "http.files", service, "metrics.http.files", ChartColor.BLUE);
htmlizeData(data, "http.pages", service, "metrics.http.pages", ChartColor.BLUE);
htmlizeData(data, "http.bytes", service, "metrics.http.bytes", ChartColor.BLUE);
htmlizeData(data, "http.ip", service, "metrics.http.ip", ChartColor.BLUE);
htmlizeData(data, "http.ip-visitorsbots", service, "http.ip (visitors + bots)", "metrics.http.ip.visitors", ChartColor.GREEN, "metrics.http.ip.bots", ChartColor.YELLOW);
htmlizeData(data, "http.ip.visitors", service, "metrics.http.ip.visitors", ChartColor.GREEN);
htmlizeData(data, "http.ip.bots", service, "metrics.http.ip.bots", ChartColor.YELLOW);
htmlizeData(data, "http.ip-ipv4ipv6", service, "http.ip (ipv4 + ipv6)", "metrics.http.ip.ipv4", ChartColor.YELLOW, "metrics.http.ip.ipv6", ChartColor.GREEN);
htmlizeData(data, "http.ip.ipv4", service, "metrics.http.ip.ipv4", ChartColor.YELLOW);
htmlizeData(data, "http.ip.ipv6", service, "metrics.http.ip.ipv6", ChartColor.GREEN);
htmlizeData(data, "http.visits", service, "metrics.http.visits", ChartColor.BLUE);
htmlizeData(data, "http.visits-visitorsbots", service, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, "metrics.http.visits.bots", ChartColor.YELLOW);
htmlizeData(data, "http.visits.bots", service, "metrics.http.visits.bots", ChartColor.YELLOW);
htmlizeData(data, "http.visits.visitors", service, "metrics.http.visits.visitors", ChartColor.GREEN);
//
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView2.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
trail.add(service.getName(), service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml");
result = WebCharterView.build(content, trail);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception);
}
//
return result;
}
/**
* Htmlize data.
*
* @param data
* the data
* @param metricId
* the metric id
* @param service
* the service
* @param metricPath
* the metric path
* @param color
* the color
* @throws StatoolInfosException
* the statool infos exception
*/
public static void htmlizeData(final TagDataManager data, final String metricId, final Service service, final String metricPath, final ChartColor color) throws StatoolInfosException
{
YearValues yearMetric = service.getMetricYearValues(metricPath);
data.setContent("charts", CHART_YEARS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, yearMetric, color));
MonthValues monthMetric = service.getMetricMonthValues(metricPath);
data.setContent("charts", CHART_MONTHS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, monthMetric, color));
data.setContent("charts", CHART_MONTHS_LAST, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.now().minusMonths(11), YearMonth.now(), monthMetric, color));
data.setContent("charts", CHART_MONTHS_2020, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(2020, 01), YearMonth.of(2020, 12), monthMetric, color));
data.setContent("charts", CHART_MONTHS_2021, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(2021, 01), YearMonth.of(2021, 12), monthMetric, color));
WeekValues weekMetric = service.getMetricWeekValues(metricPath);
data.setContent("charts", CHART_WEEKS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, weekMetric, color));
data.setContent("charts", CHART_WEEKS_LAST, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.now().minusYears(1), YearWeek.now(), weekMetric, color));
data.setContent("charts", CHART_WEEKS_2020, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(2020, 01), YearWeek.of(2020, 53), weekMetric, color));
data.setContent("charts", CHART_WEEKS_2021, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(2021, 01), YearWeek.of(2021, 53), weekMetric, color));
}
/**
* Htmlize data.
*
* @param data
* the data
* @param metricId
* the metric id
* @param service
* the service
* @param metricLabel
* the metric label
* @param metricPath1
* the metric path 1
* @param color1
* the color 1
* @param metricPath2
* the metric path 2
* @param color2
* the color 2
* @throws StatoolInfosException
* the statool infos exception
*/
public static void htmlizeData(final TagDataManager data, final String metricId, final Service service, final String metricLabel, final String metricPath1,
final ChartColor color1,
final String metricPath2,
final ChartColor color2) throws StatoolInfosException
{
//
YearValues yearMetric1 = service.getMetricYearValues(metricPath1);
YearValues yearMetric2 = service.getMetricYearValues(metricPath2);
data.setContent("charts", CHART_YEARS_FULL, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, yearMetric1, yearMetric2));
//
MonthValues monthMetric1 = service.getMetricMonthValues(metricPath1);
MonthValues monthMetric2 = service.getMetricMonthValues(metricPath2);
data.setContent("charts", CHART_MONTHS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
data.setContent("charts", CHART_MONTHS_LAST, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.now().minusMonths(11), YearMonth.now(), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
data.setContent("charts", CHART_MONTHS_2020, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(2020, 01), YearMonth.of(2020, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
data.setContent("charts", CHART_MONTHS_2021, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(2021, 01), YearMonth.of(2021, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
//
WeekValues weekMetric1 = service.getMetricWeekValues(metricPath1);
WeekValues weekMetric2 = service.getMetricWeekValues(metricPath2);
data.setContent("charts", CHART_WEEKS_FULL, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
data.setContent("charts", CHART_WEEKS_LAST, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.now().minusYears(1), YearWeek.now(), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
data.setContent("charts", CHART_WEEKS_2020, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(2020, 01), YearWeek.of(2020, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
data.setContent("charts", CHART_WEEKS_2021, metricId,
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(2021, 01), YearWeek.of(2021, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
}
}

View file

@ -18,14 +18,12 @@
*/ */
package fr.devinsy.statoolinfos.htmlize; package fr.devinsy.statoolinfos.htmlize;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.YearMonth; import java.time.YearMonth;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Organization;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem; import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem;
@ -61,8 +59,6 @@ public class OrganizationSummaryMetricPage
{ {
logger.debug("Building organization summary page {}…"); logger.debug("Building organization summary page {}…");
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
TagDataManager data = new TagDataManager(); TagDataManager data = new TagDataManager();
// //

View file

@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
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;
@ -59,10 +60,12 @@ public class ServiceMetricGenericPage
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.GENERIC)); data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.GENERIC));
// //
int graphicIndex = 0; MetricHtmlizer.htmlizeData(data, "users.count", service, "metrics.users.count", ChartColor.GREEN);
MetricHtmlizer.htmlizeData(data, "database.bytes", service, "metrics.database.bytes", ChartColor.GREEN);
MetricHtmlizer.htmlizeData(data, "files.bytes", service, "metrics.http.visits.visitors", ChartColor.GREEN);
// //
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString(); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricGenericView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail(); BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");

View file

@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
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;
@ -59,10 +60,14 @@ public class ServiceMetricSpecificPage
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SPECIFIC)); data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SPECIFIC));
// //
int graphicIndex = 0; int index = 1;
for (String metricPath : service.getMetricSpecificPrefixes())
{
MetricHtmlizer.htmlizeData(data, "foo" + index++, service, metricPath, ChartColor.BLUE);
}
// //
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString(); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSpecificView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail(); BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");

View file

@ -18,8 +18,6 @@
*/ */
package fr.devinsy.statoolinfos.htmlize; package fr.devinsy.statoolinfos.htmlize;
import java.time.YearMonth;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -27,7 +25,6 @@ import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
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;
@ -39,8 +36,19 @@ public class ServiceMetricSummaryPage
{ {
private static Logger logger = LoggerFactory.getLogger(ServiceMetricSummaryPage.class); private static Logger logger = LoggerFactory.getLogger(ServiceMetricSummaryPage.class);
private static final int CHART_YEARS_FULL = 0;
private static final int CHART_MONTHS_FULL = 1;
private static final int CHART_MONTHS_LAST = 2;
private static final int CHART_MONTHS_2020 = 3;
private static final int CHART_MONTHS_2021 = 4;
private static final int CHART_WEEKS_FULL = 5;
private static final int CHART_WEEKS_LAST = 6;
private static final int CHART_WEEKS_2020 = 7;
private static final int CHART_WEEKS_2021 = 8;
private static final int CHART_DAYS_LAST = 9;
/** /**
* Builds the. * Htmlize.
* *
* @param service * @param service
* the service * the service
@ -54,7 +62,7 @@ public class ServiceMetricSummaryPage
try try
{ {
logger.debug("Building service summary view {}…", service.get("service.name")); logger.debug("Building service generic metric page {}…", service.get("service.name"));
TagDataManager data = new TagDataManager(); TagDataManager data = new TagDataManager();
@ -62,31 +70,12 @@ public class ServiceMetricSummaryPage
data.setContent("headerView", ServiceHeaderView.htmlize(service)); data.setContent("headerView", ServiceHeaderView.htmlize(service));
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SUMMARY)); data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SUMMARY));
// MetricHtmlizer.htmlizeData(data, "http.hits.visitors", service, "metrics.http.hits.visitors", ChartColor.GREEN);
String tagIds[] = { "fullChart", "lastChart", "2020Chart", "2021Chart" }; MetricHtmlizer.htmlizeData(data, "http.ip.visitors", service, "metrics.http.ip.visitors", ChartColor.GREEN);
YearMonth starts[] = { null, YearMonth.now().minusMonths(11), YearMonth.of(2020, 01), YearMonth.of(2021, 01) }; MetricHtmlizer.htmlizeData(data, "http.visits.visitors", service, "metrics.http.visits.visitors", ChartColor.GREEN);
YearMonth ends[] = { null, YearMonth.now(), YearMonth.of(2020, 12), YearMonth.of(2021, 12) };
for (int index = 0; index < tagIds.length; index++)
{
String tagId = tagIds[index];
YearMonth start = starts[index];
YearMonth end = ends[index];
int graphicIndex = 0;
MonthValues metric = service.getMetricMonthValues("metrics.http.hits.visitors");
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN));
metric = service.getMetricMonthValues("metrics.http.ip.visitors");
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN));
metric = service.getMetricMonthValues("metrics.http.visits.visitors");
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN));
}
// //
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString(); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail(); BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
@ -95,7 +84,7 @@ public class ServiceMetricSummaryPage
} }
catch (XidynException exception) catch (XidynException exception)
{ {
throw new StatoolInfosException("Error building service summary metrics view: " + exception.getMessage(), exception); throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception);
} }
// //

View file

@ -18,8 +18,6 @@
*/ */
package fr.devinsy.statoolinfos.htmlize; package fr.devinsy.statoolinfos.htmlize;
import java.time.YearMonth;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -27,7 +25,6 @@ import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
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;
@ -40,7 +37,7 @@ public class ServiceMetricWebPage
private static Logger logger = LoggerFactory.getLogger(ServiceMetricWebPage.class); private static Logger logger = LoggerFactory.getLogger(ServiceMetricWebPage.class);
/** /**
* Builds the. * Htmlize.
* *
* @param service * @param service
* the service * the service
@ -62,83 +59,44 @@ public class ServiceMetricWebPage
data.setContent("headerView", ServiceHeaderView.htmlize(service)); data.setContent("headerView", ServiceHeaderView.htmlize(service));
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.WEB)); data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.WEB));
// service.getPrefixes(); MetricHtmlizer.htmlizeData(data, "http.hits", service, "metrics.http.hits", ChartColor.BLUE);
String tagIds[] = { "fullChart", "lastChart", "2020Chart", "2021Chart" }; MetricHtmlizer.htmlizeData(data, "http.hits-ipv4ipv6", service, "http.hits (ipv4 + ipv6)", "metrics.http.hits.ipv4", ChartColor.YELLOW, "metrics.http.hits.ipv6", ChartColor.GREEN);
YearMonth starts[] = { null, YearMonth.now().minusMonths(11), YearMonth.of(2020, 01), YearMonth.of(2021, 01) }; MetricHtmlizer.htmlizeData(data, "http.hits.ipv4", service, "metrics.http.hits.ipv4", ChartColor.YELLOW);
YearMonth ends[] = { null, YearMonth.now(), YearMonth.of(2020, 12), YearMonth.of(2021, 12) }; MetricHtmlizer.htmlizeData(data, "http.hits.ipv6", service, "metrics.http.hits.ipv6", ChartColor.GREEN);
for (int index = 0; index < tagIds.length; index++) MetricHtmlizer.htmlizeData(data, "http.hits-visitorsbots", service, "http.hits (visitors + bots)", "metrics.http.hits.visitors", ChartColor.GREEN, "metrics.http.hits.bots",
{ ChartColor.YELLOW);
String tagId = tagIds[index]; MetricHtmlizer.htmlizeData(data, "http.hits.visitors", service, "metrics.http.hits.visitors", ChartColor.GREEN);
YearMonth start = starts[index]; MetricHtmlizer.htmlizeData(data, "http.hits.bots", service, "metrics.http.hits.bots", ChartColor.YELLOW);
YearMonth end = ends[index];
int graphicIndex = 0; MetricHtmlizer.htmlizeData(data, "http.errors", service, "metrics.http.errors", ChartColor.RED);
MetricHtmlizer.htmlizeData(data, "http.errors.php", service, "metrics.http.errors.php", ChartColor.RED);
MonthValues metric = service.getMetricMonthValues("metrics.http.hits"); MetricHtmlizer.htmlizeData(data, "http.files", service, "metrics.http.files", ChartColor.BLUE);
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); MetricHtmlizer.htmlizeData(data, "http.pages", service, "metrics.http.pages", ChartColor.BLUE);
MetricHtmlizer.htmlizeData(data, "http.bytes", service, "metrics.http.bytes", ChartColor.BLUE);
MonthValues metric4 = service.getMetricMonthValues("metrics.http.hits.ipv4"); MetricHtmlizer.htmlizeData(data, "http.ip", service, "metrics.http.ip", ChartColor.BLUE);
MonthValues metric6 = service.getMetricMonthValues("metrics.http.hits.ipv6");
data.setContent(tagId, graphicIndex++,
ChartHtmlizer.htmlizeMetricsChart("http.hits (ipv4 + ipv6)", start, end, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
metric4 = service.getMetricMonthValues("metrics.http.hits.bots"); MetricHtmlizer.htmlizeData(data, "http.ip-visitorsbots", service, "http.ip (visitors + bots)", "metrics.http.ip.visitors", ChartColor.GREEN, "metrics.http.ip.bots",
metric6 = service.getMetricMonthValues("metrics.http.hits.visitors"); ChartColor.YELLOW);
data.setContent(tagId, graphicIndex++, MetricHtmlizer.htmlizeData(data, "http.ip.visitors", service, "metrics.http.ip.visitors", ChartColor.GREEN);
ChartHtmlizer.htmlizeMetricsChart("http.hits (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); MetricHtmlizer.htmlizeData(data, "http.ip.bots", service, "metrics.http.ip.bots", ChartColor.YELLOW);
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
metric = service.getMetricMonthValues("metrics.http.errors"); MetricHtmlizer.htmlizeData(data, "http.ip-ipv4ipv6", service, "http.ip (ipv4 + ipv6)", "metrics.http.ip.ipv4", ChartColor.YELLOW, "metrics.http.ip.ipv6", ChartColor.GREEN);
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED)); MetricHtmlizer.htmlizeData(data, "http.ip.ipv4", service, "metrics.http.ip.ipv4", ChartColor.YELLOW);
MetricHtmlizer.htmlizeData(data, "http.ip.ipv6", service, "metrics.http.ip.ipv6", ChartColor.GREEN);
metric = service.getMetricMonthValues("metrics.http.errors.php"); MetricHtmlizer.htmlizeData(data, "http.visits", service, "metrics.http.visits", ChartColor.BLUE);
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED));
metric = service.getMetricMonthValues("metrics.http.files"); MetricHtmlizer.htmlizeData(data, "http.visits-visitorsbots", service, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, "metrics.http.visits.bots",
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); ChartColor.YELLOW);
MetricHtmlizer.htmlizeData(data, "http.visits.bots", service, "metrics.http.visits.bots", ChartColor.YELLOW);
metric = service.getMetricMonthValues("metrics.http.pages"); MetricHtmlizer.htmlizeData(data, "http.visits.visitors", service, "metrics.http.visits.visitors", ChartColor.GREEN);
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
metric = service.getMetricMonthValues("metrics.http.bytes");
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
metric = service.getMetricMonthValues("metrics.http.ip");
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
metric4 = service.getMetricMonthValues("metrics.http.ip.bots");
metric6 = service.getMetricMonthValues("metrics.http.ip.visitors");
data.setContent(tagId, graphicIndex++,
ChartHtmlizer.htmlizeMetricsChart("http.ip (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
metric4 = service.getMetricMonthValues("metrics.http.ip.ipv4");
metric6 = service.getMetricMonthValues("metrics.http.ip.ipv6");
data.setContent(tagId, graphicIndex++,
ChartHtmlizer.htmlizeMetricsChart("http.ip (ipv4 + ipv6)", start, end, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
metric = service.getMetricMonthValues("metrics.http.visits");
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
metric4 = service.getMetricMonthValues("metrics.http.visits.bots");
metric6 = service.getMetricMonthValues("metrics.http.visits.visitors");
data.setContent(tagId, graphicIndex++,
ChartHtmlizer.htmlizeMetricsChart("http.visits (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
}
// //
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString(); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail(); BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");

View file

@ -0,0 +1,308 @@
/*
* 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.htmlize.charts;
import java.util.HashMap;
import org.threeten.extra.YearWeek;
import fr.devinsy.strings.StringList;
/**
* The Class WeekValues.
*/
public class WeekValues extends HashMap<YearWeek, Double>
{
private static final long serialVersionUID = -211990850389225574L;
private String label;
private String description;
/**
* Instantiates a new week values.
*/
public WeekValues()
{
this(null, null);
}
/**
* Instantiates a new week values.
*
* @param label
* the label
* @param description
* the description
*/
public WeekValues(final String label, final String description)
{
super();
this.label = label;
this.description = description;
}
/**
* Adds the.
*
* @param timestamp
* the timestamp
* @param value
* the value
*/
public void add(final YearWeek timestamp, final double value)
{
put(timestamp, getValue(timestamp) + value);
}
/**
* Adds the all.
*
* @param source
* the source
*/
public void addAll(final WeekValues source)
{
if (source != null)
{
for (YearWeek timestamp : source.keySet())
{
add(timestamp, source.getValue(timestamp));
}
}
}
/**
* Dec.
*
* @param timestamp
* the timestamp
*/
public void dec(final YearWeek timestamp)
{
put(timestamp, getValue(timestamp) - 1);
}
/**
* Extract.
*
* @param start
* the start
* @param end
* the end
* @return the month value map
*/
public WeekValues extract(final YearWeek start, final YearWeek end)
{
WeekValues result;
YearWeek startTarget = normalizeStart(start);
YearWeek endTarget = normalizeEnd(end);
result = new WeekValues();
for (YearWeek timestamp : this.keySet())
{
if ((!timestamp.isBefore(startTarget)) &&
(!timestamp.isAfter(endTarget)))
{
result.put(timestamp, get(timestamp));
}
}
//
return result;
}
public String getDescription()
{
return this.description;
}
public String getLabel()
{
return this.label;
}
/**
* Gets the normalized timestamps.
*
* @param start
* the start
* @param end
* the end
* @return the normalized timestamps
*/
public StringList getNormalizedTimestamps(final YearWeek start, final YearWeek end)
{
StringList result;
YearWeek startTarget = normalizeStart(start);
YearWeek endTarget = normalizeEnd(end);
result = new StringList();
for (YearWeek timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusWeeks(1))
{
result.append(timestamp);
}
//
return result;
}
/**
* Gets the oldest timestamp.
*
* @return the oldest timestamp
*/
public YearWeek getOldestTimestamp()
{
YearWeek result;
result = null;
for (YearWeek timestamp : this.keySet())
{
if ((result == null) || (timestamp.isBefore(result)))
{
result = timestamp;
}
}
//
return result;
}
/**
* Gets the value.
*
* @param timestamp
* the timestamp
* @return the value
*/
public double getValue(final YearWeek timestamp)
{
double result;
Double value = get(timestamp);
if (value == null)
{
result = 0.0;
}
else
{
result = value;
}
//
return result;
}
/**
* Inc.
*
* @param timestamp
* the timestamp
*/
public void inc(final YearWeek timestamp)
{
put(timestamp, getValue(timestamp) + 1);
}
/**
* Normalize end.
*
* @param end
* the end
* @return the year month
*/
public YearWeek normalizeEnd(final YearWeek end)
{
YearWeek result;
if (end == null)
{
result = YearWeek.now();
}
else
{
result = end;
}
//
return result;
}
/**
* Normalize start.
*
* @param start
* the start
* @return the year month
*/
public YearWeek normalizeStart(final YearWeek start)
{
YearWeek result;
if (start == null)
{
result = getOldestTimestamp();
}
else
{
result = start;
}
//
return result;
}
public void setDescription(final String description)
{
this.description = description;
}
public void setLabel(final String label)
{
this.label = label;
}
/**
* Gets the normalized values.
*
* @param start
* the start
* @param end
* the end
* @return the normalized values
*/
public StringList toNormalizedValues(final YearWeek start, final YearWeek end)
{
StringList result;
YearWeek startTarget = normalizeStart(start);
YearWeek endTarget = normalizeEnd(end);
result = new StringList();
for (YearWeek timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusWeeks(1))
{
result.append(getValue(timestamp));
}
//
return result;
}
}

View file

@ -0,0 +1,330 @@
/*
* 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.htmlize.charts;
import java.time.Year;
import java.util.HashMap;
import fr.devinsy.strings.StringList;
/**
* The Class YearValues.
*/
public class YearValues extends HashMap<Year, Double>
{
private static final long serialVersionUID = -3584379965186135356L;
private String label;
private String description;
/**
* Instantiates a new year values.
*/
public YearValues()
{
this(null, null);
}
/**
* Instantiates a new month values.
*
* @param label
* the label
* @param description
* the description
*/
public YearValues(final String label, final String description)
{
super();
this.label = label;
this.description = description;
}
/**
* Adds the.
*
* @param timestamp
* the timestamp
* @param value
* the value
*/
public void add(final Year timestamp, final double value)
{
put(timestamp, getValue(timestamp) + value);
}
/**
* Adds the all.
*
* @param source
* the source
*/
public void addAll(final YearValues source)
{
if (source != null)
{
for (Year timestamp : source.keySet())
{
add(timestamp, source.getValue(timestamp));
}
}
}
/**
* Dec.
*
* @param timestamp
* the timestamp
*/
public void dec(final Year timestamp)
{
put(timestamp, getValue(timestamp) - 1);
}
/**
* Extract.
*
* @param start
* the start
* @param end
* the end
* @return the month value map
*/
public YearValues extract(final Year start, final Year end)
{
YearValues result;
Year startTarget = normalizeStart(start);
Year endTarget = normalizeEnd(end);
result = new YearValues();
for (Year timestamp : this.keySet())
{
if ((!timestamp.isBefore(startTarget)) &&
(!timestamp.isAfter(endTarget)))
{
result.put(timestamp, get(timestamp));
}
}
//
return result;
}
/**
* Gets the description.
*
* @return the description
*/
public String getDescription()
{
return this.description;
}
/**
* Gets the label.
*
* @return the label
*/
public String getLabel()
{
return this.label;
}
/**
* Gets the normalized timestamps.
*
* @param start
* the start
* @param end
* the end
* @return the normalized timestamps
*/
public StringList getNormalizedTimestamps(final Year start, final Year end)
{
StringList result;
Year startTarget = normalizeStart(start);
Year endTarget = normalizeEnd(end);
result = new StringList();
for (Year timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusYears(1))
{
result.append(timestamp);
}
//
return result;
}
/**
* Gets the oldest timestamp.
*
* @return the oldest timestamp
*/
public Year getOldestTimestamp()
{
Year result;
result = null;
for (Year timestamp : this.keySet())
{
if ((result == null) || (timestamp.isBefore(result)))
{
result = timestamp;
}
}
//
return result;
}
/**
* Gets the value.
*
* @param timestamp
* the timestamp
* @return the value
*/
public double getValue(final Year timestamp)
{
double result;
Double value = get(timestamp);
if (value == null)
{
result = 0.0;
}
else
{
result = value;
}
//
return result;
}
/**
* Inc.
*
* @param timestamp
* the timestamp
*/
public void inc(final Year timestamp)
{
put(timestamp, getValue(timestamp) + 1);
}
/**
* Normalize end.
*
* @param end
* the end
* @return the year
*/
public Year normalizeEnd(final Year end)
{
Year result;
Year endTarget;
if (end == null)
{
result = Year.now();
}
else
{
result = end;
}
//
return result;
}
/**
* Normalize start.
*
* @param start
* the start
* @return the year month
*/
public Year normalizeStart(final Year start)
{
Year result;
if (start == null)
{
result = getOldestTimestamp();
}
else
{
result = start;
}
//
return result;
}
/**
* Sets the description.
*
* @param description
* the new description
*/
public void setDescription(final String description)
{
this.description = description;
}
/**
* Sets the label.
*
* @param label
* the new label
*/
public void setLabel(final String label)
{
this.label = label;
}
/**
* Gets the normalized values.
*
* @param start
* the start
* @param end
* the end
* @return the normalized values
*/
public StringList toNormalizedValues(final Year start, final Year end)
{
StringList result;
Year startTarget = normalizeStart(start);
Year endTarget = normalizeEnd(end);
result = new StringList();
for (Year timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusYears(1))
{
result.append(getValue(timestamp));
}
//
return result;
}
}

View file

@ -20,80 +20,158 @@
<a onclick="javascript:selectTypeMenu('specific');" href="#" id="specificTypeButton" class="button">Spécifiques</a> <a onclick="javascript:selectTypeMenu('specific');" href="#" id="specificTypeButton" class="button">Spécifiques</a>
</div> </div>
<div style="margin: 5px;"> <div style="margin: 5px;">
<span style="display: inline-block; width: 100px">Période</span> <span style="display: inline-block; width: 100px">Vue</span>
<a onclick="javascript:selectPeriodMenu('full');" href="#" id="fullPeriodButton" class="button">Tout</a> <a onclick="javascript:selectViewMenu('years');" href="#" id="yearsViewButton" class="button">Années</a>
<a onclick="javascript:selectPeriodMenu('last');" href="#" id="lastPeriodButton" class="button selected">12 mois</a> <a onclick="javascript:selectViewMenu('months');" href="#" id="monthsViewButton" class="button">Mois</a>
<a onclick="javascript:selectPeriodMenu('2020');" href="#" id="2020PeriodButton" class="button">2020</a> <a onclick="javascript:selectViewMenu('weeks');" href="#" id="weeksViewButton" class="button">Semaines</a>
<a onclick="javascript:selectPeriodMenu('2021');" href="#" id="2021PeriodButton" class="button">2021</a> <a onclick="javascript:selectViewMenu('days');" href="#" id="daysViewButton" class="button">Jours</a>
</div> </div>
<div style="margin: 5px;"> <div style="margin: 5px;">
<span style="display: inline-block; width: 100px">Vue</span> <span style="display: inline-block; width: 100px">Période</span>
<a onclick="javascript:createClosedSelect('years');" href="#" id="yearViewButton" class="button">Années</a> <a onclick="javascript:selectPeriodMenu('full');" href="#" id="fullPeriodButton" class="button">Tout</a>
<a onclick="javascript:createClosedSelect('months');" href="#" id="monthViewButton" class="button selected">Mois</a> <a onclick="javascript:selectPeriodMenu('last');" href="#" id="lastPeriodButton" class="button">12 mois</a>
<a onclick="javascript:createClosedSelect('weekds');" href="#" id="weekViewButton" class="button">Semaines</a> <a onclick="javascript:selectPeriodMenu('2020');" href="#" id="2020PeriodButton" class="button">2020</a>
<a onclick="javascript:createClosedSelect('days');" href="#" id="dayViewButton" class="button">Jours</a> <a onclick="javascript:selectPeriodMenu('2021');" href="#" id="2021PeriodButton" class="button">2021</a>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
function selectTypeMenu(selection) var CHART_YEARS_FULL = 0;
var CHART_MONTHS_FULL = 1;
var CHART_MONTHS_LAST = 2;
var CHART_MONTHS_2020 = 3;
var CHART_MONTHS_2021 = 4;
var CHART_WEEKS_FULL = 5;
var CHART_WEEKS_LAST = 6;
var CHART_WEEKS_2020 = 7;
var CHART_WEEKS_2021 = 8;
var CHART_DAYS_LAST = 9;
var currentView = 'months';
var currentPeriod = 'last';
function refreshMenu()
{ {
document.getElementById ('summaryTypeButton').classList.remove('selected'); //
document.getElementById ('genericTypeButton').classList.remove('selected'); document.getElementById('yearsViewButton').classList.remove('selected');
document.getElementById ('webTypeButton').classList.remove('selected'); document.getElementById('monthsViewButton').classList.remove('selected');
document.getElementById ('specificTypeButton').classList.remove('selected'); document.getElementById('weeksViewButton').classList.remove('selected');
document.getElementById('daysViewButton').classList.remove('selected');
if (selection == 'summary') document.getElementById(currentView + 'ViewButton').classList.add('selected');
{
document.getElementById ('summaryTypeButton').classList.add('selected');
}
else if (selection == 'generic')
{
document.getElementById ('genericTypeButton').classList.add('selected');
}
else if (selection == 'web')
{
document.getElementById ('webTypeButton').classList.add('selected');
}
else if (selection == 'specific')
{
document.getElementById ('specificTypeButton').classList.add('selected');
}
}
function selectPeriodMenu(selection)
{
document.getElementById('fullCharts').style.display = 'none';
document.getElementById('lastCharts').style.display = 'none';
document.getElementById('2020Charts').style.display = 'none';
document.getElementById('2021Charts').style.display = 'none';
//
document.getElementById('fullPeriodButton').classList.remove('selected'); document.getElementById('fullPeriodButton').classList.remove('selected');
document.getElementById('lastPeriodButton').classList.remove('selected'); document.getElementById('lastPeriodButton').classList.remove('selected');
document.getElementById('2020PeriodButton').classList.remove('selected'); document.getElementById('2020PeriodButton').classList.remove('selected');
document.getElementById('2021PeriodButton').classList.remove('selected'); document.getElementById('2021PeriodButton').classList.remove('selected');
if (selection == 'full') document.getElementById(currentPeriod + 'PeriodButton').classList.add('selected');
//
document.getElementById('charts_' + CHART_YEARS_FULL).style.display = 'none';
document.getElementById('charts_' + CHART_MONTHS_FULL).style.display = 'none';
document.getElementById('charts_' + CHART_MONTHS_LAST).style.display = 'none';
document.getElementById('charts_' + CHART_MONTHS_2020).style.display = 'none';
document.getElementById('charts_' + CHART_MONTHS_2021).style.display = 'none';
document.getElementById('charts_' + CHART_WEEKS_FULL).style.display = 'none';
document.getElementById('charts_' + CHART_WEEKS_LAST).style.display = 'none';
document.getElementById('charts_' + CHART_WEEKS_2020).style.display = 'none';
document.getElementById('charts_' + CHART_WEEKS_2021).style.display = 'none';
//document.getElementById('charts_' + CHART_DAYS_LAST).style.display = 'none';
if (currentView == 'years')
{ {
document.getElementById('fullPeriodButton').classList.add('selected'); if (currentPeriod == 'full')
document.getElementById('fullCharts').style.display = 'block'; {
document.getElementById('charts_' + CHART_YEARS_FULL).style.display = 'block';
} }
else if (selection == 'last') else if (currentPeriod == 'last')
{ {
document.getElementById('lastPeriodButton').classList.add('selected'); document.getElementById('charts_' + CHART_YEARS_FULL).style.display = 'block';
document.getElementById('lastCharts').style.display = 'block';
} }
else if (selection == '2020') else if (currentPeriod == '2020')
{ {
document.getElementById('2020PeriodButton').classList.add('selected'); document.getElementById('charts_' + CHART_YEARS_FULL).style.display = 'block';
document.getElementById('2020Charts').style.display = 'block';
} }
else if (selection == '2021') else if (currentPeriod == '2021')
{ {
document.getElementById('2021PeriodButton').classList.add('selected'); document.getElementById('charts_' + CHART_YEARS_FULL).style.display = 'block';
document.getElementById('2021Charts').style.display = 'block'; }
}
else if (currentView == 'months')
{
if (currentPeriod == 'full')
{
document.getElementById('charts_' + CHART_MONTHS_FULL).style.display = 'block';
}
else if (currentPeriod == 'last')
{
document.getElementById('charts_' + CHART_MONTHS_LAST).style.display = 'block';
}
else if (currentPeriod == '2020')
{
document.getElementById('charts_' + CHART_MONTHS_2020).style.display = 'block';
}
else if (currentPeriod == '2021')
{
document.getElementById('charts_' + CHART_MONTHS_2021).style.display = 'block';
}
}
else if (currentView == 'weeks')
{
if (currentPeriod == 'full')
{
document.getElementById('charts_' + CHART_WEEKS_FULL).style.display = 'block';
}
else if (currentPeriod == 'last')
{
document.getElementById('charts_' + CHART_WEEKS_LAST).style.display = 'block';
}
else if (currentPeriod == '2020')
{
document.getElementById('charts_' + CHART_WEEKS_2020).style.display = 'block';
}
else if (currentPeriod == '2021')
{
document.getElementById('charts_' + CHART_WEEKS_2021).style.display = 'block';
}
}
else if (currentView == 'days')
{
if (currentPeriod == 'full')
{
document.getElementById('charts_' + CHART_DAYS_LAST).style.display = 'block';
}
else if (currentPeriod == 'last')
{
document.getElementById('charts_' + CHART_DAYS_LAST).style.display = 'block';
}
else if (currentPeriod == '2020')
{
document.getElementById('charts_' + CHART_DAYS_LAST).style.display = 'block';
}
else if (currentPeriod == '2021')
{
document.getElementById('charts_' + CHART_DAYS_LAST).style.display = 'block';
}
} }
} }
</script>
function selectViewMenu(selection)
{
currentView = selection;
refreshMenu();
}
function selectPeriodMenu(selection)
{
currentPeriod = selection;
refreshMenu();
}
window.onload=function() {refreshMenu();}
</script>
</body> </body>
</html> </html>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="metricZone">
<div id="metricMenuView" />
<div id="charts" style="display: block;">
<h2>Utilisateurs</h2>
<div id="users.count" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<h2>Données</h2>
<div id="database.bytes" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="files.bytes" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="metricZone">
<div id="metricMenuView" />
<div id="charts" style="display: block;">
<h2>Spécifiques</h2>
<div id="foo1" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo2" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo3" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo4" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo5" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo7" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo8" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo9" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo10" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo11" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="foo12" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="metricZone">
<div id="metricMenuView" />
<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.ip.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>
</body>
</html>

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="metricZone">
<div id="metricMenuView" />
<div id="fullCharts" style="display: none;">
<div id="fullChart" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
<div id="lastCharts" style="display: block;">
<div id="lastChart" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
<div id="2020Charts" style="display: none;">
<div id="2020Chart" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
<div id="2021Charts" style="display: none;">
<div id="2021Chart" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="metricZone">
<div id="metricMenuView" />
<div id="charts" style="display: block;">
<h2>http.hits</h2>
<div id="http.hits" style="width: 450px; height: 300px; border: 1px solid #e7e7e7;"/>
<div id="http.hits-ipv4ipv6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.hits.ipv4" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.hits.ipv6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<br/>
<div id="http.hits-visitorsbots" 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.hits.bots" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<h2>http.errors</h2>
<div id="http.errors" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.errors.php" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<h2>http.???</h2>
<div id="http.pages" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.files" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.bytes" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<h2>http.ip</h2>
<div id="http.ip" style="width: 450px; height: 300px; border: 1px solid #e7e7e7;"/>
<div id="http.ip-ipv4ipv6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.ip.ipv4" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<div id="http.ip.ipv6" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
<br/>
<div id="http.ip-visitorsbots" 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;"/>
<h2>http.visits</h2>
<div id="http.visits" style="width: 450px; height: 300px; border: 1px solid #e7e7e7;"/>
<div id="http.visits-visitorsbots" 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.bots" style="width: 450px; height: 300px; display: inline-block; border: 1px solid #e7e7e7;"/>
</div>
</div>
</body>
</html>

View file

@ -20,6 +20,7 @@ package fr.devinsy.statoolinfos.properties;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.time.Year;
import java.time.YearMonth; import java.time.YearMonth;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -30,9 +31,12 @@ import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.threeten.extra.YearWeek;
import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues; import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
import fr.devinsy.statoolinfos.htmlize.charts.WeekValues;
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
import fr.devinsy.statoolinfos.metrics.Metric; import fr.devinsy.statoolinfos.metrics.Metric;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import fr.devinsy.strings.StringSet; import fr.devinsy.strings.StringSet;
@ -357,13 +361,6 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
return result; return result;
} }
/**
* Gets the metric.
*
* @param path
* the path
* @return the metric
*/
public MonthValues getMetricMonthValues(final String path) public MonthValues getMetricMonthValues(final String path)
{ {
MonthValues result; MonthValues result;
@ -397,6 +394,101 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
return result; return result;
} }
/**
* Gets the metric prefixes.
*
* @return the metric prefixes
*/
public StringList getMetricPrefixes()
{
StringList result;
StringSet prefixes = new StringSet();
Pattern pattern = Pattern.compile("^(?<target>metrics(\\.\\S+)+)\\.(name|description|\\d{4}).*$");
for (String path : getPaths())
{
Matcher matcher = pattern.matcher(path);
if (matcher.matches())
{
if (matcher.start("target") != -1)
{
prefixes.add(matcher.group("target"));
}
}
}
result = new StringList(prefixes).sort();
//
return result;
}
/**
* Gets the metric specific prefixes.
*
* @return the metric specific prefixes
*/
public StringList getMetricSpecificPrefixes()
{
StringList result;
result = new StringList();
for (String metricPath : getMetricPrefixes())
{
{
if ((!StringUtils.startsWithAny(metricPath, "metrics.http.", "metrics.user.", "mertics.database.", "metrics.files.")))
{
result.add(metricPath);
}
}
}
//
return result;
}
/**
* Gets the metric.
*
* @param path
* the path
* @return the metric
*/
public WeekValues getMetricWeekValues(final String path)
{
WeekValues result;
String metricName = StringUtils.defaultIfBlank(get(path + ".name"), RegExUtils.removeFirst(path, "^metrics\\."));
String metricDescription = StringUtils.defaultIfBlank(get(path + ".description"), metricName);
StringList years = getMetricYears(path).sort();
result = new WeekValues(metricName, metricDescription);
for (String year : years)
{
String line = get(path + "." + year + ".weeks");
StringList values = StatoolInfosUtils.splitWeekValues(line);
int weekIndex = 1;
for (String value : values)
{
if (!StringUtils.isBlank(value))
{
YearWeek timestamp = YearWeek.of(Integer.valueOf(year), weekIndex);
result.put(timestamp, Double.valueOf(value));
}
weekIndex += 1;
}
}
//
return result;
}
/** /**
* Gets the metric years. * Gets the metric years.
* *
@ -431,6 +523,48 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
return result; return result;
} }
/**
* Gets the metric year values.
*
* @param path
* the path
* @return the metric year values
*/
public YearValues getMetricYearValues(final String path)
{
YearValues result;
String metricName = StringUtils.defaultIfBlank(get(path + ".name"), RegExUtils.removeFirst(path, "^metrics\\."));
String metricDescription = StringUtils.defaultIfBlank(get(path + ".description"), metricName);
StringList years = getMetricYears(path).sort();
result = new YearValues(metricName, metricDescription);
if (!years.isEmpty())
{
Year start = Year.of(Integer.parseInt(years.getFirst()));
Year end = Year.of(Integer.parseInt(years.getLast()));
for (Year timestamp = start; !timestamp.isAfter(end); timestamp = timestamp.plusYears(1))
{
String value = get(path + "." + timestamp.getValue());
if (StringUtils.isNumeric(value))
{
result.put(timestamp, Double.valueOf(value));
}
else
{
result.put(timestamp, 0.0);
}
}
}
//
return result;
}
/** /**
* Gets the keys. * Gets the keys.
* *