From 07b95d46ac01b680e11af644c4ed0e0d4f8149af Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 21 Dec 2020 20:14:57 -0500 Subject: [PATCH] Delay sending stats to bStats for 3-5 minutes after server startup --- proxy/src/main/java/com/velocitypowered/proxy/Metrics.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java index 182316d7d..d8d635afa 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java @@ -18,6 +18,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ThreadLocalRandom; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; @@ -33,6 +34,8 @@ import org.asynchttpclient.Response; */ public class Metrics { + private static final int ONE_MINUTE_MS = 60_000; + // The version of this bStats class private static final int B_STATS_METRICS_REVISION = 2; @@ -96,12 +99,14 @@ public class Metrics { */ private void startSubmitting() { final Timer timer = new Timer(true); + long initialDelay = ONE_MINUTE_MS * 3 + (((long) (ThreadLocalRandom.current().nextDouble() * 2 + * ONE_MINUTE_MS))); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { submitData(); } - }, 1000, 1000 * 60 * 30); + }, initialDelay, 1000 * 60 * 30); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough // time to start. //