add: metrics for taking snapshot
This commit is contained in:
parent
e88d77d135
commit
1835591052
@ -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(
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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"
|
||||
});
|
||||
@ -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) {
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user