Phase 1: lock cron, reload chaud, argon2, providers, IMDb lookup, cache LRU, /health, /metrics, rate limit, UI dark, biome

This commit is contained in:
unfr
2026-04-24 07:35:10 +02:00
parent f9745a2390
commit a184a21f57
36 changed files with 2060 additions and 364 deletions

46
lib/metrics.js Normal file
View File

@@ -0,0 +1,46 @@
// Prometheus metrics. Reusable counters/histograms for the API + cache.
import { Counter, collectDefaultMetrics, Gauge, Histogram, Registry } from 'prom-client';
export const registry = new Registry();
collectDefaultMetrics({ register: registry });
export const httpRequests = new Counter({
name: 'http_requests_total',
help: 'Total HTTP requests',
labelNames: ['method', 'route', 'status'],
registers: [registry],
});
export const httpDuration = new Histogram({
name: 'http_request_duration_seconds',
help: 'HTTP request duration in seconds',
labelNames: ['method', 'route', 'status'],
buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2, 5],
registers: [registry],
});
export const searchCacheHits = new Counter({
name: 'search_cache_hits_total',
help: 'Number of search results served from the LRU cache',
registers: [registry],
});
export const searchCacheMisses = new Counter({
name: 'search_cache_misses_total',
help: 'Number of search requests that bypassed the cache',
registers: [registry],
});
export const imdbRatingsCount = new Gauge({
name: 'imdb_ratings_total',
help: 'Number of IMDb ratings currently loaded in memory',
registers: [registry],
});
export const searchWorkers = new Gauge({
name: 'search_workers',
help: 'Number of active search workers per type',
labelNames: ['type'],
registers: [registry],
});