diff --git a/lang/en.yml b/lang/en.yml index d2fcd5df..28aecf9f 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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." diff --git a/pom.xml b/pom.xml index 966b88ee..7dfab636 100755 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,8 @@ org.intellij:* org.jetbrains:* org.slf4j:* + org.apache.logging.log4j:* + net.java.dev.jna:* @@ -152,5 +154,15 @@ HikariCP 5.0.1 + + org.jhardware + jHardware + 0.8.6 + + + org.apache.logging.log4j + log4j-core + 2.23.1 + \ No newline at end of file diff --git a/src/main/java/net/coreprotect/command/StatusCommand.java b/src/main/java/net/coreprotect/command/StatusCommand.java index 2d806fc2..b6d1e497 100755 --- a/src/main/java/net/coreprotect/command/StatusCommand.java +++ b/src/main/java/net/coreprotect/command/StatusCommand.java @@ -54,7 +54,6 @@ public void run() { } /* - CoreProtect show RAM usage Items processed (since server start) Items processed (last 60 minutes) */ @@ -102,6 +101,42 @@ else if (instance.getServer().getPluginManager().getPlugin("WorldEdit") != null) 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)); diff --git a/src/main/java/net/coreprotect/config/ConfigHandler.java b/src/main/java/net/coreprotect/config/ConfigHandler.java index 36a35602..06be249b 100644 --- a/src/main/java/net/coreprotect/config/ConfigHandler.java +++ b/src/main/java/net/coreprotect/config/ConfigHandler.java @@ -19,6 +19,7 @@ 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(); diff --git a/src/main/java/net/coreprotect/language/Language.java b/src/main/java/net/coreprotect/language/Language.java index d390701e..918da473 100644 --- a/src/main/java/net/coreprotect/language/Language.java +++ b/src/main/java/net/coreprotect/language/Language.java @@ -44,6 +44,7 @@ public static void loadPhrases() { 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 static void loadPhrases() { 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 static void loadPhrases() { 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."); diff --git a/src/main/java/net/coreprotect/language/Phrase.java b/src/main/java/net/coreprotect/language/Phrase.java index b976e238..fc26ee7b 100644 --- a/src/main/java/net/coreprotect/language/Phrase.java +++ b/src/main/java/net/coreprotect/language/Phrase.java @@ -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, diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index 72306510..055096cb 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -21,6 +21,8 @@ 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.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 static String getPluginName() { 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;