Merge pull request #38 from movie-web/scrapetools

Add tool metrics
This commit is contained in:
William Oldham 2024-01-25 21:29:24 +00:00 committed by GitHub
commit b0f5b28084
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "backend",
"version": "1.3.0",
"version": "1.3.1",
"private": true,
"homepage": "https://github.com/movie-web/backend",
"engines": {

View File

@ -13,6 +13,7 @@ export type Metrics = {
providerHostnames: Counter<'hostname'>;
providerStatuses: Counter<'provider_id' | 'status'>;
watchMetrics: Counter<'title' | 'tmdb_full_id' | 'provider_id' | 'success'>;
toolMetrics: Counter<'tool'>;
};
let metrics: null | Metrics = null;
@ -59,6 +60,11 @@ export async function setupMetrics(app: FastifyInstance) {
help: 'mw_media_watch_count',
labelNames: ['title', 'tmdb_full_id', 'provider_id', 'success'],
}),
toolMetrics: new Counter({
name: 'mw_provider_tool_count',
help: 'mw_provider_tool_count',
labelNames: ['tool'],
}),
};
const promClient = app.metrics.client;
@ -68,6 +74,7 @@ export async function setupMetrics(app: FastifyInstance) {
promClient.register.registerMetric(metrics.providerStatuses);
promClient.register.registerMetric(metrics.watchMetrics);
promClient.register.registerMetric(metrics.captchaSolves);
promClient.register.registerMetric(metrics.toolMetrics);
const orm = getORM();
const em = orm.em.fork();

View File

@ -19,6 +19,7 @@ const metricsProviderSchema = z.object({
const metricsProviderInputSchema = z.object({
items: z.array(metricsProviderSchema).max(10).min(1),
tool: z.string().optional(),
});
export const metricsRouter = makeRouter((app) => {
@ -65,6 +66,12 @@ export const metricsRouter = makeRouter((app) => {
});
}
if (body.tool) {
getMetrics().toolMetrics.inc({
tool: body.tool,
});
}
return true;
}),
);