Do measurements one at a time in order

This commit is contained in:
Madeline 2022-07-21 17:58:10 +10:00
parent 031c65cb09
commit 63687631ea

View File

@ -20,17 +20,14 @@ const client = new Fosscord.Client({
} }
}); });
client.on("ready", () => {
console.log(`Ready on gateway as ${client.user!.tag}`);
const gatewayMeasure = async (name: string) => { const gatewayMeasure = async (name: string) => {
const time = Math.max(client.ws.ping, 0); const time = Math.max(client.ws.ping, 0);
await savePerf(time, name, null); await savePerf(time, name, null);
console.log(`${name} took ${time}ms`); console.log(`${name} took ${time}ms`);
setTimeout(gatewayMeasure, parseInt(process.env.MEASURE_INTERVAL as string), name);
}; };
gatewayMeasure("websocketPing") client.on("ready", () => {
console.log(`Ready on gateway as ${client.user!.tag}`);
}); });
client.on("error", (error) => { client.on("error", (error) => {
@ -73,8 +70,6 @@ const measureApi = async (name: string, path: string, body?: object) => {
console.log(`${name} took ${time}ms ${(error ? "with error" : "")}`, error ?? ""); console.log(`${name} took ${time}ms ${(error ? "with error" : "")}`, error ?? "");
await savePerf(time, name, error?.message ?? null); await savePerf(time, name, error?.message ?? null);
setTimeout(measureApi, parseInt(process.env.MEASURE_INTERVAL as string), name, path, body);
}; };
const app = async () => { const app = async () => {
@ -84,8 +79,15 @@ const app = async () => {
console.log(`Monitoring performance for instance at ${new URL(instance.api).hostname}`); console.log(`Monitoring performance for instance at ${new URL(instance.api).hostname}`);
measureApi("ping", `${instance.api}/ping`); const doMeasurements = async () => {
measureApi("users/@me", `${instance.api}/users/@me`); await measureApi("ping", `${instance.api}/ping`);
await measureApi("users/@me", `${instance.api}/users/@me`);
await gatewayMeasure("websocketPing");
setTimeout(doMeasurements, parseInt(process.env.MEASURE_INTERVAL as string));
};
doMeasurements();
}; };
app(); app();