make ping metric not rely on system time

This commit is contained in:
janderedev 2022-02-12 15:34:55 +01:00
parent 75ad95a357
commit 69f05dc184
Signed by: Lea
GPG key ID: 5D5E18ACB990F57A

View file

@ -2,7 +2,6 @@ import prom from 'prom-client';
import http from 'http'; import http from 'http';
import logger from '../logger'; import logger from '../logger';
import { client } from '../..'; import { client } from '../..';
import { decodeTime } from 'ulid';
const PORT = Number(process.env.BOT_METRICS_PORT); const PORT = Number(process.env.BOT_METRICS_PORT);
@ -56,7 +55,7 @@ if (!isNaN(PORT)) {
const msg = await channel?.sendMessage('Ping?'); const msg = await channel?.sendMessage('Ping?');
if (!msg) return; if (!msg) return;
const delay = decodeTime(msg._id) - now; const delay = Date.now() - now;
metrics.msgPing.set(delay); metrics.msgPing.set(delay);
await msg.edit({ content: `Pong! ${delay}ms` }); await msg.edit({ content: `Pong! ${delay}ms` });
} catch(e) { console.error(e) } } catch(e) { console.error(e) }