logging busiest uids

This commit is contained in:
Miodec 2022-10-28 14:39:33 +02:00
parent 8389970963
commit b00e5d893e
2 changed files with 15 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import {
incrementAuth,
recordAuthTime,
recordRequestCountry,
recordRequestForUid,
} from "../utils/prometheus";
import { performance } from "perf_hooks";
@ -94,6 +95,10 @@ function authenticateRequest(authOptions = DEFAULT_OPTIONS): Handler {
recordRequestCountry(country, req as MonkeyTypes.Request);
}
if (req.method !== "OPTIONS" && req?.ctx?.decodedToken?.uid) {
recordRequestForUid(req.ctx.decodedToken.uid);
}
next();
};
}

View file

@ -257,3 +257,13 @@ const tokenCacheLength = new Gauge({
export function setTokenCacheLength(length: number): void {
tokenCacheLength.set(length);
}
const uidRequestCount = new Counter({
name: "user_request_count",
help: "Request count per uid",
labelNames: ["uid"],
});
export function recordRequestForUid(uid: string): void {
uidRequestCount.inc({ uid });
}