mirror of
https://github.com/kaboomserver/extras.git
synced 2025-08-03 11:06:27 +00:00
Re-add CPU model detection and add GPU model detection via OSHI
This commit is contained in:
parent
531c27b11d
commit
54faeaedd7
2 changed files with 41 additions and 0 deletions
8
pom.xml
8
pom.xml
|
@ -18,6 +18,14 @@
|
||||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
@ -5,12 +5,35 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import oshi.SystemInfo;
|
||||||
|
import oshi.hardware.GraphicsCard;
|
||||||
|
import oshi.hardware.HardwareAbstractionLayer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
public final class CommandServerInfo implements CommandExecutor {
|
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,
|
private void sendInfoMessage(final CommandSender target, final String description,
|
||||||
final String value) {
|
final String value) {
|
||||||
target.sendMessage(
|
target.sendMessage(
|
||||||
|
@ -50,6 +73,8 @@ public final class CommandServerInfo implements CommandExecutor {
|
||||||
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
|
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendInfoMessage(sender, "CPU model", PROCESSOR_NAME);
|
||||||
|
|
||||||
sendInfoMessage(sender, "CPU cores",
|
sendInfoMessage(sender, "CPU cores",
|
||||||
String.valueOf(Runtime.getRuntime().availableProcessors())
|
String.valueOf(Runtime.getRuntime().availableProcessors())
|
||||||
);
|
);
|
||||||
|
@ -57,6 +82,14 @@ public final class CommandServerInfo implements CommandExecutor {
|
||||||
String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
|
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 heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
|
||||||
final long nonHeapUsage = ManagementFactory.getMemoryMXBean()
|
final long nonHeapUsage = ManagementFactory.getMemoryMXBean()
|
||||||
.getNonHeapMemoryUsage().getUsed();
|
.getNonHeapMemoryUsage().getUsed();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue