Added CPU & RAM information to /co status
This commit is contained in:
parent
e093970992
commit
dbd8723752
7 changed files with 77 additions and 2 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue