diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-21 17:58:10 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-21 17:58:10 +1000 |
commit | 63687631ea7b5231e3dcf5299c1c93c5750c039f (patch) | |
tree | 31b6352a8cd129dfd1d63ed865195d3b183e5a22 | |
parent | Added simple response time measurement for grafana (diff) | |
download | server-63687631ea7b5231e3dcf5299c1c93c5750c039f.tar.xz |
Do measurements one at a time in order
-rw-r--r-- | slowcord/status/src/index.ts | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/slowcord/status/src/index.ts b/slowcord/status/src/index.ts index a4d911ad..1ef062a1 100644 --- a/slowcord/status/src/index.ts +++ b/slowcord/status/src/index.ts @@ -20,17 +20,14 @@ const client = new Fosscord.Client({ } }); +const gatewayMeasure = async (name: string) => { + const time = Math.max(client.ws.ping, 0); + await savePerf(time, name, null); + console.log(`${name} took ${time}ms`); +}; + client.on("ready", () => { console.log(`Ready on gateway as ${client.user!.tag}`); - - const gatewayMeasure = async (name: string) => { - const time = Math.max(client.ws.ping, 0); - await savePerf(time, name, null); - console.log(`${name} took ${time}ms`); - setTimeout(gatewayMeasure, parseInt(process.env.MEASURE_INTERVAL as string), name); - }; - - gatewayMeasure("websocketPing") }); 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 ?? ""); await savePerf(time, name, error?.message ?? null); - - setTimeout(measureApi, parseInt(process.env.MEASURE_INTERVAL as string), name, path, body); }; const app = async () => { @@ -84,8 +79,15 @@ const app = async () => { console.log(`Monitoring performance for instance at ${new URL(instance.api).hostname}`); - measureApi("ping", `${instance.api}/ping`); - measureApi("users/@me", `${instance.api}/users/@me`); + const doMeasurements = async () => { + 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(); \ No newline at end of file |