Add tool metrics

This commit is contained in:
mrjvs 2024-01-25 22:24:58 +01:00
parent 06ad2249d6
commit 4af2d32b72
2 changed files with 14 additions and 0 deletions

View File

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

View File

@ -19,6 +19,7 @@ const metricsProviderSchema = z.object({
const metricsProviderInputSchema = z.object({ const metricsProviderInputSchema = z.object({
items: z.array(metricsProviderSchema).max(10).min(1), items: z.array(metricsProviderSchema).max(10).min(1),
tool: z.string().optional(),
}); });
export const metricsRouter = makeRouter((app) => { 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; return true;
}), }),
); );