Add more metrics (#1896)

- Add the Java version being used
- Add the Minecraft server version being used, alongside the platform type that is using that version. Not used for proxies as those have to be on latest to support the latest Minecraft version
This commit is contained in:
Camotoy 2021-02-03 19:54:35 -05:00 committed by GitHub
parent 254990148c
commit c26a2baed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 6 deletions

View File

@ -69,6 +69,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
private GeyserConnector connector;
/**
* The Minecraft server version, formatted as <code>1.#.#</code>
*/
private String minecraftVersion;
@Override
public void onEnable() {
// This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed
@ -118,6 +123,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
geyserConfig.loadFloodgate(this);
// Turn "(MC: 1.16.4)" into 1.16.4.
this.minecraftVersion = Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
this.connector = GeyserConnector.start(PlatformType.SPIGOT, this);
if (geyserConfig.isLegacyPingPassthrough()) {
@ -239,6 +247,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
return new GeyserSpigotDumpInfo();
}
@Override
public String getMinecraftServerVersion() {
return this.minecraftVersion;
}
public boolean isCompatible(String version, String whichVersion) {
int[] currentVersion = parseVersion(version);
int[] otherVersion = parseVersion(whichVersion);
@ -277,10 +290,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
* @return the server version before ViaVersion finishes initializing
*/
public ProtocolVersion getServerProtocolVersion() {
String bukkitVersion = Bukkit.getServer().getVersion();
// Turn "(MC: 1.16.4)" into 1.16.4.
String version = bukkitVersion.split("\\(MC: ")[1].split("\\)")[0];
return ProtocolVersion.getClosest(version);
return ProtocolVersion.getClosest(this.minecraftVersion);
}
/**

View File

@ -163,4 +163,9 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
public BootstrapDumpInfo getDumpInfo() {
return new GeyserSpongeDumpInfo();
}
@Override
public String getMinecraftServerVersion() {
return Sponge.getPlatform().getMinecraftVersion().getName();
}
}

View File

@ -244,6 +244,20 @@ public class GeyserConnector {
}
return valueMap;
}));
String minecraftVersion = bootstrap.getMinecraftServerVersion();
if (minecraftVersion != null) {
Map<String, Map<String, Integer>> versionMap = new HashMap<>();
Map<String, Integer> platformMap = new HashMap<>();
platformMap.put(platformType.getPlatformName(), 1);
versionMap.put(minecraftVersion, platformMap);
metrics.addCustomChart(new Metrics.DrilldownPie("minecraftServerVersion", () -> {
// By the end, we should return, for example:
// 1.16.5 => (Spigot, 1)
return versionMap;
}));
}
}
boolean isGui = false;

View File

@ -33,6 +33,7 @@ import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.network.translators.world.GeyserWorldManager;
import org.geysermc.connector.network.translators.world.WorldManager;
import javax.annotation.Nullable;
import java.nio.file.Path;
public interface GeyserBootstrap {
@ -99,4 +100,18 @@ public interface GeyserBootstrap {
* @return The info about the bootstrap
*/
BootstrapDumpInfo getDumpInfo();
/**
* Returns the Minecraft version currently being used on the server. This should be only be implemented on platforms
* that have direct server access - platforms such as proxies always have to be on their latest version to support
* the newest Minecraft version, but older servers can use ViaVersion to enable newer versions to join.
* <br>
* If used, this should not be null before {@link org.geysermc.connector.GeyserConnector} initialization.
*
* @return the Minecraft version being used on the server, or <code>null</code> if not applicable
*/
@Nullable
default String getMinecraftServerVersion() {
return null;
}
}

View File

@ -36,6 +36,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -75,7 +76,7 @@ public class Metrics {
private final static ObjectMapper mapper = new ObjectMapper();
private GeyserConnector connector;
private final GeyserConnector connector;
/**
* Class constructor.
@ -156,6 +157,7 @@ public class Metrics {
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
String javaVersion = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
ObjectNode data = mapper.createObjectNode();
@ -163,6 +165,7 @@ public class Metrics {
data.put("serverUUID", serverUUID);
data.put("playerAmount", playerAmount);
data.put("javaVersion", javaVersion);
data.put("osName", osName);
data.put("osArch", osArch);
data.put("osVersion", osVersion);
@ -241,7 +244,7 @@ public class Metrics {
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
gzip.write(str.getBytes("UTF-8"));
gzip.write(str.getBytes(StandardCharsets.UTF_8));
gzip.close();
return outputStream.toByteArray();
}