123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package com.gmail.nossr50.util.metrics;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Locale;
- import com.gmail.nossr50.mcMMO;
- import com.gmail.nossr50.config.Config;
- import com.gmail.nossr50.config.HiddenConfig;
- import com.gmail.nossr50.locale.LocaleLoader;
- import com.turt2live.metrics.EMetrics;
- import com.turt2live.metrics.Metrics;
- import com.turt2live.metrics.Metrics.Graph;
- public class MetricsManager {
- private static boolean setup = false;
- public static void setup() {
- if (setup) {
- return;
- }
- if (Config.getInstance().getStatsTrackingEnabled()) {
- try {
- EMetrics emetrics = new EMetrics(mcMMO.p);
- Metrics metrics = emetrics.getMetrics();
- // Timings Graph
- Graph timingsGraph = metrics.createGraph("Percentage of servers using timings");
- if (mcMMO.p.getServer().getPluginManager().useTimings()) {
- timingsGraph.addPlotter(new Metrics.Plotter("Enabled") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- else {
- timingsGraph.addPlotter(new Metrics.Plotter("Disabled") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- // Donut Version Graph
- Graph versionDonutGraph = metrics.createGraph("Donut Version");
- boolean haveVersionInformation = false;
- boolean isOfficialBuild = false;
- String officialKey = "e14cfacdd442a953343ebd8529138680";
- String version = mcMMO.p.getDescription().getVersion();
- InputStreamReader isr = new InputStreamReader(mcMMO.p.getResource(".jenkins"));
- BufferedReader br = new BufferedReader(isr);
- char[] key = new char[32];
- br.read(key);
- if (officialKey.equals(String.valueOf(key))) {
- isOfficialBuild = true;
- }
- if (version.contains("-")) {
- String majorVersion = version.substring(0, version.indexOf("-"));
- String subVersion = "";
- if (isOfficialBuild) {
- int startIndex = version.indexOf("-");
- if (version.substring(startIndex + 1).contains("-")) {
- subVersion = version.substring(startIndex, version.indexOf("-", startIndex + 1));
- } else {
- subVersion = "-release";
- }
- } else {
- subVersion = "-custom";
- }
- version = majorVersion + "~=~" + subVersion;
- haveVersionInformation = true;
- } else {
- haveVersionInformation = false;
- }
- if (haveVersionInformation) {
- versionDonutGraph.addPlotter(new Metrics.Plotter(version) {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- // Official v Custom build Graph
- Graph officialGraph = metrics.createGraph("Built by official ci");
- if (isOfficialBuild) {
- officialGraph.addPlotter(new Metrics.Plotter("Yes") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- else {
- officialGraph.addPlotter(new Metrics.Plotter("No") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- // Chunkmeta enabled Graph
- Graph chunkmetaGraph = metrics.createGraph("Uses Chunkmeta");
- if (HiddenConfig.getInstance().getChunkletsEnabled()) {
- chunkmetaGraph.addPlotter(new Metrics.Plotter("Yes") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- else {
- chunkmetaGraph.addPlotter(new Metrics.Plotter("No") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- // Storage method Graph
- Graph storageGraph = metrics.createGraph("Storage method");
- if (Config.getInstance().getUseMySQL()) {
- storageGraph.addPlotter(new Metrics.Plotter("SQL") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- else {
- storageGraph.addPlotter(new Metrics.Plotter("Flatfile") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- // Locale Graph
- Graph localeGraph = metrics.createGraph("Locale");
- localeGraph.addPlotter(new Metrics.Plotter(LocaleLoader.getCurrentLocale().getDisplayLanguage(Locale.US)) {
- @Override
- public int getValue() {
- return 1;
- }
- });
- // GlobalMultiplier Graph
- Graph globalMultiplierGraph = metrics.createGraph("Global Multiplier Graph");
- globalMultiplierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getExperienceGainsGlobalMultiplier() + "") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- // GlobalCurveModifier Graph
- Graph globalCurveModifierGraph = metrics.createGraph("Global Curve Modifier Graph");
- globalCurveModifierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getFormulaMultiplierCurve() + "") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- emetrics.startMetrics();
- }
- catch (IOException e) {
- mcMMO.p.getLogger().warning("Failed to submit stats.");
- }
- }
- }
- }
|