1
0

add: metrics for taking snapshot

This commit is contained in:
alikia2x (寒寒) 2025-12-09 04:36:58 +08:00
parent e88d77d135
commit 1835591052
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6
5 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { redis } from "@core/db/redis";
import { ErrorResponseSchema } from "@backend/src/schema";
import type { VideoInfoData } from "@core/net/bilibili.d.ts";
import { BiliAPIVideoMetadataSchema } from "@backend/lib/schema";
import { snapshotCounter } from "@crawler/metrics";
export async function retrieveVideoInfoFromCache(aid: number) {
const cacheKey = `cvsa:videoInfo:av${aid}`;
@ -41,6 +42,7 @@ async function insertVideoSnapshot(data: VideoInfoData) {
shares,
favorites
});
snapshotCounter.add(1);
}
export const getVideoMetadataHandler = new Elysia({ prefix: "/video" }).get(

View File

@ -3,9 +3,11 @@ import type { Psql } from "@core/db/psql.d";
import { db, LatestVideoSnapshotType, videoSnapshot, VideoSnapshotType } from "@core/drizzle";
import { PartialBy } from "@core/lib";
import { sql } from "drizzle-orm";
import { snapshotCounter } from "metrics";
export async function insertVideoSnapshot(data: PartialBy<VideoSnapshotType, "id">) {
await db.insert(videoSnapshot).values(data);
snapshotCounter.add(1);
}
export async function getVideosNearMilestone() {

View File

@ -27,3 +27,7 @@ export const queueJobsCounter = meter.createGauge("queue_jobs_count", {
export const jobDurationRaw = meter.createGauge("job_duration_raw", {
description: "Execution duration of BullMQ jobs in milliseconds"
});
export const snapshotCounter = meter.createCounter("snapshot_count", {
description: "Number of snapshots taken"
});

View File

@ -11,6 +11,7 @@ import { insertIntoSongs } from "mq/task/collectSongs";
import { bilibiliUser, db, videoSnapshot } from "@core/drizzle";
import { eq } from "drizzle-orm";
import { GetVideoInfoJobData } from "mq/schema";
import { snapshotCounter } from "metrics";
interface AddSongEventPayload {
eventName: string;
@ -100,6 +101,8 @@ export const getVideoInfoWorker = async (job: Job<GetVideoInfoJobData>): Promise
favorites: stat.favorite
});
snapshotCounter.add(1);
logger.log(`Inserted video metadata for aid: ${aid}`, "mq");
if (!insertSongs) {

View File

@ -15,6 +15,7 @@ import { SnapshotScheduleType } from "@core/db/schema";
import { sql } from "@core/db/dbNew";
import { updateETA } from "db/eta";
import { closetMilestone } from "./snapshotTick";
import { snapshotCounter } from "metrics";
export const takeBulkSnapshotForVideosWorker = async (job: Job) => {
const schedules: SnapshotScheduleType[] = job.data.schedules;
@ -73,6 +74,8 @@ export const takeBulkSnapshotForVideosWorker = async (job: Job) => {
)
`;
snapshotCounter.add(1);
logger.log(
`Taken snapshot for video ${aid} in bulk.`,
"net",