Readd world count metric as multiline chart (for future use).

This commit is contained in:
Jeremy Wood 2020-06-13 01:17:00 -04:00
parent 04c65cc59e
commit 582d6bef1a
2 changed files with 33 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package com.onarandombox.MultiverseCore.utils.metrics; package com.onarandombox.MultiverseCore.utils.metrics;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
@ -28,10 +30,19 @@ public class MetricsConfigurator {
this.metrics = new Metrics(plugin, PLUGIN_ID); this.metrics = new Metrics(plugin, PLUGIN_ID);
} }
private MVWorldManager getWorldManager() {
return plugin.getMVWorldManager();
}
private Collection<MultiverseWorld> getMVWorlds() {
return getWorldManager().getMVWorlds();
}
private void initMetrics() { private void initMetrics() {
try { try {
addCustomGeneratorsMetric(); addCustomGeneratorsMetric();
createEnvironmentsMetric(); addEnvironmentsMetric();
addWorldCountMetric();
Logging.fine("Metrics enabled."); Logging.fine("Metrics enabled.");
} catch (Exception e) { } catch (Exception e) {
@ -42,7 +53,7 @@ public class MetricsConfigurator {
private void addCustomGeneratorsMetric() { private void addCustomGeneratorsMetric() {
addAdvancedPieMetric("custom_generators", map -> { addAdvancedPieMetric("custom_generators", map -> {
for (MultiverseWorld w : plugin.getMVWorldManager().getMVWorlds()) { for (MultiverseWorld w : getMVWorlds()) {
MetricsHelper.incrementCount(map, getGeneratorName(w)); MetricsHelper.incrementCount(map, getGeneratorName(w));
} }
}); });
@ -52,9 +63,9 @@ public class MetricsConfigurator {
return world.getGenerator() != null ? world.getGenerator() : NO_GENERATOR_NAME; return world.getGenerator() != null ? world.getGenerator() : NO_GENERATOR_NAME;
} }
private void createEnvironmentsMetric() { private void addEnvironmentsMetric() {
addAdvancedPieMetric("environments", map -> { addAdvancedPieMetric("environments", map -> {
for (MultiverseWorld w : plugin.getMVWorldManager().getMVWorlds()) { for (MultiverseWorld w : getMVWorlds()) {
MetricsHelper.incrementCount(map, titleCaseEnv(w.getEnvironment())); MetricsHelper.incrementCount(map, titleCaseEnv(w.getEnvironment()));
} }
}); });
@ -65,7 +76,19 @@ public class MetricsConfigurator {
return StringUtils.capitalize(envName.toLowerCase()); return StringUtils.capitalize(envName.toLowerCase());
} }
private void addWorldCountMetric() {
addMultiLineMetric("world_count", map -> {
int loadedWorldsCount = getMVWorlds().size();
map.put("Loaded worlds", loadedWorldsCount);
map.put("Total number of worlds", loadedWorldsCount + getWorldManager().getUnloadedWorlds().size());
});
}
private void addAdvancedPieMetric(String chartId, Consumer<Map<String, Integer>> metricsFunc) { private void addAdvancedPieMetric(String chartId, Consumer<Map<String, Integer>> metricsFunc) {
metrics.addCustomChart(MetricsHelper.createAdvancedPieChart(chartId, metricsFunc)); metrics.addCustomChart(MetricsHelper.createAdvancedPieChart(chartId, metricsFunc));
} }
private void addMultiLineMetric(String chartId, Consumer<Map<String, Integer>> metricsFunc) {
metrics.addCustomChart(MetricsHelper.createMultiLineChart(chartId, metricsFunc));
}
} }

View File

@ -23,4 +23,10 @@ enum MetricsHelper {
return new Metrics.AdvancedPie(chartId, () -> map); return new Metrics.AdvancedPie(chartId, () -> map);
} }
static Metrics.MultiLineChart createMultiLineChart(String chartId, Consumer<Map<String, Integer>> metricsFunc) {
Map<String, Integer> map = new HashMap<>();
metricsFunc.accept(map);
return new Metrics.MultiLineChart(chartId, () -> map);
}
} }