mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Add command to monitor plugin load performance
This commit is contained in:
parent
e95987a766
commit
05c2434efc
3 changed files with 27 additions and 0 deletions
|
@ -18,11 +18,13 @@ import { ReloadServerCmd } from "./commands/ReloadServerCmd";
|
||||||
import { RemoveDashboardUserCmd } from "./commands/RemoveDashboardUserCmd";
|
import { RemoveDashboardUserCmd } from "./commands/RemoveDashboardUserCmd";
|
||||||
import { ServersCmd } from "./commands/ServersCmd";
|
import { ServersCmd } from "./commands/ServersCmd";
|
||||||
import { BotControlPluginType, ConfigSchema } from "./types";
|
import { BotControlPluginType, ConfigSchema } from "./types";
|
||||||
|
import { PerformanceCmd } from "./commands/PerformanceCmd";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
config: {
|
config: {
|
||||||
can_use: false,
|
can_use: false,
|
||||||
can_eligible: false,
|
can_eligible: false,
|
||||||
|
can_performance: false,
|
||||||
update_cmd: null,
|
update_cmd: null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -45,6 +47,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
|
||||||
ListDashboardUsersCmd,
|
ListDashboardUsersCmd,
|
||||||
ListDashboardPermsCmd,
|
ListDashboardPermsCmd,
|
||||||
EligibleCmd,
|
EligibleCmd,
|
||||||
|
PerformanceCmd,
|
||||||
],
|
],
|
||||||
|
|
||||||
async afterLoad(pluginData) {
|
async afterLoad(pluginData) {
|
||||||
|
|
23
backend/src/plugins/BotControl/commands/PerformanceCmd.ts
Normal file
23
backend/src/plugins/BotControl/commands/PerformanceCmd.ts
Normal 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);
|
||||||
|
},
|
||||||
|
});
|
|
@ -9,6 +9,7 @@ import { tNullable } from "../../utils";
|
||||||
export const ConfigSchema = t.type({
|
export const ConfigSchema = t.type({
|
||||||
can_use: t.boolean,
|
can_use: t.boolean,
|
||||||
can_eligible: t.boolean,
|
can_eligible: t.boolean,
|
||||||
|
can_performance: t.boolean,
|
||||||
update_cmd: tNullable(t.string),
|
update_cmd: tNullable(t.string),
|
||||||
});
|
});
|
||||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue