mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-05 23:15:08 +08:00
added cron job to log collection sizes
This commit is contained in:
parent
2b0ccbe44c
commit
921aa94dc7
3 changed files with 37 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import updateLeaderboards from "./update-leaderboards";
|
||||
import deleteOldLogs from "./delete-old-logs";
|
||||
import logCollectionSizes from "./log-collection-sizes";
|
||||
|
||||
export default [updateLeaderboards, deleteOldLogs];
|
||||
export default [updateLeaderboards, deleteOldLogs, logCollectionSizes];
|
||||
|
|
|
|||
25
backend/src/jobs/log-collection-sizes.ts
Normal file
25
backend/src/jobs/log-collection-sizes.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { CronJob } from "cron";
|
||||
import * as db from "../init/db";
|
||||
import * as Prometheus from "../utils/prometheus";
|
||||
|
||||
const CRON_SCHEDULE = "0 0 * * * *";
|
||||
|
||||
function main(): void {
|
||||
Promise.all([
|
||||
set("ape-keys"),
|
||||
set("configs"),
|
||||
set("errors"),
|
||||
set("logs"),
|
||||
set("presets"),
|
||||
set("reports"),
|
||||
set("results"),
|
||||
set("users"),
|
||||
]);
|
||||
}
|
||||
|
||||
async function set(collection: string): Promise<void> {
|
||||
const size = await db.collection(collection).estimatedDocumentCount();
|
||||
Prometheus.setCollectionSize(collection, size);
|
||||
}
|
||||
|
||||
export default new CronJob(CRON_SCHEDULE, main);
|
||||
|
|
@ -267,3 +267,13 @@ const uidRequestCount = new Counter({
|
|||
export function recordRequestForUid(uid: string): void {
|
||||
uidRequestCount.inc({ uid });
|
||||
}
|
||||
|
||||
const collectionSize = new Gauge({
|
||||
name: "db_collection_size",
|
||||
help: "Size of a collection",
|
||||
labelNames: ["collection"],
|
||||
});
|
||||
|
||||
export function setCollectionSize(collection: string, size: number): void {
|
||||
collectionSize.set({ collection }, size);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue