mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
fix: 修复mi lag命令参数错误报错 百分比显示能耗
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
50bbe6ff40
commit
c7fc35ab7e
6
pom.xml
6
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>Yum</artifactId>
|
<artifactId>Yum</artifactId>
|
||||||
<version>2.7.1</version>
|
<version>2.7.2</version>
|
||||||
<name>Yum</name>
|
<name>Yum</name>
|
||||||
<description>Minecraft 服务器插件管理系统</description>
|
<description>Minecraft 服务器插件管理系统</description>
|
||||||
<build>
|
<build>
|
||||||
@ -66,10 +66,8 @@
|
|||||||
<update.description>§a全新 2.X 版本 更多守护与优化</update.description>
|
<update.description>§a全新 2.X 版本 更多守护与优化</update.description>
|
||||||
<update.changes>
|
<update.changes>
|
||||||
§c注意 §6- §aYum更新需要§d重启服务器!§c重启服务器!§4重启服务器!;
|
§c注意 §6- §aYum更新需要§d重启服务器!§c重启服务器!§4重启服务器!;
|
||||||
|
§b2.7.2 §6- §c修复mi lag命令参数错误报错 §d百分比显示能耗...;
|
||||||
§b2.7.1 §6- §c修复部分BUG(load可直接载入文件)...;
|
§b2.7.1 §6- §c修复部分BUG(load可直接载入文件)...;
|
||||||
§b2.7.0 §6- §d完善能耗监控流程...;
|
|
||||||
§b §6- §c报错§6/§d能耗§a添加日志记录;
|
|
||||||
§b §6- §a文件处理添加复制命令;
|
|
||||||
</update.changes>
|
</update.changes>
|
||||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -46,6 +46,7 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
|
|
||||||
private final String prefix = "§6[§bYum §a能耗监控§6] ";
|
private final String prefix = "§6[§bYum §a能耗监控§6] ";
|
||||||
|
|
||||||
|
private final String no_mi = prefix + "§6%s §a自服务器启动以来尚未执行任何操作";
|
||||||
private final String micprefix = " §6命令名称 §a总耗时 §b执行次数 §d平均耗时";
|
private final String micprefix = " §6命令名称 §a总耗时 §b执行次数 §d平均耗时";
|
||||||
private final String mieprefix = " §6事件名称 §a总耗时 §b执行次数 §d平均耗时";
|
private final String mieprefix = " §6事件名称 §a总耗时 §b执行次数 §d平均耗时";
|
||||||
private final String mitprefix = " §6任务名称 §a总耗时 §b执行次数 §d平均耗时";
|
private final String mitprefix = " §6任务名称 §a总耗时 §b执行次数 §d平均耗时";
|
||||||
@ -57,8 +58,9 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
private final String uninjected = prefix + "§a插件 §b%s §a成功撤销能耗监控器!";
|
private final String uninjected = prefix + "§a插件 §b%s §a成功撤销能耗监控器!";
|
||||||
private final String notEnable = prefix + "§c插件 §b%s §c未成功加载 无法执行注入!";
|
private final String notEnable = prefix + "§c插件 §b%s §c未成功加载 无法执行注入!";
|
||||||
|
|
||||||
private final String lagprefix = " §6插件名称 §c主线程耗时 §a命令耗时 §b事件耗时 §d任务耗时";
|
private final String lag = prefix + "§a当前服务器插件能耗如下§6(单位: %)";
|
||||||
private final String laglist = "§6%-2s §b%-15s §c%-11.2f §a%-9.2f §b%-9.2f §d%-9.2f";
|
private final String lagprefix = " §6插件名称 §c主线程 §a命令 §b事件 §d任务";
|
||||||
|
private final String laglist = "§6%-2s §b%-20s §c%-25s §a%-5.2f §b%-5.2f §d%-5.2f";
|
||||||
|
|
||||||
private final String no_error = prefix + "§a自服务器启动以来尚未发现报错!";
|
private final String no_error = prefix + "§a自服务器启动以来尚未发现报错!";
|
||||||
private final String last_error = prefix + "§c最后一次错误异常由 §b%s §c造成 详细如下:";
|
private final String last_error = prefix + "§c最后一次错误异常由 §b%s §c造成 详细如下:";
|
||||||
@ -94,6 +96,10 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (temp.isEmpty()) {
|
||||||
|
sender.sendMessage(String.format(no_mi, pname));
|
||||||
|
return;
|
||||||
|
}
|
||||||
sender.sendMessage(micprefix);
|
sender.sendMessage(micprefix);
|
||||||
for (final Entry<String, Command> command : temp.entrySet()) {
|
for (final Entry<String, Command> command : temp.entrySet()) {
|
||||||
final org.bukkit.command.CommandExecutor executor = Reflect.on(command.getValue()).get("executor");
|
final org.bukkit.command.CommandExecutor executor = Reflect.on(command.getValue()).get("executor");
|
||||||
@ -150,6 +156,10 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (eventTotalTime.isEmpty()) {
|
||||||
|
sender.sendMessage(String.format(no_mi, pname));
|
||||||
|
return;
|
||||||
|
}
|
||||||
sender.sendMessage(mieprefix);
|
sender.sendMessage(mieprefix);
|
||||||
for (final String event : MonitorManager.sortMapByValue(eventTotalTime).keySet()) {
|
for (final String event : MonitorManager.sortMapByValue(eventTotalTime).keySet()) {
|
||||||
final double avgTime = eventTotalTime.get(event) / um / eventCount.get(event);
|
final double avgTime = eventTotalTime.get(event) / um / eventCount.get(event);
|
||||||
@ -182,14 +192,19 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
final CommandSender sender = e.getSender();
|
final CommandSender sender = e.getSender();
|
||||||
final Map<String, Long> mm = MonitorManager.getMonitor();
|
final Map<String, Long> mm = MonitorManager.getMonitor();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
final int max = e.getArgs().length > 0 ? Integer.parseInt(e.getArgs()[0]) : 8;
|
int max = 8;
|
||||||
|
try {
|
||||||
|
max = Integer.parseInt(e.getArgs()[0]);
|
||||||
|
} catch (final Exception ignore) {
|
||||||
|
}
|
||||||
|
sender.sendMessage(lag);
|
||||||
sender.sendMessage(lagprefix);
|
sender.sendMessage(lagprefix);
|
||||||
for (final Entry<String, Long> entry : mm.entrySet()) {
|
for (final Entry<String, Long> entry : mm.entrySet()) {
|
||||||
if (++i > max) {
|
if (++i > max) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final MonitorInfo mi = MonitorManager.getMonitorInfo(entry.getKey());
|
final MonitorInfo mi = MonitorManager.getMonitorInfo(entry.getKey());
|
||||||
sender.sendMessage(String.format(laglist, i, entry.getKey(), mi.monitor, mi.cmd, mi.event, mi.task));
|
sender.sendMessage(String.format(laglist, i, entry.getKey(), getPer(mi.monitor), mi.cmd, mi.event, mi.task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +249,10 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks();
|
final List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks();
|
||||||
|
if (pendingTasks.isEmpty()) {
|
||||||
|
sender.sendMessage(String.format(no_mi, pname));
|
||||||
|
return;
|
||||||
|
}
|
||||||
sender.sendMessage(prefix + "§6插件 §b" + pname + " §6的任务能耗如下!");
|
sender.sendMessage(prefix + "§6插件 §b" + pname + " §6的任务能耗如下!");
|
||||||
sender.sendMessage(mitprefix);
|
sender.sendMessage(mitprefix);
|
||||||
for (final BukkitTask pendingTask : pendingTasks) {
|
for (final BukkitTask pendingTask : pendingTasks) {
|
||||||
@ -271,4 +290,27 @@ public class MonitorCommand implements CommandExecutor {
|
|||||||
private String getClassName(final Class<?> clazz) {
|
private String getClassName(final Class<?> clazz) {
|
||||||
return StrKit.isBlank(clazz.getSimpleName()) ? clazz.getName().substring(clazz.getName().lastIndexOf(".") + 1) : clazz.getSimpleName();
|
return StrKit.isBlank(clazz.getSimpleName()) ? clazz.getName().substring(clazz.getName().lastIndexOf(".") + 1) : clazz.getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getPer(final double per) {
|
||||||
|
final double p = per / 5;
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
if (p < 4) {
|
||||||
|
sb.append("§a");
|
||||||
|
} else if (p < 7) {
|
||||||
|
sb.append("§d");
|
||||||
|
} else if (p < 10) {
|
||||||
|
sb.append("§c");
|
||||||
|
} else {
|
||||||
|
sb.append("§4");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 11; i++) {
|
||||||
|
if (p > i) {
|
||||||
|
sb.append("|");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (per > 0) {
|
||||||
|
sb.append(String.format("% 3.2f", per));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class NetCommand implements CommandExecutor {
|
|||||||
|
|
||||||
private final String showlist = prefix + "§a自服务器启动以来尝试联网的插件列表如下:";
|
private final String showlist = prefix + "§a自服务器启动以来尝试联网的插件列表如下:";
|
||||||
private final String listprefix = " §6插件名称 §d联网次数";
|
private final String listprefix = " §6插件名称 §d联网次数";
|
||||||
private final String list = "§6- §b%s §d%s";
|
private final String list = "§6- §b%-20s §d%s";
|
||||||
private final String no_net = prefix + "§a尚未检测到尝试联网的插件!";
|
private final String no_net = prefix + "§a尚未检测到尝试联网的插件!";
|
||||||
private final String add = prefix + "§a已添加插件 §b%s §a到网络 %s §a列表!";
|
private final String add = prefix + "§a已添加插件 §b%s §a到网络 %s §a列表!";
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package pw.yumc.Yum.managers;
|
package pw.yumc.Yum.managers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -36,6 +37,8 @@ public class MonitorManager {
|
|||||||
public final static boolean debug = ConfigManager.i().isMonitorDebug();
|
public final static boolean debug = ConfigManager.i().isMonitorDebug();
|
||||||
public final static boolean log_to_file = ConfigManager.i().isLogToFile();
|
public final static boolean log_to_file = ConfigManager.i().isLogToFile();
|
||||||
|
|
||||||
|
private static double totalTime = 0;
|
||||||
|
|
||||||
private final static Map<String, Long> monitor = new ConcurrentHashMap<>();
|
private final static Map<String, Long> monitor = new ConcurrentHashMap<>();
|
||||||
private final static Map<String, Long> task = new ConcurrentHashMap<>();
|
private final static Map<String, Long> task = new ConcurrentHashMap<>();
|
||||||
private final static Map<String, Long> event = new ConcurrentHashMap<>();
|
private final static Map<String, Long> event = new ConcurrentHashMap<>();
|
||||||
@ -71,7 +74,8 @@ public class MonitorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MonitorInfo getMonitorInfo(final String pname) {
|
public static MonitorInfo getMonitorInfo(final String pname) {
|
||||||
return new MonitorInfo(monitor.get(pname) / um, cmd.get(pname) / um, event.get(pname) / um, task.get(pname) / um);
|
final double per = 100.00;
|
||||||
|
return new MonitorInfo(monitor.get(pname) / totalTime * per, cmd.get(pname) / totalTime * per, event.get(pname) / totalTime * per, task.get(pname) / totalTime * per);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
@ -123,7 +127,7 @@ public class MonitorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendObject(final CommandSender sender) {
|
public static void sendObject(final CommandSender sender) {
|
||||||
sender.sendMessage(String.format("monitor@%s cmd@%s event@%s task@%s", monitor.hashCode(), cmd.hashCode(), event.hashCode(), task.hashCode()));
|
sender.sendMessage(String.format("totalTime@%s monitor@%s cmd@%s event@%s task@%s", totalTime, sum(monitor.values()), sum(cmd.values()), sum(event.values()), sum(task.values())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,11 +154,20 @@ public class MonitorManager {
|
|||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
private static void add(final String pname, final long time, final Map<String, Long>... maps) {
|
private static void add(final String pname, final long time, final Map<String, Long>... maps) {
|
||||||
|
totalTime += time;
|
||||||
for (final Map<String, Long> map : maps) {
|
for (final Map<String, Long> map : maps) {
|
||||||
map.put(pname, map.get(pname) + time);
|
map.put(pname, map.get(pname) + time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long sum(final Collection<? extends Long> numbers) {
|
||||||
|
int result = 0;
|
||||||
|
for (final Long num : numbers) {
|
||||||
|
result += num;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static class MonitorInfo {
|
public static class MonitorInfo {
|
||||||
public double monitor;
|
public double monitor;
|
||||||
public double cmd;
|
public double cmd;
|
||||||
|
Loading…
Reference in New Issue
Block a user