mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Added Java Version to the metrics
This commit is contained in:
parent
41c1be4262
commit
1eef152f43
2 changed files with 36 additions and 5 deletions
|
@ -81,6 +81,8 @@ import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class GeyserConnector {
|
public class GeyserConnector {
|
||||||
|
@ -330,6 +332,40 @@ public class GeyserConnector {
|
||||||
return versionMap;
|
return versionMap;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following code can be attributed to the PaperMC project
|
||||||
|
// https://github.com/PaperMC/Paper/blob/master/Spigot-Server-Patches/0005-Paper-Metrics.patch#L614
|
||||||
|
metrics.addCustomChart(new Metrics.DrilldownPie("javaVersion", () -> {
|
||||||
|
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||||
|
String javaVersion = System.getProperty("java.version");
|
||||||
|
Map<String, Integer> entry = new HashMap<>();
|
||||||
|
entry.put(javaVersion, 1);
|
||||||
|
|
||||||
|
// http://openjdk.java.net/jeps/223
|
||||||
|
// Java decided to change their versioning scheme and in doing so modified the
|
||||||
|
// java.version system property to return $major[.$minor][.$security][-ea], as opposed to
|
||||||
|
// 1.$major.0_$identifier we can handle pre-9 by checking if the "major" is equal to "1",
|
||||||
|
// otherwise, 9+
|
||||||
|
String majorVersion = javaVersion.split("\\.")[0];
|
||||||
|
String release;
|
||||||
|
|
||||||
|
int indexOf = javaVersion.lastIndexOf('.');
|
||||||
|
|
||||||
|
if (majorVersion.equals("1")) {
|
||||||
|
release = "Java " + javaVersion.substring(0, indexOf);
|
||||||
|
} else {
|
||||||
|
// of course, it really wouldn't be all that simple if they didn't add a quirk, now
|
||||||
|
// would it valid strings for the major may potentially include values such as -ea to
|
||||||
|
// denote a pre release
|
||||||
|
Matcher versionMatcher = Pattern.compile("\\d+").matcher(majorVersion);
|
||||||
|
if (versionMatcher.find()) {
|
||||||
|
majorVersion = versionMatcher.group(0);
|
||||||
|
}
|
||||||
|
release = "Java " + majorVersion;
|
||||||
|
}
|
||||||
|
map.put(release, entry);
|
||||||
|
return map;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isGui = false;
|
boolean isGui = false;
|
||||||
|
|
|
@ -152,20 +152,15 @@ public class Metrics {
|
||||||
*/
|
*/
|
||||||
private ObjectNode getServerData() {
|
private ObjectNode getServerData() {
|
||||||
// OS specific data
|
// OS specific data
|
||||||
int playerAmount = connector.getPlayers().size();
|
|
||||||
|
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
String osArch = System.getProperty("os.arch");
|
String osArch = System.getProperty("os.arch");
|
||||||
String osVersion = System.getProperty("os.version");
|
String osVersion = System.getProperty("os.version");
|
||||||
String javaVersion = System.getProperty("java.version");
|
|
||||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
ObjectNode data = mapper.createObjectNode();
|
ObjectNode data = mapper.createObjectNode();
|
||||||
|
|
||||||
data.put("serverUUID", serverUUID);
|
data.put("serverUUID", serverUUID);
|
||||||
|
|
||||||
data.put("playerAmount", playerAmount);
|
|
||||||
data.put("javaVersion", javaVersion);
|
|
||||||
data.put("osName", osName);
|
data.put("osName", osName);
|
||||||
data.put("osArch", osArch);
|
data.put("osArch", osArch);
|
||||||
data.put("osVersion", osVersion);
|
data.put("osVersion", osVersion);
|
||||||
|
|
Loading…
Reference in a new issue