UNPKG

@dudousxd/nestjs-telescope

Version:

Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.

67 lines 2.73 kB
import { type OnApplicationShutdown } from '@nestjs/common'; import type { ResolvedCoreConfig } from '../config/options.js'; export interface ServerStats { uptimeSec: number; memory: { rssMb: number; heapUsedMb: number; heapTotalMb: number; }; cpu: { userMs: number; systemMs: number; }; /** Mean event-loop delay in ms, or `null` when perf_hooks can't measure it. */ eventLoopDelayMs: number | null; instanceId: string; } /** One point in the CPU/mem history ring buffer. */ export interface ServerStatsSample { /** Wall-clock time of the sample (epoch ms). */ atMs: number; rssMb: number; heapUsedMb: number; /** CPU utilisation since the previous sample, as a percent of one core (>= 0; * 0 on the very first sample, where there is no previous interval). */ cpuPercent: number; /** Mean event-loop delay (ms) at sample time, or null when unavailable. */ eventLoopDelayMs: number | null; } export interface ServerStatsHistory { samples: ServerStatsSample[]; } export interface ServerStatsServiceOptions { /** Ring-buffer cap for the CPU/mem history. Default 120 (~10m at a 5s poll). */ maxSamples?: number; } /** * Point-in-time snapshot of the Node process health (memory, CPU, uptime, * event-loop delay). The event-loop histogram is started once at construction * and read per request so its mean reflects the whole process lifetime. When * `perf_hooks.monitorEventLoopDelay` is unavailable, the delay degrades to * `null` rather than throwing — every other field is always present. */ export declare class ServerStatsService implements OnApplicationShutdown { private readonly config; private readonly loopMonitor; private readonly maxSamples; /** CPU/mem history ring buffer (oldest first). */ private readonly samples; /** Previous (cpuUsage, wall ms) for deriving the per-interval cpuPercent. */ private lastCpu; private lastSampleMs; constructor(config: ResolvedCoreConfig, options?: ServerStatsServiceOptions); onApplicationShutdown(): void; getStats(): ServerStats; /** The CPU/mem history captured so far (oldest first), for the dashboard's * CPU/mem-history card. Cheap copy of the ring buffer. */ getHistory(): ServerStatsHistory; /** * Append one history sample, deriving cpuPercent from the CPU-time delta since * the previous sample over the wall-clock interval (percent of ONE core). The * first sample has no prior interval, so its cpuPercent is 0. Evicts the oldest * once the ring buffer exceeds its cap. */ private recordSample; } //# sourceMappingURL=server-stats.service.d.ts.map