mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 12:43:26 +00:00
Add captcha solves metric
This commit is contained in:
@@ -9,6 +9,7 @@ const log = scopedLogger('metrics');
|
|||||||
|
|
||||||
export type Metrics = {
|
export type Metrics = {
|
||||||
user: Counter<'namespace'>;
|
user: Counter<'namespace'>;
|
||||||
|
captchaSolves: Counter<'success'>;
|
||||||
providerHostnames: Counter<'hostname'>;
|
providerHostnames: Counter<'hostname'>;
|
||||||
providerStatuses: Counter<'provider_id' | 'status'>;
|
providerStatuses: Counter<'provider_id' | 'status'>;
|
||||||
watchMetrics: Counter<'title' | 'tmdb_full_id' | 'provider_id' | 'success'>;
|
watchMetrics: Counter<'title' | 'tmdb_full_id' | 'provider_id' | 'success'>;
|
||||||
@@ -38,6 +39,11 @@ export async function setupMetrics(app: FastifyInstance) {
|
|||||||
help: 'mw_user_help',
|
help: 'mw_user_help',
|
||||||
labelNames: ['namespace'],
|
labelNames: ['namespace'],
|
||||||
}),
|
}),
|
||||||
|
captchaSolves: new Counter({
|
||||||
|
name: 'mw_captcha_solves',
|
||||||
|
help: 'mw_captcha_solves',
|
||||||
|
labelNames: ['success'],
|
||||||
|
}),
|
||||||
providerHostnames: new Counter({
|
providerHostnames: new Counter({
|
||||||
name: 'mw_provider_hostname_count',
|
name: 'mw_provider_hostname_count',
|
||||||
help: 'mw_provider_hostname_count',
|
help: 'mw_provider_hostname_count',
|
||||||
|
@@ -58,7 +58,7 @@ export const metricsRouter = makeRouter((app) => {
|
|||||||
|
|
||||||
if (lastItem) {
|
if (lastItem) {
|
||||||
getMetrics().watchMetrics.inc({
|
getMetrics().watchMetrics.inc({
|
||||||
tmdb_full_id: lastItem.tmdbId,
|
tmdb_full_id: lastItem.type + '-' + lastItem.tmdbId,
|
||||||
provider_id: lastSuccessfulItem?.providerId ?? lastItem.providerId,
|
provider_id: lastSuccessfulItem?.providerId ?? lastItem.providerId,
|
||||||
title: lastItem.title,
|
title: lastItem.title,
|
||||||
success: (!!lastSuccessfulItem).toString(),
|
success: (!!lastSuccessfulItem).toString(),
|
||||||
@@ -68,4 +68,29 @@ export const metricsRouter = makeRouter((app) => {
|
|||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.post(
|
||||||
|
'/metrics/captcha',
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
body: z.object({
|
||||||
|
success: z.boolean(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
handle(async ({ body, req, limiter }) => {
|
||||||
|
await limiter?.assertAndBump(req, {
|
||||||
|
id: 'captcha_solves',
|
||||||
|
max: 300,
|
||||||
|
inc: 1,
|
||||||
|
window: '30m',
|
||||||
|
});
|
||||||
|
|
||||||
|
getMetrics().captchaSolves.inc({
|
||||||
|
success: body.success.toString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user