// server/utils/metrics.ts import { Histogram } from 'prom-client'; import { register } from '../plugins/metrics'; export const externalCallDuration = new Histogram({ name: 'gay_cool__external_call_duration_seconds', help: 'Длительность внешнего запроса (например, к другим сервисам)', labelNames: ['service', 'status'], buckets: [0.05, 0.1, 0.3, 0.5, 1, 2, 5], registers: [register], }); export async function trackExternalCall( serviceName: string, fn: () => Promise ): Promise { const start = process.hrtime(); try { const result = await fn(); const [s, ns] = process.hrtime(start); externalCallDuration.observe({ service: serviceName, status: 'success' }, s + ns / 1e9); return result; } catch (e) { const [s, ns] = process.hrtime(start); externalCallDuration.observe({ service: serviceName, status: 'error' }, s + ns / 1e9); throw e; } }