|
5 | 5 | import org.bukkit.command.Command;
|
6 | 6 | import org.bukkit.command.CommandExecutor;
|
7 | 7 | import org.bukkit.command.CommandSender;
|
| 8 | +import oshi.SystemInfo; |
| 9 | +import oshi.hardware.GraphicsCard; |
| 10 | +import oshi.hardware.HardwareAbstractionLayer; |
8 | 11 |
|
9 | 12 | import javax.annotation.Nonnull;
|
10 | 13 | import java.lang.management.ManagementFactory;
|
11 | 14 | import java.net.InetAddress;
|
12 | 15 |
|
13 | 16 | public final class CommandServerInfo implements CommandExecutor {
|
| 17 | + private static final String[] GPU_DEVICES; |
| 18 | + private static final String PROCESSOR_NAME; |
| 19 | + |
| 20 | + static { |
| 21 | + // No need to store this in a static variable as it would |
| 22 | + // just waste memory & won't be accessed outside construction |
| 23 | + // anyway. |
| 24 | + |
| 25 | + final SystemInfo systemInfo = new SystemInfo(); |
| 26 | + final HardwareAbstractionLayer hardware = systemInfo.getHardware(); |
| 27 | + |
| 28 | + GPU_DEVICES = hardware.getGraphicsCards() |
| 29 | + .stream() |
| 30 | + .map(GraphicsCard::getName) |
| 31 | + .toArray(String[]::new); |
| 32 | + PROCESSOR_NAME = hardware.getProcessor() |
| 33 | + .getProcessorIdentifier() |
| 34 | + .getName(); |
| 35 | + } |
| 36 | + |
14 | 37 | private void sendInfoMessage(final CommandSender target, final String description,
|
15 | 38 | final String value) {
|
16 | 39 | target.sendMessage(
|
@@ -50,13 +73,23 @@ public boolean onCommand(final @Nonnull CommandSender sender,
|
50 | 73 | + ManagementFactory.getRuntimeMXBean().getVmVersion()
|
51 | 74 | );
|
52 | 75 |
|
| 76 | + sendInfoMessage(sender, "CPU model", PROCESSOR_NAME); |
| 77 | + |
53 | 78 | sendInfoMessage(sender, "CPU cores",
|
54 | 79 | String.valueOf(Runtime.getRuntime().availableProcessors())
|
55 | 80 | );
|
56 | 81 | sendInfoMessage(sender, "CPU load",
|
57 | 82 | String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
|
58 | 83 | );
|
59 | 84 |
|
| 85 | + for (int i = 0; i < GPU_DEVICES.length; i++) { |
| 86 | + sendInfoMessage( |
| 87 | + sender, |
| 88 | + "GPU device (" + i + ")", |
| 89 | + GPU_DEVICES[i] |
| 90 | + ); |
| 91 | + } |
| 92 | + |
60 | 93 | final long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
|
61 | 94 | final long nonHeapUsage = ManagementFactory.getMemoryMXBean()
|
62 | 95 | .getNonHeapMemoryUsage().getUsed();
|
|
0 commit comments