mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-24 12:16:36 +01:00
Added CPU & RAM information to /co status
This commit is contained in:
parent
e093970992
commit
dbd8723752
@ -15,6 +15,7 @@ COMMAND_THROTTLED: "Please wait a moment and try again."
|
||||
CONSUMER_ERROR: "Consumer queue processing already {paused|resumed}."
|
||||
CONSUMER_TOGGLED: "Consumer queue processing has been {paused|resumed}."
|
||||
CONTAINER_HEADER: "Container Transactions"
|
||||
CPU_CORES: "CPU cores."
|
||||
DATABASE_BUSY: "Database busy. Please try again later."
|
||||
DATABASE_INDEX_ERROR: "Unable to validate database indexes."
|
||||
DATABASE_LOCKED_1: "Database locked. Waiting up to 15 seconds..."
|
||||
@ -23,7 +24,7 @@ DATABASE_LOCKED_3: "To disable database locking, set \"database-lock: false\"."
|
||||
DATABASE_LOCKED_4: "Disabling database locking can result in data corruption."
|
||||
DATABASE_UNREACHABLE: "Database is unreachable. Discarding data and shutting down."
|
||||
DEVELOPMENT_BRANCH: "Development branch detected, skipping patch scripts."
|
||||
DIRT_BLOCK: "Placed a dirt block under you."
|
||||
DIRT_BLOCK: "Placed a temporary safety block under you."
|
||||
DISABLE_SUCCESS: "Success! Disabled {0}"
|
||||
ENABLE_FAILED: "{0} was unable to start."
|
||||
ENABLE_SUCCESS: "{0} has been successfully enabled!"
|
||||
@ -159,6 +160,7 @@ PURGE_REPAIRING: "Attempting to repair. This may take some time..."
|
||||
PURGE_ROWS: "{0} {row|rows} of data deleted."
|
||||
PURGE_STARTED: "Data purge started on \"{0}\"."
|
||||
PURGE_SUCCESS: "Data purge successful."
|
||||
RAM_STATS: "{0}GB / {1}GB RAM"
|
||||
RELOAD_STARTED: "Reloading configuration - please wait."
|
||||
RELOAD_SUCCESS: "Configuration successfully reloaded."
|
||||
ROLLBACK_ABORTED: "Rollback or restore aborted."
|
||||
@ -180,6 +182,7 @@ STATUS_CONSUMER: "Consumer: {0} {item|items} in queue."
|
||||
STATUS_DATABASE: "Database: Using {0}."
|
||||
STATUS_INTEGRATION: "{0}: Integration {enabled|disabled}."
|
||||
STATUS_LICENSE: "License: {0}"
|
||||
STATUS_SYSTEM: "System: {0}"
|
||||
STATUS_VERSION: "Version: {0}"
|
||||
TELEPORTED: "Teleported to {0}."
|
||||
TELEPORTED_SAFETY: "Teleported you to safety."
|
||||
|
12
pom.xml
12
pom.xml
@ -69,6 +69,8 @@
|
||||
<exclude>org.intellij:*</exclude>
|
||||
<exclude>org.jetbrains:*</exclude>
|
||||
<exclude>org.slf4j:*</exclude>
|
||||
<exclude>org.apache.logging.log4j:*</exclude>
|
||||
<exclude>net.java.dev.jna:*</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
@ -152,5 +154,15 @@
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>5.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jhardware</groupId>
|
||||
<artifactId>jHardware</artifactId>
|
||||
<version>0.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.23.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -54,7 +54,6 @@ public class StatusCommand {
|
||||
}
|
||||
|
||||
/*
|
||||
CoreProtect show RAM usage
|
||||
Items processed (since server start)
|
||||
Items processed (last 60 minutes)
|
||||
*/
|
||||
@ -102,6 +101,42 @@ public class StatusCommand {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
String cpuInfo = "";
|
||||
if (ConfigHandler.processorInfo != null) {
|
||||
String modelName = ConfigHandler.processorInfo.getModelName();
|
||||
if (modelName.contains(" CPU")) {
|
||||
String[] split = ConfigHandler.processorInfo.getModelName().split(" CPU")[0].split(" ");
|
||||
modelName = split[split.length - 1];
|
||||
}
|
||||
else if (modelName.contains(" Processor")) {
|
||||
String[] split = ConfigHandler.processorInfo.getModelName().split(" Processor")[0].split(" ");
|
||||
modelName = split[split.length - 1];
|
||||
}
|
||||
|
||||
String cpuSpeed = ConfigHandler.processorInfo.getMhz();
|
||||
cpuSpeed = String.format("%.2f", Double.valueOf(cpuSpeed) / 1000.0);
|
||||
cpuInfo = modelName + " " + Runtime.getRuntime().availableProcessors() + " x " + cpuSpeed + "GHz.";
|
||||
}
|
||||
else {
|
||||
cpuInfo = "x" + Runtime.getRuntime().availableProcessors() + " " + Phrase.build(Phrase.CPU_CORES);
|
||||
}
|
||||
|
||||
int mb = 1024 * 1024;
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
String usedRAM = String.format("%.2f", Double.valueOf((runtime.totalMemory() - runtime.freeMemory()) / mb) / 1000.0);
|
||||
String totalRAM = String.format("%.2f", Double.valueOf(runtime.maxMemory() / mb) / 1000.0);
|
||||
String systemInformation = Phrase.build(Phrase.RAM_STATS, usedRAM, totalRAM);
|
||||
if (cpuInfo.length() > 0) {
|
||||
systemInformation = cpuInfo + " (" + systemInformation + ")";
|
||||
}
|
||||
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + Phrase.build(Phrase.STATUS_SYSTEM, Color.WHITE, systemInformation));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Functions.sendMessage(player, Color.DARK_AQUA + "Website: " + Color.WHITE + "www.coreprotect.net/updates/");
|
||||
|
||||
// Functions.sendMessage(player, Color.DARK_AQUA + Phrase.build(Phrase.LINK_DISCORD, Color.WHITE + "www.coreprotect.net/discord/").replaceFirst(":", ":" + Color.WHITE));
|
||||
|
@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jutils.jhardware.model.ProcessorInfo;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
@ -55,6 +56,7 @@ public class ConfigHandler extends Queue {
|
||||
public static int maximumPoolSize = 10;
|
||||
|
||||
public static HikariDataSource hikariDataSource = null;
|
||||
public static final ProcessorInfo processorInfo = Util.getProcessorInfo();
|
||||
public static final boolean isSpigot = Util.isSpigot();
|
||||
public static final boolean isPaper = Util.isPaper();
|
||||
public static final boolean isFolia = Util.isFolia();
|
||||
|
@ -44,6 +44,7 @@ public class Language {
|
||||
phrases.put(Phrase.CONSUMER_ERROR, "Consumer queue processing already {paused|resumed}.");
|
||||
phrases.put(Phrase.CONSUMER_TOGGLED, "Consumer queue processing has been {paused|resumed}.");
|
||||
phrases.put(Phrase.CONTAINER_HEADER, "Container Transactions");
|
||||
phrases.put(Phrase.CPU_CORES, "CPU cores.");
|
||||
phrases.put(Phrase.DATABASE_BUSY, "Database busy. Please try again later.");
|
||||
phrases.put(Phrase.DATABASE_INDEX_ERROR, "Unable to validate database indexes.");
|
||||
phrases.put(Phrase.DATABASE_LOCKED_1, "Database locked. Waiting up to 15 seconds...");
|
||||
@ -188,6 +189,7 @@ public class Language {
|
||||
phrases.put(Phrase.PURGE_ROWS, "{0} {row|rows} of data deleted.");
|
||||
phrases.put(Phrase.PURGE_STARTED, "Data purge started on \"{0}\".");
|
||||
phrases.put(Phrase.PURGE_SUCCESS, "Data purge successful.");
|
||||
phrases.put(Phrase.RAM_STATS, "{0}GB / {1}GB RAM");
|
||||
phrases.put(Phrase.RELOAD_STARTED, "Reloading configuration - please wait.");
|
||||
phrases.put(Phrase.RELOAD_SUCCESS, "Configuration successfully reloaded.");
|
||||
phrases.put(Phrase.ROLLBACK_ABORTED, "Rollback or restore aborted.");
|
||||
@ -209,6 +211,7 @@ public class Language {
|
||||
phrases.put(Phrase.STATUS_DATABASE, "Database: Using {0}.");
|
||||
phrases.put(Phrase.STATUS_INTEGRATION, "{0}: Integration {enabled|disabled}.");
|
||||
phrases.put(Phrase.STATUS_LICENSE, "License: {0}");
|
||||
phrases.put(Phrase.STATUS_SYSTEM, "System: {0}");
|
||||
phrases.put(Phrase.STATUS_VERSION, "Version: {0}");
|
||||
phrases.put(Phrase.TELEPORTED, "Teleported to {0}.");
|
||||
phrases.put(Phrase.TELEPORTED_SAFETY, "Teleported you to safety.");
|
||||
|
@ -27,6 +27,7 @@ public enum Phrase {
|
||||
CONSUMER_ERROR,
|
||||
CONSUMER_TOGGLED,
|
||||
CONTAINER_HEADER,
|
||||
CPU_CORES,
|
||||
DATABASE_BUSY,
|
||||
DATABASE_INDEX_ERROR,
|
||||
DATABASE_LOCKED_1,
|
||||
@ -171,6 +172,7 @@ public enum Phrase {
|
||||
PURGE_ROWS,
|
||||
PURGE_STARTED,
|
||||
PURGE_SUCCESS,
|
||||
RAM_STATS,
|
||||
RELOAD_STARTED,
|
||||
RELOAD_SUCCESS,
|
||||
ROLLBACK_ABORTED,
|
||||
@ -192,6 +194,7 @@ public enum Phrase {
|
||||
STATUS_DATABASE,
|
||||
STATUS_INTEGRATION,
|
||||
STATUS_LICENSE,
|
||||
STATUS_SYSTEM,
|
||||
STATUS_VERSION,
|
||||
TELEPORTED,
|
||||
TELEPORTED_SAFETY,
|
||||
|
@ -21,6 +21,8 @@ import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -51,6 +53,8 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.jutils.jhardware.HardwareInfo;
|
||||
import org.jutils.jhardware.model.ProcessorInfo;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
@ -112,6 +116,19 @@ public class Util extends Queue {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static ProcessorInfo getProcessorInfo() {
|
||||
ProcessorInfo result = null;
|
||||
try {
|
||||
Configurator.setLevel("com.profesorfalken.jsensors.manager.unix.UnixSensorsManager", Level.WARN);
|
||||
result = HardwareInfo.getProcessorInfo();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// unable to read processor information
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int getBlockId(Material material) {
|
||||
if (material == null) {
|
||||
material = Material.AIR;
|
||||
|
Loading…
Reference in New Issue
Block a user