@codai/memorai-core
Version:
Simplified advanced memory engine - no tiers, just powerful semantic search with persistence
109 lines • 2.97 kB
TypeScript
/**
* Performance monitoring and metrics collection for Memorai
* Tracks query performance, memory usage, and system health
*/
export interface PerformanceMetrics {
queryCount: number;
avgQueryTime: number;
queryErrors: number;
querySuccessRate: number;
rememberCount: number;
recallCount: number;
forgetCount: number;
contextCount: number;
avgRememberTime: number;
avgRecallTime: number;
avgForgetTime: number;
avgContextTime: number;
cacheHits: number;
cacheMisses: number;
cacheHitRate: number;
memoryUsage: number;
activeConnections: number;
windowStart: Date;
windowEnd: Date;
}
export interface QueryMetrics {
operation: 'remember' | 'recall' | 'forget' | 'context';
startTime: number;
endTime: number;
duration: number;
success: boolean;
error?: string;
tenantId: string;
agentId?: string;
resultCount?: number;
cacheHit?: boolean;
}
export declare class PerformanceMonitor {
private metrics;
private windowSizeMs;
private maxHistorySize;
private activeConnections;
private totalConnections;
private maxConcurrentConnections;
constructor(windowSizeMs?: number, maxHistorySize?: number);
/**
* Record a query operation for metrics tracking
*/
recordQuery(metrics: QueryMetrics): void; /**
* Start timing a query operation
*/
startQuery(operation: QueryMetrics['operation'], tenantId: string, agentId?: string): {
finish: (success: boolean, error?: string, resultCount?: number, cacheHit?: boolean) => void;
};
/**
* Get performance metrics for the current time window
*/
getMetrics(): PerformanceMetrics;
/**
* Get detailed query history for debugging
*/
getQueryHistory(count?: number): QueryMetrics[];
/**
* Get metrics for a specific tenant
*/
getTenantMetrics(tenantId: string): PerformanceMetrics;
/**
* Get slow query analysis
*/
getSlowQueries(thresholdMs?: number, count?: number): QueryMetrics[];
/**
* Get error analysis
*/
getErrorAnalysis(): {
error: string;
count: number;
lastOccurrence: Date;
}[];
/**
* Clear metrics history (useful for testing)
*/
clearMetrics(): void;
/**
* Track a new connection
*/
recordConnection(type: 'open' | 'close'): void;
/**
* Get connection statistics
*/
getConnectionStats(): {
active: number;
total: number;
maxConcurrent: number;
};
/**
* Reset connection counters (useful for testing)
*/
resetConnections(): void;
/**
* Export metrics for external monitoring systems
*/
exportMetrics(): {
prometheus: string;
json: PerformanceMetrics;
csv: string;
};
}
export declare const performanceMonitor: PerformanceMonitor;
//# sourceMappingURL=PerformanceMonitor.d.ts.map