@noony-serverless/core
Version:
A Middy base framework compatible with Firebase and GCP Cloud Functions with TypeScript
73 lines • 2.02 kB
TypeScript
/**
* Performance monitoring utilities for production use
* Provides lightweight performance tracking without impacting application performance
*/
interface AggregatedMetrics {
count: number;
totalDuration: number;
averageDuration: number;
minDuration: number;
maxDuration: number;
p95Duration: number;
}
declare class PerformanceMonitor {
private metrics;
private readonly maxMetricsPerOperation;
private isEnabled;
constructor();
/**
* Start timing an operation
*/
startTiming(operationName: string): () => void;
/**
* Time an async operation
*/
timeAsync<T>(operationName: string, operation: () => Promise<T>): Promise<T>;
/**
* Time a synchronous operation
*/
timeSync<T>(operationName: string, operation: () => T): T;
/**
* Record a metric manually
*/
recordMetric(operationName: string, duration: number, metadata?: Record<string, unknown>): void;
/**
* Get aggregated metrics for an operation
*/
getMetrics(operationName: string): AggregatedMetrics | null;
/**
* Get all metrics summary
*/
getAllMetrics(): Record<string, AggregatedMetrics>;
/**
* Reset all metrics
*/
reset(): void;
/**
* Get performance summary for health checks
*/
getHealthSummary(): {
isEnabled: boolean;
trackedOperations: number;
totalMetrics: number;
slowOperations: Array<{
name: string;
avgDuration: number;
}>;
};
/**
* Enable or disable monitoring
*/
setEnabled(enabled: boolean): void;
}
export declare const performanceMonitor: PerformanceMonitor;
/**
* Decorator for timing method calls
*/
export declare function timed(operationName?: string): MethodDecorator;
/**
* Decorator for timing synchronous method calls
*/
export declare function timedSync(operationName?: string): MethodDecorator;
export {};
//# sourceMappingURL=performanceMonitor.d.ts.map