Re-add CPU model detection and add GPU model detection via OSHI

This commit is contained in:
OptimisticDeving 2025-02-17 04:07:48 +00:00
parent 531c27b11d
commit 54faeaedd7
Signed by: opt
SSH key fingerprint: SHA256:efAXeDMyuFt1iia2xaqlrcHPlsXcjQEWNA2tmvVTqK8
2 changed files with 41 additions and 0 deletions
pom.xml
src/main/java/pw/kaboom/extras/commands

View file

@ -18,6 +18,14 @@
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.4.5</version>
<!-- This is a vanilla dependency, as of 1.20.4 -->
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>

View file

@ -5,12 +5,35 @@ import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import oshi.SystemInfo;
import oshi.hardware.GraphicsCard;
import oshi.hardware.HardwareAbstractionLayer;
import javax.annotation.Nonnull;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
public final class CommandServerInfo implements CommandExecutor {
private static final String[] GPU_DEVICES;
private static final String PROCESSOR_NAME;
static {
// No need to store this in a static variable as it would
// just waste memory & won't be accessed outside construction
// anyway.
final SystemInfo systemInfo = new SystemInfo();
final HardwareAbstractionLayer hardware = systemInfo.getHardware();
GPU_DEVICES = hardware.getGraphicsCards()
.stream()
.map(GraphicsCard::getName)
.toArray(String[]::new);
PROCESSOR_NAME = hardware.getProcessor()
.getProcessorIdentifier()
.getName();
}
private void sendInfoMessage(final CommandSender target, final String description,
final String value) {
target.sendMessage(
@ -50,6 +73,8 @@ public final class CommandServerInfo implements CommandExecutor {
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
);
sendInfoMessage(sender, "CPU model", PROCESSOR_NAME);
sendInfoMessage(sender, "CPU cores",
String.valueOf(Runtime.getRuntime().availableProcessors())
);
@ -57,6 +82,14 @@ public final class CommandServerInfo implements CommandExecutor {
String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
);
for (int i = 0; i < GPU_DEVICES.length; i++) {
sendInfoMessage(
sender,
"GPU device (" + i + ")",
GPU_DEVICES[i]
);
}
final long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
final long nonHeapUsage = ManagementFactory.getMemoryMXBean()
.getNonHeapMemoryUsage().getUsed();