Skip to content

Commit

Permalink
Add config for the metrics/stats id until there is a good way to read it
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Apr 30, 2021
1 parent 824db1e commit 2b39a98
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/de/themoep/snap/Snap.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public Snap(ProxyServer proxy, Logger logger, @DataDirectory Path dataFolder) {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InvocationTargetException, IOException {
if (loadConfig()) {
if (!config.has("stats-id") || config.getString("stats-id").isEmpty()) {
config.set("stats-id", UUID.randomUUID().toString());
config.save();
}
bungeeAdapter = new SnapBungeeAdapter(this);
bungeeAdapter.registerEvents();
bungeeAdapter.loadPlugins();
Expand All @@ -77,6 +81,10 @@ private boolean loadConfig() {
return false;
}

public PluginConfig getConfig() {
return config;
}

public ProxyServer getProxy() {
return proxy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
public class SnapProxyServer extends ProxyServer {
private final Snap snap;

private String statsId;
private Field fIdentifierMap;
private Set<String> channels = new HashSet<>();
private final ListenerInfo listener;
Expand All @@ -73,6 +74,11 @@ public SnapProxyServer(Snap snap) {
this.snap = snap;
com.velocitypowered.api.proxy.config.ProxyConfig config = snap.getProxy().getConfiguration();

statsId = snap.getConfig().getString("stats-id");
if (statsId == null) {
statsId = UUID.randomUUID().toString();
}

listener = new ListenerInfo(
snap.getProxy().getBoundAddress(),
LegacyComponentSerializer.legacySection().serialize(config.getMotd()),
Expand Down Expand Up @@ -356,7 +362,7 @@ public int getTimeout() {

@Override
public String getUuid() {
return UUID.randomUUID().toString();
return statsId;
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/snap.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Whether to throw exceptions when accessing methods that aren't supported
# Setting this to false makes them return sensible values but they might not be correct
throw-unsupported-exception = true
throw-unsupported-exception = true

# The stats/metrics ID of this proxy, ideally the same as in the velocity.toml
stats-id = ""

0 comments on commit 2b39a98

Please sign in to comment.