TF-EssentialsX/Essentials/src/com/earth2me/essentials/metrics/MetricsStarter.java

213 lines
4.8 KiB
Java
Raw Normal View History

package com.earth2me.essentials.metrics;
import com.earth2me.essentials.IEssentials;
2012-03-15 01:17:12 +00:00
import com.earth2me.essentials.metrics.Metrics.Graph;
2012-03-15 02:12:27 +00:00
import com.earth2me.essentials.metrics.Metrics.Plotter;
2012-03-15 08:08:25 +00:00
import com.earth2me.essentials.register.payment.Method;
2012-03-30 12:27:57 +00:00
import com.earth2me.essentials.register.payment.methods.VaultEco;
2012-03-15 02:12:27 +00:00
import java.util.Locale;
import java.util.logging.Level;
public class MetricsStarter implements Runnable
{
private final IEssentials ess;
private transient Boolean start;
2012-03-15 01:17:12 +00:00
private enum Modules
{
Essentials,
2012-08-25 15:57:36 +00:00
EssentialsAntiBuild,
2012-03-25 09:39:19 +00:00
EssentialsAntiCheat,
2012-03-15 01:17:12 +00:00
EssentialsChat,
EssentialsSpawn,
EssentialsProtect,
EssentialsGeoIP,
EssentialsXMPP
};
public MetricsStarter(final IEssentials plugin)
{
ess = plugin;
try
{
2012-03-15 03:49:17 +00:00
final Metrics metrics = new Metrics(ess);
2012-03-15 03:49:17 +00:00
ess.setMetrics(metrics);
if (!metrics.isOptOut())
{
if (ess.getSettings().isMetricsEnabled())
{
start = true;
}
else
{
ess.getLogger().info("This plugin collects minimal statistic data and sends it to http://metrics.essentials3.net.");
2012-03-15 03:49:17 +00:00
ess.getLogger().info("You can opt out by running /essentials opt-out");
ess.getLogger().info("This will start 5 minutes after the first admin/op joins.");
start = false;
}
return;
}
}
2012-03-15 03:49:17 +00:00
catch (Exception ex)
{
2012-03-15 01:32:08 +00:00
metricsError(ex);
}
}
@Override
public void run()
{
try
{
2012-03-15 03:49:17 +00:00
final Metrics metrics = ess.getMetrics();
2012-03-15 01:17:12 +00:00
2012-03-15 03:49:17 +00:00
final Graph moduleGraph = metrics.createGraph("Modules Used");
2012-03-15 01:17:12 +00:00
for (Modules module : Modules.values())
{
final String moduleName = module.toString();
if (ess.getServer().getPluginManager().isPluginEnabled(moduleName))
{
2012-03-15 02:12:27 +00:00
moduleGraph.addPlotter(new SimplePlotter(moduleName));
2012-03-15 01:17:12 +00:00
}
}
2012-03-15 03:49:17 +00:00
final Graph localeGraph = metrics.createGraph("Locale");
2012-03-15 02:12:27 +00:00
localeGraph.addPlotter(new SimplePlotter(ess.getI18n().getCurrentLocale().getDisplayLanguage(Locale.ENGLISH)));
2012-03-15 03:49:17 +00:00
final Graph featureGraph = metrics.createGraph("Features");
2012-03-15 02:12:27 +00:00
featureGraph.addPlotter(new Plotter("Unique Accounts")
{
@Override
public int getValue()
{
return ess.getUserMap().getUniqueUsers();
}
});
2012-03-15 08:08:25 +00:00
featureGraph.addPlotter(new Plotter("Jails")
{
@Override
public int getValue()
{
return ess.getJails().getCount();
}
});
2012-03-15 02:12:27 +00:00
featureGraph.addPlotter(new Plotter("Kits")
{
@Override
public int getValue()
{
return ess.getSettings().getKits().getKeys(false).size();
}
});
featureGraph.addPlotter(new Plotter("Warps")
{
@Override
public int getValue()
{
return ess.getWarps().getWarpNames().size();
}
});
2012-03-15 08:08:25 +00:00
final Graph enabledGraph = metrics.createGraph("EnabledFeatures");
enabledGraph.addPlotter(new SimplePlotter("Total"));
final String BKcommand = ess.getSettings().getBackupCommand();
if (BKcommand != null && !"".equals(BKcommand))
{
enabledGraph.addPlotter(new SimplePlotter("Backup"));
}
if (ess.getJails().getCount() > 0)
{
enabledGraph.addPlotter(new SimplePlotter("Jails"));
}
if (ess.getSettings().getKits().getKeys(false).size() > 0)
{
enabledGraph.addPlotter(new SimplePlotter("Kits"));
}
if (ess.getWarps().getWarpNames().size() > 0)
{
enabledGraph.addPlotter(new SimplePlotter("Warps"));
}
if (!ess.getSettings().areSignsDisabled())
{
enabledGraph.addPlotter(new SimplePlotter("Signs"));
}
if (ess.getSettings().getAutoAfk() > 0)
{
enabledGraph.addPlotter(new SimplePlotter("AutoAFK"));
}
if (ess.getSettings().changeDisplayName())
{
enabledGraph.addPlotter(new SimplePlotter("DisplayName"));
}
if (ess.getSettings().getChatRadius() >= 1)
{
enabledGraph.addPlotter(new SimplePlotter("LocalChat"));
}
2012-03-15 08:15:28 +00:00
final Graph depGraph = metrics.createGraph("Dependencies");
2012-03-25 09:39:19 +00:00
final Method method = ess.getPaymentMethod().getMethod();
2012-03-15 08:08:25 +00:00
if (method != null)
{
2012-03-30 12:27:57 +00:00
String version;
2012-03-30 12:29:58 +00:00
if (method instanceof VaultEco)
{
2012-03-30 12:27:57 +00:00
version = ((VaultEco)method).getEconomy();
}
2012-03-30 12:29:58 +00:00
else
{
2012-03-30 12:27:57 +00:00
version = method.getVersion();
final int dashPosition = version.indexOf('-');
if (dashPosition > 0)
{
version = version.substring(0, dashPosition);
}
2012-03-25 09:39:19 +00:00
}
depGraph.addPlotter(new SimplePlotter(method.getName() + " " + version));
2012-03-15 08:08:25 +00:00
}
depGraph.addPlotter(new SimplePlotter(ess.getPermissionsHandler().getName()));
metrics.start();
}
2012-03-15 03:49:17 +00:00
catch (Exception ex)
{
2012-03-15 01:32:08 +00:00
metricsError(ex);
}
}
2012-03-15 03:49:17 +00:00
public void metricsError(final Exception ex)
2012-03-15 01:32:08 +00:00
{
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage(), ex);
}
else
{
ess.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
}
public Boolean getStart()
{
return start;
}
2012-03-15 02:12:27 +00:00
private class SimplePlotter extends Plotter
{
public SimplePlotter(final String name)
{
super(name);
}
@Override
public int getValue()
{
return 1;
}
}
}