Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more metrics #1896

Merged
merged 2 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,6 +123,9 @@ public void onEnable() {

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()) {
Expand Down Expand Up @@ -239,6 +247,11 @@ public BootstrapDumpInfo getDumpInfo() {
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);
Expand Down Expand Up @@ -277,10 +290,7 @@ private int[] parseVersion(String versionParam) {
* @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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ public void onServerStop(GameStoppedEvent event) {
public BootstrapDumpInfo getDumpInfo() {
return new GeyserSpongeDumpInfo();
}

@Override
public String getMinecraftServerVersion() {
return Sponge.getPlatform().getMinecraftVersion().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
}
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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 {
Expand Down Expand Up @@ -99,4 +100,18 @@ default WorldManager getWorldManager() {
* @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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -75,7 +76,7 @@ public class Metrics {

private final static ObjectMapper mapper = new ObjectMapper();

private GeyserConnector connector;
private final GeyserConnector connector;

/**
* Class constructor.
Expand Down Expand Up @@ -156,13 +157,15 @@ private ObjectNode getServerData() {
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();

data.put("serverUUID", serverUUID);

data.put("playerAmount", playerAmount);
data.put("javaVersion", javaVersion);
data.put("osName", osName);
data.put("osArch", osArch);
data.put("osVersion", osVersion);
Expand Down Expand Up @@ -241,7 +244,7 @@ private static byte[] compress(final String str) throws IOException {
}
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();
}
Expand Down