Added host chart.
This commit is contained in:
parent
0bc73f661e
commit
62390fd4a0
9 changed files with 575 additions and 3 deletions
|
@ -211,6 +211,21 @@ public class Service extends PathPropertyList
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host name.
|
||||
*
|
||||
* @return the host name
|
||||
*/
|
||||
public String getHostName()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = get("host.name");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host provider type.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
/*
|
||||
* Copyright (C) 2020-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.core;
|
||||
|
||||
|
@ -8,7 +23,7 @@ import java.util.Comparator;
|
|||
import fr.devinsy.statoolinfos.util.CompareUtils;
|
||||
|
||||
/**
|
||||
* The Class CategoryStatComparator.
|
||||
* The Class ServiceComparator.
|
||||
*/
|
||||
public class ServiceComparator implements Comparator<Service>
|
||||
{
|
||||
|
|
|
@ -118,6 +118,8 @@ public class FederationStatsPage
|
|||
data.setContent("categoryDistributionChart", Htmlizer.htmlizeCategoryDistributionChart());
|
||||
data.setContent("categoryDistributionPieChart", Htmlizer.htmlizeCatergoryDistributionPieChart(federation.getAllServices()));
|
||||
|
||||
data.setContent("hostNameChart", Htmlizer.htmlizeHostNamePieChart(federation.getAllServices()));
|
||||
|
||||
//
|
||||
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml", data).toString();
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ import fr.devinsy.statoolinfos.htmlize.charts.DoughnutChartView;
|
|||
import fr.devinsy.statoolinfos.htmlize.charts.PieChart;
|
||||
import fr.devinsy.statoolinfos.htmlize.charts.PieChart.Position;
|
||||
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView;
|
||||
import fr.devinsy.statoolinfos.metrics.StringCounter;
|
||||
import fr.devinsy.statoolinfos.metrics.StringCounterList;
|
||||
import fr.devinsy.statoolinfos.metrics.StringCounters;
|
||||
import fr.devinsy.statoolinfos.properties.PathProperty;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
import fr.devinsy.statoolinfos.stats.StatAgent;
|
||||
|
@ -292,6 +295,83 @@ public class Htmlizer
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Htmlize host name pie chart.
|
||||
*
|
||||
* @param services
|
||||
* the services
|
||||
* @return the string
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
*/
|
||||
public static String htmlizeHostNamePieChart(final Services services) throws StatoolInfosException
|
||||
{
|
||||
String result;
|
||||
|
||||
ChartColors colors = ChartColor.valueList();
|
||||
colors.remove(ChartColor.BLUE);
|
||||
|
||||
StringCounters counters = new StringCounters();
|
||||
long unknowns = 0;
|
||||
for (Service service : services)
|
||||
{
|
||||
if (service.getHostProviderType() == null)
|
||||
{
|
||||
unknowns += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (service.getHostProviderType())
|
||||
{
|
||||
case HOME:
|
||||
counters.inc("Auto-hébergé");
|
||||
break;
|
||||
|
||||
case HOSTEDBAY:
|
||||
case HOSTEDSERVER:
|
||||
case OUTSOURCED:
|
||||
counters.inc(service.getHostName());
|
||||
break;
|
||||
|
||||
case UNKNOWN:
|
||||
unknowns += 1;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringCounterList list = counters.toList().sortByCounter().reverse();
|
||||
|
||||
PieChart pie = new PieChart("Hébergeurs des services");
|
||||
pie.setLegendPosition(Position.RIGHT);
|
||||
|
||||
int index = 0;
|
||||
while ((index < list.size() && (index < 9)))
|
||||
{
|
||||
ChartColor color = colors.get(index);
|
||||
StringCounter counter = list.get(index);
|
||||
pie.add(counter.getString(), counter.getCounter(), color);
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
int others = 0;
|
||||
while (index < list.size())
|
||||
{
|
||||
StringCounter counter = list.get(index);
|
||||
others += counter.getCounter();
|
||||
|
||||
index += 1;
|
||||
}
|
||||
pie.add("Autres", others, ChartColor.GREY);
|
||||
pie.add("Inconnus", unknowns, ChartColor.BLUE);
|
||||
|
||||
result = DoughnutChartView.build(pie);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Htmlize host provider type chart.
|
||||
*
|
||||
|
@ -656,7 +736,7 @@ public class Htmlizer
|
|||
* the services
|
||||
* @return the string
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
* )* the statool infos exception
|
||||
*/
|
||||
public static String htmlizeServiceCountryChart(final Services services) throws StatoolInfosException
|
||||
{
|
||||
|
|
|
@ -24,9 +24,12 @@
|
|||
<div>
|
||||
<div id="hostServerTypeChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
|
||||
<div id="hostProviderTypeChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
|
||||
<div id="serviceInstallTypeChart" class="chartborder" style="width: 250px; height: 230px; display: inline-block; vertical-align: top;"/>
|
||||
<div id="serviceCountryChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
|
||||
</div>
|
||||
<div>
|
||||
<div id="hostNameChart" class="chartborder" style="width: 500px; height: 250px; display: inline-block;"/>
|
||||
<div id="serviceInstallTypeChart" class="chartborder" style="width: 500px; height: 250px; display: inline-block; vertical-align: top;"/>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div id="registrationTypeChart" class="column chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
|
||||
<div class="column">
|
||||
|
|
73
src/fr/devinsy/statoolinfos/metrics/StringCounter.java
Normal file
73
src/fr/devinsy/statoolinfos/metrics/StringCounter.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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.metrics;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class StringCounter.
|
||||
*/
|
||||
public class StringCounter
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(StringCounter.class);
|
||||
|
||||
private String string;
|
||||
private long counter;
|
||||
|
||||
/**
|
||||
* Instantiates a new string counter.
|
||||
*
|
||||
* @param string
|
||||
* the value
|
||||
*/
|
||||
public StringCounter(final String string)
|
||||
{
|
||||
this.string = string;
|
||||
this.counter = 0;
|
||||
}
|
||||
|
||||
public long getCounter()
|
||||
{
|
||||
return this.counter;
|
||||
}
|
||||
|
||||
public String getString()
|
||||
{
|
||||
return this.string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inc.
|
||||
*/
|
||||
public void inc()
|
||||
{
|
||||
this.counter += 1;
|
||||
}
|
||||
|
||||
public void setCounter(final long counter)
|
||||
{
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public void setString(final String string)
|
||||
{
|
||||
this.string = string;
|
||||
}
|
||||
}
|
158
src/fr/devinsy/statoolinfos/metrics/StringCounterComparator.java
Normal file
158
src/fr/devinsy/statoolinfos/metrics/StringCounterComparator.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* 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.metrics;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import fr.devinsy.statoolinfos.util.CompareUtils;
|
||||
|
||||
/**
|
||||
* The Class StringCounterComparator.
|
||||
*/
|
||||
public class StringCounterComparator implements Comparator<StringCounter>
|
||||
{
|
||||
public enum Sorting
|
||||
{
|
||||
STRING,
|
||||
COUNTER
|
||||
}
|
||||
|
||||
private Sorting sorting;
|
||||
|
||||
/**
|
||||
* Instantiates a new string counter comparator.
|
||||
*
|
||||
* @param sorting
|
||||
* the sorting
|
||||
*/
|
||||
public StringCounterComparator(final Sorting sorting)
|
||||
{
|
||||
this.sorting = sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare.
|
||||
*
|
||||
* @param alpha
|
||||
* the alpha
|
||||
* @param bravo
|
||||
* the bravo
|
||||
* @return the int
|
||||
*/
|
||||
@Override
|
||||
public int compare(final StringCounter alpha, final StringCounter 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 StringCounter alpha, final StringCounter bravo, final Sorting sorting)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (sorting == null)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (sorting)
|
||||
{
|
||||
default:
|
||||
case STRING:
|
||||
result = CompareUtils.compareIgnoreCase(getString(alpha), getString(bravo));
|
||||
break;
|
||||
|
||||
case COUNTER:
|
||||
result = CompareUtils.compare(getCounter(alpha), getCounter(bravo));
|
||||
if (result == 0)
|
||||
{
|
||||
result = CompareUtils.compareIgnoreCase(getString(alpha), getString(bravo));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the counter.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the counter
|
||||
*/
|
||||
public static Long getCounter(final StringCounter source)
|
||||
{
|
||||
Long result;
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (long) source.getCounter();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the string
|
||||
*/
|
||||
public static String getString(final StringCounter source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = source.getString();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
104
src/fr/devinsy/statoolinfos/metrics/StringCounterList.java
Normal file
104
src/fr/devinsy/statoolinfos/metrics/StringCounterList.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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.metrics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* The Class StringCounterList.
|
||||
*/
|
||||
public class StringCounterList extends ArrayList<StringCounter>
|
||||
{
|
||||
private static final long serialVersionUID = 6392647621400816570L;
|
||||
|
||||
/**
|
||||
* Instantiates a new string counter list.
|
||||
*/
|
||||
public StringCounterList()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse.
|
||||
*
|
||||
* @return the categories
|
||||
*/
|
||||
public StringCounterList reverse()
|
||||
{
|
||||
StringCounterList result;
|
||||
|
||||
Collections.reverse(this);
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort.
|
||||
*
|
||||
* @param sorting
|
||||
* the sorting
|
||||
* @return the string counter list
|
||||
*/
|
||||
public StringCounterList sort(final StringCounterComparator.Sorting sorting)
|
||||
{
|
||||
StringCounterList result;
|
||||
|
||||
sort(new StringCounterComparator(sorting));
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by counter.
|
||||
*
|
||||
* @return the string counter list
|
||||
*/
|
||||
public StringCounterList sortByCounter()
|
||||
{
|
||||
StringCounterList result;
|
||||
|
||||
result = sort(StringCounterComparator.Sorting.COUNTER);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by name.
|
||||
*
|
||||
* @return the services
|
||||
*/
|
||||
public StringCounterList sortByString()
|
||||
{
|
||||
StringCounterList result;
|
||||
|
||||
result = sort(StringCounterComparator.Sorting.STRING);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
122
src/fr/devinsy/statoolinfos/metrics/StringCounters.java
Normal file
122
src/fr/devinsy/statoolinfos/metrics/StringCounters.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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.metrics;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* The Class StringCounters.
|
||||
*/
|
||||
public class StringCounters extends HashMap<String, StringCounter>
|
||||
{
|
||||
private static final long serialVersionUID = -4771969211702752306L;
|
||||
|
||||
/**
|
||||
* Instantiates a new string counters.
|
||||
*/
|
||||
public StringCounters()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute key.
|
||||
*
|
||||
* @param string
|
||||
* the string
|
||||
* @return the string
|
||||
*/
|
||||
public String computeKey(final String string)
|
||||
{
|
||||
String result;
|
||||
|
||||
result = StringUtils.toRootLowerCase(string);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param string
|
||||
* the string
|
||||
* @return the long
|
||||
*/
|
||||
public long get(final String string)
|
||||
{
|
||||
long result;
|
||||
|
||||
String key = computeKey(string);
|
||||
|
||||
StringCounter counter = super.get(key);
|
||||
|
||||
if (counter == null)
|
||||
{
|
||||
result = 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = counter.getCounter();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inc.
|
||||
*
|
||||
* @param string
|
||||
* the key
|
||||
*/
|
||||
public void inc(final String string)
|
||||
{
|
||||
String key = computeKey(string);
|
||||
|
||||
StringCounter counter = super.get(key);
|
||||
|
||||
if (counter == null)
|
||||
{
|
||||
counter = new StringCounter(string);
|
||||
put(key, counter);
|
||||
}
|
||||
|
||||
counter.inc();
|
||||
}
|
||||
|
||||
/**
|
||||
* To list.
|
||||
*
|
||||
* @return the string counter list
|
||||
*/
|
||||
public StringCounterList toList()
|
||||
{
|
||||
StringCounterList result;
|
||||
|
||||
result = new StringCounterList();
|
||||
|
||||
result.addAll(values());
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue