Archiviert
13
0

Add the ability to disable metrics in the config file.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-11-04 02:15:16 +01:00
Ursprung 2f2eb148fa
Commit 64e3ba7f14
5 geänderte Dateien mit 32 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -14,6 +14,8 @@ class ProtocolConfig {
private static final String SECTION_GLOBAL = "global"; private static final String SECTION_GLOBAL = "global";
private static final String SECTION_AUTOUPDATER = "auto updater"; private static final String SECTION_AUTOUPDATER = "auto updater";
private static final String METRICS_ENABLED = "metrics";
private static final String UPDATER_NOTIFY = "notify"; private static final String UPDATER_NOTIFY = "notify";
private static final String UPDATER_DOWNLAD = "download"; private static final String UPDATER_DOWNLAD = "download";
private static final String UPDATER_DELAY = "delay"; private static final String UPDATER_DELAY = "delay";
@ -119,6 +121,25 @@ class ProtocolConfig {
return updater.getLong(UPDATER_LAST_TIME, 0); return updater.getLong(UPDATER_LAST_TIME, 0);
} }
/**
* Retrieve whether or not metrics is enabled.
* @return TRUE if metrics is enabled, FALSE otherwise.
*/
public boolean isMetricsEnabled() {
return global.getBoolean(METRICS_ENABLED, true);
}
/**
* Set whether or not metrics is enabled.
* <p>
* This setting will take effect next time ProtocolLib is started.
*
* @param enabled - whether or not metrics is enabled.
*/
public void setMetricsEnabled(boolean enabled) {
global.set(METRICS_ENABLED, enabled);
}
/** /**
* Set the last time we updated, in seconds since 1970.01.01 00:00. * Set the last time we updated, in seconds since 1970.01.01 00:00.
* @param lastTimeSeconds - new last update time. * @param lastTimeSeconds - new last update time.

Datei anzeigen

@ -189,7 +189,9 @@ public class ProtocolLibrary extends JavaPlugin {
// Try to enable statistics // Try to enable statistics
try { try {
statistisc = new Statistics(this); if (config.isMetricsEnabled()) {
statistisc = new Statistics(this);
}
} catch (IOException e) { } catch (IOException e) {
reporter.reportDetailed(this, "Unable to enable metrics.", e, statistisc); reporter.reportDetailed(this, "Unable to enable metrics.", e, statistisc);
} catch (Throwable e) { } catch (Throwable e) {
@ -310,7 +312,8 @@ public class ProtocolLibrary extends JavaPlugin {
/** /**
* Retrieve the metrics instance used to measure users of this library. * Retrieve the metrics instance used to measure users of this library.
* <p> * <p>
* Note that this method may return NULL when the server is reloading or shutting down. * Note that this method may return NULL when the server is reloading or shutting down. It is also
* NULL if metrics has been disabled.
* @return Metrics instance container. * @return Metrics instance container.
*/ */
public Statistics getStatistics() { public Statistics getStatistics() {

Datei anzeigen

@ -36,10 +36,11 @@ public class Statistics {
public Statistics(Plugin plugin) throws IOException { public Statistics(Plugin plugin) throws IOException {
metrics = new Metrics(plugin); metrics = new Metrics(plugin);
metrics.start();
// Determine who is using this library // Determine who is using this library
addPluginUserGraph(metrics); addPluginUserGraph(metrics);
metrics.start();
} }
private void addPluginUserGraph(Metrics metrics) { private void addPluginUserGraph(Metrics metrics) {

Datei anzeigen

@ -333,7 +333,7 @@ public class Updater
downloaded += count; downloaded += count;
fout.write(data, 0, count); fout.write(data, 0, count);
int percent = (int) (downloaded * 100 / fileLength); int percent = (int) (downloaded * 100 / fileLength);
if(announce & (percent % 10 == 0)) if(announce && (percent % 10 == 0))
{ {
logger.info("Downloading update: " + percent + "% of " + fileLength + " bytes."); logger.info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
} }

Datei anzeigen

@ -7,4 +7,6 @@ global:
# Number of seconds to wait until a new update is downloaded # Number of seconds to wait until a new update is downloaded
delay: 43200 # 12 hours delay: 43200 # 12 hours
# Last update time # Last update time
last: 0 last: 0
metrics: true