Add the ability to disable metrics in the config file.

This commit is contained in:
Kristian S. Stangeland 2012-11-04 02:15:16 +01:00
parent 2f2eb148fa
commit 64e3ba7f14
5 changed files with 32 additions and 5 deletions

View File

@ -14,6 +14,8 @@ class ProtocolConfig {
private static final String SECTION_GLOBAL = "global";
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_DOWNLAD = "download";
private static final String UPDATER_DELAY = "delay";
@ -119,6 +121,25 @@ class ProtocolConfig {
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.
* @param lastTimeSeconds - new last update time.

View File

@ -189,7 +189,9 @@ public class ProtocolLibrary extends JavaPlugin {
// Try to enable statistics
try {
if (config.isMetricsEnabled()) {
statistisc = new Statistics(this);
}
} catch (IOException e) {
reporter.reportDetailed(this, "Unable to enable metrics.", e, statistisc);
} catch (Throwable e) {
@ -310,7 +312,8 @@ public class ProtocolLibrary extends JavaPlugin {
/**
* Retrieve the metrics instance used to measure users of this library.
* <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.
*/
public Statistics getStatistics() {

View File

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

View File

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

View File

@ -8,3 +8,5 @@ global:
delay: 43200 # 12 hours
# Last update time
last: 0
metrics: true