3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 04:25:01 +00:00

Add command to monitor plugin load performance

This commit is contained in:
Dragory 2021-09-04 22:11:38 +03:00
parent e95987a766
commit 05c2434efc
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import { TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { createChunkedMessage, formatNumber, resolveInvite, sorter, verboseUserMention } from "../../../utils";
import { botControlCmd } from "../types";
export const PerformanceCmd = botControlCmd({
trigger: ["performance"],
permission: "can_performance",
signature: {},
async run({ pluginData, message: msg, args }) {
const stats = pluginData.getKnubInstance().getPluginPerformanceStats();
const averageLoadTimeEntries = Object.entries(stats.averageLoadTimes);
averageLoadTimeEntries.sort(sorter(v => v[1].time, "DESC"));
const lines = averageLoadTimeEntries.map(
([pluginName, { time }]) => `${pluginName}: **${formatNumber(Math.round(time))}ms**`,
);
const fullStats = `Average plugin load times:\n\n${lines.join("\n")}`;
createChunkedMessage(msg.channel as TextChannel, fullStats);
},
});